Skip to content

Commit 54c560f

Browse files
committed
Improve configuration file initialization log output
1 parent fd38dd3 commit 54c560f

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

authority/config/config.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ type Config struct {
7575
SkipValidation bool `json:"-"`
7676

7777
// Keeps record of the filename the Config is read from
78-
loadedFromFilename string
78+
loadedFromFilepath string
7979
}
8080

8181
// ASN1DN contains ASN1.DN attributes that are used in Subject and Issuer
@@ -167,7 +167,7 @@ func LoadConfiguration(filename string) (*Config, error) {
167167
}
168168

169169
// store filename that was read to populate Config
170-
c.loadedFromFilename = filename
170+
c.loadedFromFilepath = filename
171171

172172
// initialize the Config
173173
c.Init()
@@ -215,13 +215,19 @@ func (c *Config) Commit() error {
215215
if !c.WasLoadedFromFile() {
216216
return errors.New("cannot commit configuration if not loaded from file")
217217
}
218-
return c.Save(c.loadedFromFilename)
218+
return c.Save(c.loadedFromFilepath)
219219
}
220220

221221
// WasLoadedFromFile returns whether or not the Config was
222-
// read from a file.
222+
// loaded from a file.
223223
func (c *Config) WasLoadedFromFile() bool {
224-
return c.loadedFromFilename != ""
224+
return c.loadedFromFilepath != ""
225+
}
226+
227+
// Filepath returns the path to the file the Config was
228+
// loaded from.
229+
func (c *Config) Filepath() string {
230+
return c.loadedFromFilepath
225231
}
226232

227233
// Validate validates the configuration.

ca/ca.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ func (ca *CA) Run() error {
349349
if step.Contexts().GetCurrent() != nil {
350350
log.Printf("Current context: %s", step.Contexts().GetCurrent().Name)
351351
}
352-
log.Printf("Config file: %s", ca.opts.configFile)
352+
log.Printf("Config file: %s", ca.getConfigFileOutput())
353353
baseURL := fmt.Sprintf("https://%s%s",
354354
authorityInfo.DNSNames[0],
355355
ca.config.Address[strings.LastIndex(ca.config.Address, ":"):])
@@ -569,3 +569,10 @@ func dumpRoutes(mux chi.Routes) {
569569
fmt.Printf("Logging err: %s\n", err.Error())
570570
}
571571
}
572+
573+
func (ca *CA) getConfigFileOutput() string {
574+
if ca.config.WasLoadedFromFile() {
575+
return ca.config.Filepath()
576+
}
577+
return "loaded from token"
578+
}

0 commit comments

Comments
 (0)