From aca793537f10e0f8cfa36dc1f45a5a4c832bbdef Mon Sep 17 00:00:00 2001 From: micsthepick Date: Fri, 10 Oct 2025 12:14:19 +1100 Subject: [PATCH 1/3] vt: set toml file mod --- vt/main.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/vt/main.go b/vt/main.go index 89e6a44..699852b 100644 --- a/vt/main.go +++ b/vt/main.go @@ -16,6 +16,7 @@ package main import ( "fmt" "os" + "path/filepath" "github.com/VirusTotal/vt-cli/cmd" homedir "github.com/mitchellh/go-homedir" @@ -41,6 +42,7 @@ func initConfig() { // The prefix for all environment variables will be VTCLI_. Examples: // VTCLI_PROXY, VTCLI_APIKEY. + viper.SetEnvPrefix("VTCLI") // Read in environment variables that match @@ -48,6 +50,19 @@ func initConfig() { // If a config file is found, read it in. viper.ReadInConfig() + + // Ensure mode bits set correctly + cfg := viper.ConfigFileUsed() + if cfg == "" { + cfg = filepath.Join(home, ".vt.toml") + } + + if _, err := os.Stat(cfg); os.IsNotExist(err) { + f, _ := os.OpenFile(cfg, os.O_CREATE|os.O_WRONLY, 0600) + f.Close() + } else { + os.Chmod(cfg, 0600) + } } func init() { From c83e25c0fc37da429147ed8760c2bdb20410937a Mon Sep 17 00:00:00 2001 From: "Victor M. Alvarez" Date: Fri, 10 Oct 2025 12:28:11 +0200 Subject: [PATCH 2/3] refactor: don't change the config rule permissions on every execution of the tool. Set 0600 permissions when the file is originally created. From that moment, if the user decides to change the initial permissions, the tool should not be messing up with manually assigned permissions. Also the tool should not create a `.vt.toml` file if it doesn't exist, except when the `init` command is run. --- cmd/init.go | 2 +- vt/main.go | 14 -------------- 2 files changed, 1 insertion(+), 15 deletions(-) diff --git a/cmd/init.go b/cmd/init.go index e158298..0fd4657 100644 --- a/cmd/init.go +++ b/cmd/init.go @@ -89,7 +89,7 @@ func NewInitCmd() *cobra.Command { } configFilePath := path.Join(dir, ".vt.toml") - configFile, err := os.Create(configFilePath) + configFile, err := os.OpenFile(configFilePath, os.O_CREATE|os.O_WRONLY, 0600) if err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) diff --git a/vt/main.go b/vt/main.go index 699852b..8677d74 100644 --- a/vt/main.go +++ b/vt/main.go @@ -16,7 +16,6 @@ package main import ( "fmt" "os" - "path/filepath" "github.com/VirusTotal/vt-cli/cmd" homedir "github.com/mitchellh/go-homedir" @@ -50,19 +49,6 @@ func initConfig() { // If a config file is found, read it in. viper.ReadInConfig() - - // Ensure mode bits set correctly - cfg := viper.ConfigFileUsed() - if cfg == "" { - cfg = filepath.Join(home, ".vt.toml") - } - - if _, err := os.Stat(cfg); os.IsNotExist(err) { - f, _ := os.OpenFile(cfg, os.O_CREATE|os.O_WRONLY, 0600) - f.Close() - } else { - os.Chmod(cfg, 0600) - } } func init() { From 72f3326fa91a7d1f3bc4f048d68e58ef40e48cc2 Mon Sep 17 00:00:00 2001 From: "Victor M. Alvarez" Date: Fri, 10 Oct 2025 12:37:53 +0200 Subject: [PATCH 3/3] style: remove empty line. --- vt/main.go | 1 - 1 file changed, 1 deletion(-) diff --git a/vt/main.go b/vt/main.go index 8677d74..89e6a44 100644 --- a/vt/main.go +++ b/vt/main.go @@ -41,7 +41,6 @@ func initConfig() { // The prefix for all environment variables will be VTCLI_. Examples: // VTCLI_PROXY, VTCLI_APIKEY. - viper.SetEnvPrefix("VTCLI") // Read in environment variables that match