Skip to content

Commit aca7935

Browse files
author
micsthepick
committed
vt: set toml file mod
1 parent eb5dbbc commit aca7935

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

vt/main.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package main
1616
import (
1717
"fmt"
1818
"os"
19+
"path/filepath"
1920

2021
"github.com/VirusTotal/vt-cli/cmd"
2122
homedir "github.com/mitchellh/go-homedir"
@@ -41,13 +42,27 @@ func initConfig() {
4142

4243
// The prefix for all environment variables will be VTCLI_. Examples:
4344
// VTCLI_PROXY, VTCLI_APIKEY.
45+
4446
viper.SetEnvPrefix("VTCLI")
4547

4648
// Read in environment variables that match
4749
viper.AutomaticEnv()
4850

4951
// If a config file is found, read it in.
5052
viper.ReadInConfig()
53+
54+
// Ensure mode bits set correctly
55+
cfg := viper.ConfigFileUsed()
56+
if cfg == "" {
57+
cfg = filepath.Join(home, ".vt.toml")
58+
}
59+
60+
if _, err := os.Stat(cfg); os.IsNotExist(err) {
61+
f, _ := os.OpenFile(cfg, os.O_CREATE|os.O_WRONLY, 0600)
62+
f.Close()
63+
} else {
64+
os.Chmod(cfg, 0600)
65+
}
5166
}
5267

5368
func init() {

0 commit comments

Comments
 (0)