mirror of
https://github.com/ebrianne/adguard-exporter.git
synced 2024-12-22 07:57:35 +01:00
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
|
- 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
|
||||||
|
@ -3,6 +3,7 @@ package config
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
@ -16,28 +17,30 @@ import (
|
|||||||
|
|
||||||
// Config is the exporter CLI configuration.
|
// Config is the exporter CLI configuration.
|
||||||
type Config struct {
|
type Config struct {
|
||||||
AdguardProtocol string `config:"adguard_protocol"`
|
AdguardProtocol string `config:"adguard_protocol"`
|
||||||
AdguardHostname string `config:"adguard_hostname"`
|
AdguardHostname string `config:"adguard_hostname"`
|
||||||
AdguardUsername string `config:"adguard_username"`
|
AdguardUsername string `config:"adguard_username"`
|
||||||
AdguardPassword string `config:"adguard_password"`
|
AdguardPassword string `config:"adguard_password"`
|
||||||
AdguardPort string `config:"adguard_port"`
|
AdguardPort string `config:"adguard_port"`
|
||||||
ServerPort string `config:"server_port"`
|
ServerPort string `config:"server_port"`
|
||||||
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 {
|
||||||
return &Config{
|
return &Config{
|
||||||
AdguardProtocol: "http",
|
AdguardProtocol: "http",
|
||||||
AdguardHostname: "127.0.0.1",
|
AdguardHostname: "127.0.0.1",
|
||||||
AdguardUsername: "",
|
AdguardUsername: "",
|
||||||
AdguardPassword: "",
|
AdguardPassword: "",
|
||||||
AdguardPort: "80",
|
AdguardPort: "80",
|
||||||
ServerPort: "9617",
|
ServerPort: "9617",
|
||||||
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
|
||||||
|
Loading…
Reference in New Issue
Block a user