Skip to content

Commit d41eb7f

Browse files
committed
support env variable for TENABLE_ACCESSKEY and TENABLE_SECRETKEY
1 parent a9c8de6 commit d41eb7f

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

tenablecmd/root.go

+16-12
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import (
77
"github.com/spf13/cobra"
88
"github.com/spf13/viper"
99

10-
"github.com/mistsys/go-tenable/tenable"
1110
"github.com/mistsys/go-tenable/outputs"
11+
"github.com/mistsys/go-tenable/tenable"
1212
)
1313

1414
var (
@@ -25,7 +25,11 @@ var rootCmd = &cobra.Command{
2525
Use: "tenable COMMAND",
2626
Short: "A CLI for the Tenable API",
2727
PersistentPreRun: func(cmd *cobra.Command, args []string) {
28-
client = tenable.NewClient(viper.GetString("accesskey"), viper.GetString("secretkey"))
28+
viper.AutomaticEnv()
29+
viper.SetEnvPrefix("TENABLE")
30+
accessKey := viper.GetString("accesskey")
31+
secretKey := viper.GetString("secretkey")
32+
client = tenable.NewClient(accessKey, secretKey)
2933
// using viper means the cobra *Var flag options don't actually populate the global variables from config files
3034
// if we have to manually set them anyway, we'll just manually set them
3135
debug := viper.GetBool("debug")
@@ -34,17 +38,17 @@ var rootCmd = &cobra.Command{
3438
client.QueryOpts = queryOpts
3539

3640
/*
37-
var outputFd *os.File
38-
var err error // ???
39-
if outputFilename == "-" {
40-
outputFd = os.Stdout
41-
} else {
42-
outputFd, err = outputs.NewFile(outputFilename)
43-
if err != nil {
44-
fmt.Println("Error creating output file:", err)
45-
os.Exit(1)
41+
var outputFd *os.File
42+
var err error // ???
43+
if outputFilename == "-" {
44+
outputFd = os.Stdout
45+
} else {
46+
outputFd, err = outputs.NewFile(outputFilename)
47+
if err != nil {
48+
fmt.Println("Error creating output file:", err)
49+
os.Exit(1)
50+
}
4651
}
47-
}
4852
*/
4953

5054
// TODO remove outputter entirely

0 commit comments

Comments
 (0)