Fix error messages for consistency in ca.go and certdb.go

This commit is contained in:
2025-12-10 21:13:51 +01:00
parent 5d2675450d
commit 714a38d612
2 changed files with 6 additions and 6 deletions

8
ca.go
View File

@@ -462,7 +462,7 @@ func issueSingleCertificate(def CertificateDefinition, i int, n int) (bool, erro
// Check if the certificate is in database, fail if it is. // Check if the certificate is in database, fail if it is.
if caState.FindByName(def.Name, false) != nil { if caState.FindByName(def.Name, false) != nil {
return false, fmt.Errorf("certificate %s already exists and is valid.", def.Name) return false, fmt.Errorf("certificate %s already exists and is valid", def.Name)
} }
// Initialize Subject if not specified // Initialize Subject if not specified
@@ -634,7 +634,7 @@ Certificate generated:
// If saving CA state fails, we still return success for the certificate issuance // If saving CA state fails, we still return success for the certificate issuance
fmt.Printf("WARNING: %v\n", err) fmt.Printf("WARNING: %v\n", err)
fmt.Println("CA state not saved, but certificate issued and saved successfully.") fmt.Println("CA state not saved, but certificate issued and saved successfully.")
return true, fmt.Errorf("Error saving CA state: %v", err) return true, fmt.Errorf("error saving CA state: %v", err)
} }
return true, nil return true, nil
@@ -655,12 +655,12 @@ func ProvisionCertificates(filePath string) error {
// Load certificates provisioning configuration from the file (HCL syntax) // Load certificates provisioning configuration from the file (HCL syntax)
err = certDefs.LoadFromFile(filePath) err = certDefs.LoadFromFile(filePath)
if err != nil { if err != nil {
return fmt.Errorf("Error loading certificates file: %v", err) return fmt.Errorf("error loading certificates file: %v", err)
} }
// The certificate provisioning file must contain at least one certificate definition // The certificate provisioning file must contain at least one certificate definition
if len(certDefs.Certificates) < 1 { if len(certDefs.Certificates) < 1 {
return fmt.Errorf("No certificates defined in %s", filePath) return fmt.Errorf("no certificates defined in %s", filePath)
} }
// We will be counting successes and errors // We will be counting successes and errors

View File

@@ -98,7 +98,7 @@ func SaveCAState() error {
// UpdateCAStateAfterIssue updates the CA state JSON after issuing a certificate // UpdateCAStateAfterIssue updates the CA state JSON after issuing a certificate
func (s *CAState) UpdateCAStateAfterIssue(serialType, name string, subject string, certType string, serialNumber any, validity time.Duration) error { func (s *CAState) UpdateCAStateAfterIssue(serialType, name string, subject string, certType string, serialNumber any, validity time.Duration) error {
if s == nil { if s == nil {
return fmt.Errorf("CAState is nil in UpdateCAStateAfterIssue. This indicates a programming error.") return fmt.Errorf("CAState is nil in UpdateCAStateAfterIssue. This indicates a programming error")
} }
issued := time.Now().UTC().Format(time.RFC3339) issued := time.Now().UTC().Format(time.RFC3339)
expires := time.Now().Add(validity).UTC().Format(time.RFC3339) expires := time.Now().Add(validity).UTC().Format(time.RFC3339)
@@ -135,7 +135,7 @@ func (s *CAState) AddCertificate(name, subject, certType, issued, expires, seria
// RevokeCertificate revokes a certificate by serial number and reason code, updates state, and saves to disk // RevokeCertificate revokes a certificate by serial number and reason code, updates state, and saves to disk
func (s *CAState) RevokeCertificate(serial string, reason int) error { func (s *CAState) RevokeCertificate(serial string, reason int) error {
if s == nil { if s == nil {
return fmt.Errorf("CAState is nil in RevokeCertificate. This indicates a programming error.") return fmt.Errorf("CAState is nil in RevokeCertificate. This indicates a programming error")
} }
revoked := false revoked := false
revokedAt := time.Now().UTC().Format(time.RFC3339) revokedAt := time.Now().UTC().Format(time.RFC3339)