Allow passing list-settings via env-variables as well (Issue #100)
This commit is contained in:
parent
8502faee6e
commit
158cd40397
3 changed files with 7 additions and 2 deletions
|
@ -36,7 +36,7 @@ There are no dependencies on Python modules that are not part of the standard li
|
|||
### Configuration
|
||||
Near the top of the py-file you will find some global variables you can change to customize the configurator a little bit. If you are unfamiliar with Python: when setting variables of the type _string_, you have to write that within quotation marks. The default settings are fine for just checking this out quickly. With more customized setups you will have to change some settings though.
|
||||
To keep your setting across updates it is also possible to save settings in an external file. In that case copy [settings.conf](https://github.com/danielperna84/hass-configurator/blob/master/settings.conf) whereever you like and append the full path to the file to the command when starting the configurator. E.g. `sudo .configurator.py /home/homeassistant/.homeassistant/mysettings.conf`. This file is in JSON format. So make sure it has a valid syntax (you can set the editor to JSON to get syntax highlighting for the settings). The major difference to the settings in the py-file is, that `None` becomes `null`.
|
||||
Another way of passing settings (except those defined as lists like e.g. `ALLOWED_NETWORKS`) is by using [environment variables](https://en.wikipedia.org/wiki/Environment_variable). All settings passed via environment variables will overwrite the settings you have set in the `settings.conf` file. This allows you to provide settings in you systemd service file or the way it is usually done with Docker. The names of the environment variables have to be named exactly like the regular ones, prepended with the prefix `HC_`. You can customize this prefix in the `settings.conf` by setting `ENV_PREFIX` to something you like. `ENV_PREFIX` can not be set via environment variable.
|
||||
Another way of passing settings is by using [environment variables](https://en.wikipedia.org/wiki/Environment_variable). All settings passed via environment variables will overwrite the settings you have set in the `settings.conf` file. This allows you to provide settings in you systemd service file or the way it is usually done with Docker. The names of the environment variables have to be named exactly like the regular ones, prepended with the prefix `HC_`. You can customize this prefix in the `settings.conf` by setting `ENV_PREFIX` to something you like. `ENV_PREFIX` can not be set via environment variable. For settings that are usually defined as lists (`ALLOWED_NETWORKS` etc.) a comma is used as a separator for each value (e.g. `HC_ALLOWED_NETWORKS="127.0.0.1,192.168.0.0/16"`).
|
||||
|
||||
#### LISTENIP (string)
|
||||
The IP address the service is listening on. By default it is binding to `0.0.0.0`, which is every IPv4 interface on the system. When using `::`, all available IPv6- and IPv4-addresses will be used.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
Version 0.3.0 (2018-)
|
||||
- Allow passing settings (except lists) via environment variables (Issue #100) @danielperna84
|
||||
- Allow passing settings via environment variables (Issue #100) @danielperna84
|
||||
- Added basic git stash functionality (Issue #16) @danielperna84
|
||||
|
||||
Version 0.2.9 (2018-06-22)
|
||||
|
|
|
@ -3399,6 +3399,7 @@ def load_settings(settingsfile):
|
|||
ENV_PREFIX = settings.get('ENV_PREFIX', ENV_PREFIX)
|
||||
for key, value in os.environ.items():
|
||||
if key.startswith(ENV_PREFIX):
|
||||
print("Got setting: %s" % key)
|
||||
# Convert booleans
|
||||
if value in ['true', 'false', 'True', 'False']:
|
||||
value = True if value in ['true', 'True'] else False
|
||||
|
@ -3408,6 +3409,10 @@ def load_settings(settingsfile):
|
|||
# Convert plain numbers
|
||||
elif value.isnumeric():
|
||||
value = int(value)
|
||||
# Make lists out of comma separated values for list-settings
|
||||
elif key[len(ENV_PREFIX):] in ["ALLOWED_NETWORKS", "BANNED_IPS", "IGNORE_PATTERN"]:
|
||||
print("got networks: %s" % value)
|
||||
value = value.split(',')
|
||||
settings[key[len(ENV_PREFIX):]] = value
|
||||
LISTENIP = settings.get("LISTENIP", LISTENIP)
|
||||
LISTENPORT = settings.get("LISTENPORT", LISTENPORT)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue