From bea028500765970a09fb9466d012cdb32ea314e7 Mon Sep 17 00:00:00 2001 From: Slawek Koszewski Date: Mon, 28 Jul 2025 15:36:45 +0200 Subject: [PATCH] Refactoring --- ca.go | 10 ++++++---- certdb.go | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/ca.go b/ca.go index 9095cdb..f8a9c79 100644 --- a/ca.go +++ b/ca.go @@ -41,7 +41,7 @@ type _CAConfig struct { Paths Paths `hcl:"paths,block"` } -func (c *_CAConfig) StateName() string { +func (c *_CAConfig) GetStateFileName() string { return c.Label + "_state.json" } @@ -57,7 +57,7 @@ type CertificateDefinition struct { SAN []string `hcl:"san,optional"` } -func (def *CertificateDefinition) fillDefaultValues(defaults *CertificateDefaults) { +func (def *CertificateDefinition) FillDefaultValues(defaults *CertificateDefaults) { if defaults == nil { return } @@ -150,7 +150,9 @@ var CACert *x509.Certificate // LoadCAConfig parses and validates the CA config from the given path and stores it in the CAConfig global variable func LoadCAConfig() error { - fmt.Printf("Loading CA config from %s\n", CAConfigPath) + if verbose { + fmt.Printf("Loading CA config from \"%s\"", CAConfigPath) + } parser := hclparse.NewParser() file, diags := parser.ParseHCLFile(CAConfigPath) if diags.HasErrors() { @@ -598,7 +600,7 @@ func ProvisionCertificates(filePath string, overwrite bool, dryRun bool, verbose // to render templates and fill missing fields from defaults for i := range certDefs.Certificates { // Fill missing fields from defaults, if provided - certDefs.Certificates[i].fillDefaultValues(certDefs.Defaults) + certDefs.Certificates[i].FillDefaultValues(certDefs.Defaults) // Render templates in the definition using the variables map // with added definition name. variables := certDefs.Variables diff --git a/certdb.go b/certdb.go index 67fa444..ef0ee24 100644 --- a/certdb.go +++ b/certdb.go @@ -34,7 +34,7 @@ type CertificateRecord struct { } func caStatePath() string { - return filepath.Join(filepath.Dir(CAConfigPath), CAConfig.StateName()) + return filepath.Join(filepath.Dir(CAConfigPath), CAConfig.GetStateFileName()) } // LoadCAState loads the CA state from a JSON file