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:
parent
e75108942e
commit
23838bf07e
|
@ -127,6 +127,7 @@ services:
|
|||
- server_port=9617
|
||||
- interval=10s
|
||||
- log_limit=10000
|
||||
- password_from_file=true
|
||||
```
|
||||
### Swarm mode (docker swarm init)
|
||||
|
||||
|
@ -159,6 +160,7 @@ services:
|
|||
- server_port=9617
|
||||
- interval=10s
|
||||
- log_limit=10000
|
||||
- password_from_file=true
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
|
|
@ -3,6 +3,7 @@ package config
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"reflect"
|
||||
|
@ -25,6 +26,7 @@ type Config struct {
|
|||
Interval time.Duration `config:"interval"`
|
||||
LogLimit string `config:"log_limit"`
|
||||
RDnsEnabled bool `config:"rdns_enabled"`
|
||||
PasswordFromFile bool `config:"password_from_file"`
|
||||
}
|
||||
|
||||
func getDefaultConfig() *Config {
|
||||
|
@ -38,6 +40,7 @@ func getDefaultConfig() *Config {
|
|||
Interval: 10 * time.Second,
|
||||
LogLimit: "1000",
|
||||
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()
|
||||
|
||||
return cfg
|
||||
|
|
Loading…
Reference in New Issue