flyte / mqtt-io

Expose GPIO modules (Raspberry Pi, Beaglebone, PCF8754, PiFace2 etc.) and digital sensors (LM75 etc.) to an MQTT server for remote control and monitoring.
MIT License
467 stars 158 forks source link

[Feature] Consume host/user/pass from env variables or command line #406

Closed mahnunchik closed 1 day ago

mahnunchik commented 3 weeks ago

Is your feature request related to a problem? Please describe.

I'd like to bring to mqtt-io ability to be launched in single click as Home Assistant integration. To implement this, it is required to add the ability to read authentication related configuration values from environment variables or from the command line.

Describe the solution you'd like

Option 1: Env vars

export MQTT_IO_HOST="core-mosquitto"
export MQTT_IO_USER="addons"
export MQTT_IO_PASS="12345"
python -m mqtt_io config.yml

Option 2: Command line arguments

python -m mqtt_io config.yml --host="core-mosquitto" --user="addons" --pass="12345"

The questions are:

  1. How is better to implement this feature? Any ideas?
  2. Should env vars or command line arguments has precedence over yaml configuration? According to old spec - yes (https://12factor.net/config)
  3. Should it be validated separately or together with the main config? According to common sense - yes 😉

Describe alternatives you've considered

It is possible to implement the similar behaviour on top of current implementation

python -m mqtt_io --render render.yaml config.yaml
# render.yaml
backends:
  env:
    type: env
    prefix: 'MQTT_IO'
# config.yaml
mqtt:
  host: { { env('HOST') } }
  user: { { env('USER') } }
  password: { { env('PASS') } }
  ha_discovery:
    enabled: true

More info: https://github.com/hassio-addons/addon-mqtt-io/issues/19

But in the maintainer's opinion and in my opinion, this is too complicated and error prone a design for configuration.

Additional context

I'd like to work on this feature in the core https://github.com/flyte/mqtt-io and ha addon https://github.com/hassio-addons/addon-mqtt-io/

Related issues:

  1. https://github.com/hassio-addons/addon-mqtt-io/issues/19
  2. https://github.com/hassio-addons/addon-mqtt-io/issues/134 - I've described how to load necessary auth data from HA core.
  3. https://github.com/flyte/mqtt-io/issues/399 - I'd like to fix config not found issues too
  4. https://github.com/hassio-addons/addon-mqtt-io/issues/110
  5. https://github.com/flyte/mqtt-io/issues/279
  6. https://github.com/flyte/mqtt-io/issues/209
BenjiU commented 1 day ago

merged