Skip to content

Commit

Permalink
Merge pull request #21 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 04ec683 + 3b0176f commit 36f758c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
12 changes: 11 additions & 1 deletion cmd/collect.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ usage: dora collect
`,
Run: func(cmd *cobra.Command, args []string) {
configItems := []string{
"bmc_pass",
"bmc_user",
"collector.concurrency",
"collector.dump_invalid_payloads",
Expand All @@ -56,6 +55,17 @@ usage: dora collect
}
}

bmcPass := viper.IsSet("bmc_pass")
bmcPassFile := viper.IsSet("bmc_pass_file")
if !bmcPass && !bmcPassFile {
fmt.Printf("One of the bmc_pass/bmc_pass_file parameters is missing in the config file\n")
os.Exit(1)
}
if bmcPass && bmcPassFile {
fmt.Printf("Only one of the bmc_pass/bmc_pass_file parameters is allowed in the config file\n")
os.Exit(1)
}

// This will avoid a deadlock in metrics. They are not setup at this stage
viper.Set("metrics.enabled", false)

Expand Down
13 changes: 12 additions & 1 deletion connectors/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package connectors

import (
"fmt"
"io/ioutil"
"net"
"sync"
"time"
Expand All @@ -24,7 +25,17 @@ import (

func collect(input <-chan string, source *string, db *gorm.DB) {
bmcUser := viper.GetString("bmc_user")
bmcPass := viper.GetString("bmc_pass")
bmcPass := ""
if viper.IsSet("bmc_pass") {
bmcPass = viper.GetString("bmc_pass")
} else {
bmcPassFile := viper.GetString("bmc_pass_file")
bmcPassBytes, err := ioutil.ReadFile(bmcPassFile)
if err != nil {
log.WithFields(log.Fields{"operation": "scan"}).Error(err)
}
bmcPass = string(bmcPassBytes)
}

for host := range input {
log.WithFields(log.Fields{"operation": "scan", "ip": host}).Debug("collection started")
Expand Down
2 changes: 1 addition & 1 deletion dora.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ debug: true
site:
- all
bmc_user: Priest
bmc_pass: Wololo
bmc_pass_file: /my/password/file
url: http://service.example.com/v1
database_type: postgres
database_options: host=0.0.0.0 user=postgres port=32768 dbname=postgres password=mysecretpassword
Expand Down

0 comments on commit 36f758c

Please sign in to comment.