Skip to content

Commit 4673829

Browse files
authored
config: fix access for config and history file (#166)
Fixes #157 --------- Signed-off-by: Abhishek Kumar <[email protected]>
1 parent 765b62f commit 4673829

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

config/config.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ func saveConfig(cfg *Config) *Config {
267267
conf.Section(defaultCoreConfig.ProfileName).ReflectFrom(&defaultProfile)
268268
conf.SaveTo(cfg.ConfigFile)
269269
}
270+
makeFileUserPrivate(cfg.ConfigFile)
270271

271272
conf := readConfig(cfg)
272273

@@ -322,6 +323,10 @@ func saveConfig(cfg *Config) *Config {
322323
profiles = append(profiles, profile.Name())
323324
}
324325

326+
if cfg.HistoryFile != "" {
327+
makeFileUserPrivate(cfg.HistoryFile)
328+
}
329+
325330
return cfg
326331
}
327332

@@ -395,6 +400,14 @@ func (c *Config) UpdateConfig(key string, value string, update bool) {
395400
}
396401
}
397402

403+
func makeFileUserPrivate(filePath string) {
404+
if fi, err := os.Stat(filePath); err == nil && fi.Mode().IsRegular() {
405+
if err := os.Chmod(filePath, 0600); err != nil {
406+
fmt.Printf("Failed to set permissions on %s: %v\n", filePath, err)
407+
}
408+
}
409+
}
410+
398411
// NewConfig creates or reload config and loads API cache
399412
func NewConfig(configFilePath *string) *Config {
400413
defaultConf := defaultConfig()

0 commit comments

Comments
 (0)