add support for reading password from secret/file (#22)

* add support for reading password from secret/file

Signed-off-by: mvadu <8618235+mvadu@users.noreply.github.com>

* avoid trimming

Signed-off-by: mvadu <8618235+mvadu@users.noreply.github.com>
This commit is contained in:
Adarsha 2022-02-12 03:46:45 -05:00 committed by GitHub
parent e75108942e
commit 23838bf07e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 18 deletions

View File

@ -127,6 +127,7 @@ services:
- server_port=9617 - server_port=9617
- interval=10s - interval=10s
- log_limit=10000 - log_limit=10000
- password_from_file=true
``` ```
### Swarm mode (docker swarm init) ### Swarm mode (docker swarm init)
@ -159,6 +160,7 @@ services:
- server_port=9617 - server_port=9617
- interval=10s - interval=10s
- log_limit=10000 - log_limit=10000
- password_from_file=true
``` ```
## Usage ## Usage

View File

@ -3,6 +3,7 @@ package config
import ( import (
"context" "context"
"fmt" "fmt"
"io/ioutil"
"log" "log"
"os" "os"
"reflect" "reflect"
@ -25,6 +26,7 @@ type Config struct {
Interval time.Duration `config:"interval"` Interval time.Duration `config:"interval"`
LogLimit string `config:"log_limit"` LogLimit string `config:"log_limit"`
RDnsEnabled bool `config:"rdns_enabled"` RDnsEnabled bool `config:"rdns_enabled"`
PasswordFromFile bool `config:"password_from_file"`
} }
func getDefaultConfig() *Config { func getDefaultConfig() *Config {
@ -38,6 +40,7 @@ func getDefaultConfig() *Config {
Interval: 10 * time.Second, Interval: 10 * time.Second,
LogLimit: "1000", LogLimit: "1000",
RDnsEnabled: true, RDnsEnabled: true,
PasswordFromFile: false,
} }
} }
@ -69,6 +72,17 @@ func Load() *Config {
} }
} }
//Set the adguard password based on the input configuration
if cfg.PasswordFromFile {
secret, err := ioutil.ReadFile(cfg.AdguardPassword)
if err != nil {
log.Printf("unable to read AdguardPassword from %s due to %s", cfg.AdguardPassword, err)
os.Exit(1)
}
cfg.AdguardPassword = string(secret)
}
cfg.show() cfg.show()
return cfg return cfg