diff --git a/actor.sample.yaml b/actor.sample.yaml index dbbe430..c32414e 100644 --- a/actor.sample.yaml +++ b/actor.sample.yaml @@ -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 @@ -17,4 +18,4 @@ metrics: host: localhost port: 2003 prefix: - server: actor.server \ No newline at end of file + server: actor.server diff --git a/cmd/server.go b/cmd/server.go index a4f69f1..e7cb0d1 100644 --- a/cmd/server.go +++ b/cmd/server.go @@ -15,6 +15,7 @@ package cmd import ( + "io/ioutil" "time" "github.com/bmc-toolbox/actor/internal" @@ -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"), @@ -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))