How adhocteam/certwatcher works
Project Type & Purpose
• This is a utility tool (CLI app) written in Go.
• Its purpose is to:
• Read a list of host URLs (and optional descriptions) from a CSV file.
• Check the SSL/TLS certificate status for each host.
• Alert via SMTP if any certificate is expiring soon.
• With very few files (main.go, main_test.go, Makefile, config example, etc.), it follows a single-application, minimal architecture.
Analyzing the File Structure
• Top-level files include:
• main.go: The core application logic.
• main_test.go: Test cases for the main functionality.
• config.ini.example: An example configuration file (SMTP and possibly other parameters).
• Makefile: Likely used for building, testing, and/or running the project.
• There is no explicit separation into directories, meaning that all components are tightly integrated within the main application.
Key Architectural Components & Relationships
• Input Handling:
• CSV File Parser: Reads the list of URLs and (optional) descriptions.
• Validates the format (ignoring comments and parsing 'host,description' values).
• Certificate Checker:
• For each host, establishes an HTTPS connection to retrieve its certificate.
• Checks the certificate’s expiry date against the threshold specified by a command-line parameter (e.g., -days 90).
• Notification Service:
• Reads SMTP configuration from config.ini.
• Sends an email notification if a certificate is about to expire.
• Logging & Reporting:
• Logs the status of each host’s certificate check (e.g., “certificate is ok”).
• Logs notification events when alerts are sent.
• Testing:
• Included primary testing via main_test.go ensures the reliability of core functionalities (input validation, certificate checking logic, notification triggers).
a. And Label Main Components:
• “CSV Input Parser” (handles reading and sanitizing URL input).
• “Certificate Checker” (handles the connection, fetching the certificate, and evaluating expiration).
• “SMTP Notification Service” (manages email alerting when certificates are near expiration).
• “Configuration Manager” (loads SMTP and possibly other config options from config.ini).
• “Logging/Monitoring” (records status messages and alert events).
b. Relationships and Data Flow:
• The parser sends URL data to “Certificate Checker”.
• “Certificate Checker” interacts with external “Remote Hosts” (each providing a certificate).
• “SMTP Notification Service” then interacts with the “SMTP Server” (depicted as an external mail service).
• Throughout, include a “Logging” component that receives status updates from both the Checker and Notification Service.
c. Architectural Design Principles:
• Fact that the tool leverages built-in libraries (like Go’s crypto/tls, net/smtp, etc.) for its functionalities.
d. Relevant Technologies and Patterns:
• That this is a command-line utility built in Go.
• Mention that configuration is managed via an INI file.
• Use minimal layering but make sure to represent clear separation between input, business logic (certificate checking), and output (notification).