certwarden-deploy/internal/configuration/models.go

61 lines
1.7 KiB
Go
Raw Permalink Normal View History

2024-07-03 10:00:21 +02:00
package configuration
2024-06-28 15:28:54 +02:00
2024-07-11 16:22:58 +02:00
import "log/slog"
2024-07-03 11:56:04 +02:00
// Config file gets read into here
2024-06-28 15:28:54 +02:00
var Config *ConfigFileData
2024-07-03 11:56:04 +02:00
// ConfigFile contains the path to the config file on disk
2024-07-03 10:00:21 +02:00
var ConfigFile string
2024-07-03 11:56:04 +02:00
// Flag to show that the user wants a dry run
2024-06-30 08:55:07 +02:00
var DryRun bool
2024-07-03 11:56:04 +02:00
// Flag to show that the user wants quiet logging
2024-06-30 08:55:07 +02:00
var QuietLogging bool
2024-07-03 11:56:04 +02:00
// Flag to show that the user wants verbose logging
2024-06-30 08:55:07 +02:00
var VerboseLogging bool
2024-06-28 15:28:54 +02:00
2024-07-03 11:56:04 +02:00
// Flag to show that the user wants to force certificate update
var Force bool
// Struct to read the config file into when reading from disk
2024-06-28 15:28:54 +02:00
type ConfigFileData struct {
BaseURL string `yaml:"base_url"`
DisableCertificateValidation bool `yaml:"disable_certificate_validation"`
Certificates []CertificateData `yaml:"certificates"`
}
2024-07-03 11:56:04 +02:00
// Struct that holds the details of a single managed certificate
2024-06-28 15:28:54 +02:00
type CertificateData struct {
2024-07-11 16:22:58 +02:00
Name string `yaml:"name"`
CertificateSecret string `yaml:"cert_secret"`
CertificatePath string `yaml:"cert_path"`
KeySecret string `yaml:"key_secret"`
KeyPath string `yaml:"key_path"`
Action string `yaml:"action"`
2024-06-28 15:28:54 +02:00
}
2024-07-03 10:00:21 +02:00
2024-07-11 16:22:58 +02:00
type ConfigValidationError struct {
ErrorMessages []string
}
func (e *ConfigValidationError) Error() string {
return "Configuration file has errors! Application cannot start unless the errors are corrected."
}
func (e *ConfigValidationError) Add(msg string) {
e.ErrorMessages = append(e.ErrorMessages, msg)
}
func (e *ConfigValidationError) HasMessages() bool {
2024-07-12 11:18:32 +02:00
return len(e.ErrorMessages) != 0
2024-07-11 16:22:58 +02:00
}
func (e *ConfigValidationError) Print(logger *slog.Logger) {
for _, line := range e.ErrorMessages {
logger.Error(line)
}
}