File tree 2 files changed +21
-0
lines changed
2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -69,6 +69,16 @@ _Requires Python 3.6+_
69
69
70
70
` python3 -m mqtt_io config.yml `
71
71
72
+ Some configuration parameters can be passed as environment variables:
73
+
74
+ - ` MQTT_IO_HOST ` - Host name or IP address of the MQTT server.
75
+ - ` MQTT_IO_PORT ` - Port number to connect to on the MQTT server.
76
+ - ` MQTT_IO_USER ` - Username to authenticate with on the MQTT server.
77
+ - ` MQTT_IO_PASSWORD ` - Password to authenticate with on the MQTT server.
78
+ - ` MQTT_IO_PROTOCOL ` - Version of the MQTT protocol to use.
79
+
80
+ Environment variables take precedence over configuration files.
81
+
72
82
## Configuration Example
73
83
74
84
Configuration is written in a YAML file which is passed as an argument to the server on startup.
Original file line number Diff line number Diff line change 4
4
import argparse
5
5
import logging .config
6
6
import sys
7
+ from os import getenv
7
8
from copy import deepcopy
8
9
from hashlib import sha256
9
10
from typing import Any , Optional
@@ -76,6 +77,16 @@ def main() -> None:
76
77
# Load, validate and normalise config, or quit.
77
78
try :
78
79
raw_config = load_config (args .config , args .render )
80
+ if raw_config :
81
+ if "mqtt" not in raw_config or raw_config ["mqtt" ] is None :
82
+ raw_config ["mqtt" ] = {}
83
+ raw_config ["mqtt" ]["host" ] = getenv ("MQTT_IO_HOST" , raw_config ["mqtt" ].get ("host" ))
84
+ raw_config ["mqtt" ]["port" ] = getenv ("MQTT_IO_PORT" , raw_config ["mqtt" ].get ("port" ))
85
+ raw_config ["mqtt" ]["user" ] = getenv ("MQTT_IO_USER" , raw_config ["mqtt" ].get ("user" ))
86
+ raw_config ["mqtt" ]["password" ] = getenv ("MQTT_IO_PASSWORD" ,
87
+ raw_config ["mqtt" ].get ("password" ))
88
+ raw_config ["mqtt" ]["protocol" ] = getenv ("MQTT_IO_PROTOCOL" ,
89
+ raw_config ["mqtt" ].get ("protocol" ))
79
90
config = validate_and_normalise_main_config (raw_config )
80
91
except ConfigValidationFailed as exc :
81
92
print (str (exc ), file = sys .stderr )
You can’t perform that action at this time.
0 commit comments