Skip to content

Commit

Permalink
Merge pull request #11 from bmc-toolbox/abdrabo/password-file
Browse files Browse the repository at this point in the history
Add a config option to read password from a file
  • Loading branch information
nnuss authored Nov 5, 2020
2 parents 7dc28c7 + 635f329 commit 5ec11a3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
3 changes: 2 additions & 1 deletion actor.sample.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
debug: true
bmc_user: my_super_user
bmc_pass: my_super_password
bmc_pass_file: /my/password/file
bind_to: 0.0.0.0:8000
s3:
enabled: false
Expand All @@ -17,4 +18,4 @@ metrics:
host: localhost
port: 2003
prefix:
server: actor.server
server: actor.server
23 changes: 22 additions & 1 deletion cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package cmd

import (
"io/ioutil"
"time"

"github.com/bmc-toolbox/actor/internal"
Expand All @@ -41,6 +42,15 @@ var serverCmd = &cobra.Command{
}
}

bmcPass := viper.IsSet("bmc_pass")
bmcPassFile := viper.IsSet("bmc_pass_file")
if !bmcPass && !bmcPassFile {
log.Fatal("One of the bmc_pass/bmc_pass_file parameters is missing in the config file")
}
if bmcPass && bmcPassFile {
log.Fatal("Only one of the bmc_pass/bmc_pass_file parameters is allowed in the config file")
}

config := &server.Config{
Address: viper.GetString("bind_to"),
IsDebug: viper.GetBool("debug"),
Expand All @@ -66,7 +76,18 @@ func createAPIs() *server.APIs {
sleepExecutorFactory := internal.NewSleepExecutorFactory()

bmcUsername := viper.GetString("bmc_user")
bmcPassword := viper.GetString("bmc_pass")
bmcPassword := ""

if viper.IsSet("bmc_pass") {
bmcPassword = viper.GetString("bmc_pass")
} else {
bmcPassFile := viper.GetString("bmc_pass_file")
bmcPassBytes, err := ioutil.ReadFile(bmcPassFile)
if err != nil {
log.Fatal(err)
}
bmcPassword = string(bmcPassBytes)
}

hostExecutorFactory := internal.NewHostExecutorFactory(bmcUsername, bmcPassword, viper.GetBool("s3.enabled"))
hostAPI := routes.NewHostAPI(actions.NewPlanMaker(sleepExecutorFactory, hostExecutorFactory))
Expand Down

0 comments on commit 5ec11a3

Please sign in to comment.