Improve configuration file initialization log output

pull/1075/head
Herman Slatman 2 years ago
parent fd38dd34f9
commit 54c560f620
No known key found for this signature in database
GPG Key ID: F4D8A44EA0A75A4F

@ -75,7 +75,7 @@ type Config struct {
SkipValidation bool `json:"-"`
// Keeps record of the filename the Config is read from
loadedFromFilename string
loadedFromFilepath string
}
// ASN1DN contains ASN1.DN attributes that are used in Subject and Issuer
@ -167,7 +167,7 @@ func LoadConfiguration(filename string) (*Config, error) {
}
// store filename that was read to populate Config
c.loadedFromFilename = filename
c.loadedFromFilepath = filename
// initialize the Config
c.Init()
@ -215,13 +215,19 @@ func (c *Config) Commit() error {
if !c.WasLoadedFromFile() {
return errors.New("cannot commit configuration if not loaded from file")
}
return c.Save(c.loadedFromFilename)
return c.Save(c.loadedFromFilepath)
}
// WasLoadedFromFile returns whether or not the Config was
// read from a file.
// loaded from a file.
func (c *Config) WasLoadedFromFile() bool {
return c.loadedFromFilename != ""
return c.loadedFromFilepath != ""
}
// Filepath returns the path to the file the Config was
// loaded from.
func (c *Config) Filepath() string {
return c.loadedFromFilepath
}
// Validate validates the configuration.

@ -349,7 +349,7 @@ func (ca *CA) Run() error {
if step.Contexts().GetCurrent() != nil {
log.Printf("Current context: %s", step.Contexts().GetCurrent().Name)
}
log.Printf("Config file: %s", ca.opts.configFile)
log.Printf("Config file: %s", ca.getConfigFileOutput())
baseURL := fmt.Sprintf("https://%s%s",
authorityInfo.DNSNames[0],
ca.config.Address[strings.LastIndex(ca.config.Address, ":"):])
@ -569,3 +569,10 @@ func dumpRoutes(mux chi.Routes) {
fmt.Printf("Logging err: %s\n", err.Error())
}
}
func (ca *CA) getConfigFileOutput() string {
if ca.config.WasLoadedFromFile() {
return ca.config.Filepath()
}
return "loaded from token"
}

Loading…
Cancel
Save