allow environment variable in configuration file (#601)
This commit is contained in:
parent
564c4155a8
commit
359a9cb8ce
|
@ -4,6 +4,7 @@
|
|||
|
||||
## Configuration example
|
||||
|
||||
|
||||
<details>
|
||||
<summary>Default configuration</summary>
|
||||
|
||||
|
@ -63,6 +64,30 @@ prometheus:
|
|||
|
||||
</details>
|
||||
|
||||
## Environment variable
|
||||
|
||||
It is possible to set a configuration value based on an enrivonement variables.
|
||||
|
||||
For example, if you don't want to store your database password in the configuration file, you can do this:
|
||||
|
||||
```yaml
|
||||
db_config:
|
||||
type: mysql
|
||||
user: database_user
|
||||
password: ${DB_PASSWORD}
|
||||
db_name: db_name
|
||||
host: 192.168.0.2
|
||||
port: 3306
|
||||
```
|
||||
|
||||
And export the environment variable such as:
|
||||
|
||||
```bash
|
||||
export DB_PASSWORD="<db_password>"
|
||||
```
|
||||
|
||||
!!! warning
|
||||
**Note**: you need to be `root` or put the environment variable in `/etc/environement`
|
||||
|
||||
## Configuration format
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ package csconfig
|
|||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
|
@ -40,7 +41,8 @@ func (c *GlobalConfig) LoadConfigurationFile(path string) error {
|
|||
if err != nil {
|
||||
return errors.Wrap(err, "failed to read config file")
|
||||
}
|
||||
err = yaml.UnmarshalStrict(fcontent, c)
|
||||
configData := os.ExpandEnv(string(fcontent))
|
||||
err = yaml.UnmarshalStrict([]byte(configData), c)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed unmarshaling config")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue