You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by sh...@apache.org on 2025/08/07 08:19:36 UTC

(cloudstack-cloudmonkey) branch main updated: config: fix access for config and history file (#166)

This is an automated email from the ASF dual-hosted git repository.

shwstppr pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudstack-cloudmonkey.git


The following commit(s) were added to refs/heads/main by this push:
     new 4673829  config: fix access for config and history file (#166)
4673829 is described below

commit 4673829bfd21405a0fdec6fd7bfcc8594468ab39
Author: Abhishek Kumar <ab...@gmail.com>
AuthorDate: Thu Aug 7 13:49:32 2025 +0530

    config: fix access for config and history file (#166)
    
    Fixes #157
    
    ---------
    
    Signed-off-by: Abhishek Kumar <ab...@gmail.com>
---
 config/config.go | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/config/config.go b/config/config.go
index 3245f4e..91632aa 100644
--- a/config/config.go
+++ b/config/config.go
@@ -267,6 +267,7 @@ func saveConfig(cfg *Config) *Config {
 		conf.Section(defaultCoreConfig.ProfileName).ReflectFrom(&defaultProfile)
 		conf.SaveTo(cfg.ConfigFile)
 	}
+	makeFileUserPrivate(cfg.ConfigFile)
 
 	conf := readConfig(cfg)
 
@@ -322,6 +323,10 @@ func saveConfig(cfg *Config) *Config {
 		profiles = append(profiles, profile.Name())
 	}
 
+	if cfg.HistoryFile != "" {
+		makeFileUserPrivate(cfg.HistoryFile)
+	}
+
 	return cfg
 }
 
@@ -395,6 +400,14 @@ func (c *Config) UpdateConfig(key string, value string, update bool) {
 	}
 }
 
+func makeFileUserPrivate(filePath string) {
+	if fi, err := os.Stat(filePath); err == nil && fi.Mode().IsRegular() {
+		if err := os.Chmod(filePath, 0600); err != nil {
+			fmt.Printf("Failed to set permissions on %s: %v\n", filePath, err)
+		}
+	}
+}
+
 // NewConfig creates or reload config and loads API cache
 func NewConfig(configFilePath *string) *Config {
 	defaultConf := defaultConfig()