Cumulocity-IoT / cumulocity-devicemanagement-agent

Cumulocity Reference Agent written in Python to demonstrate most of the Device Management Capabilities of Cumulocity IoT
Apache License 2.0
26 stars 20 forks source link

read environment variables into config #35

Closed 6293 closed 3 years ago

6293 commented 3 years ago

https://github.com/SoftwareAG/cumulocity-devicemanagement-agent/issues/25#issuecomment-915094898

Basically this change will help you start docker container (start.sh) with config modified for given tenant:

C8YDM_MQTT_URL=<tenant domain> \
C8YDM_MQTT_CERT_AUTH=true \
C8YDM_SECRET_C8Y__BOOTSTRAP__TENANT=<tenant id> \
C8YDM_SECRET_C8Y__BOOTSTRAP__USER=<tenant username> \
C8YDM_SECRET_C8Y__BOOTSTRAP__PASSWORD=<tenant password> \
C8YDM_SECRET_C8Y__TENANT=<subtenant id> \
C8YDM_SECRET_C8Y__USERNAME=<subtenant username> \
C8YDM_SECRET_C8Y__PASSWORD=<subtenant password> \
./start.sh

By executing this, certificates will be generated and the root ca is uploaded to your tenant, then the agent will connect to the tenant with cert authentication.

6293 commented 3 years ago

will update README after holidays

switschel commented 3 years ago

Hi @z8674558,

I tried your branch. In general both authentication methods (user +pw & certificates) should be supported. Unfortunately your changes broke the user + pw bootstrapping authentication. Most likely because you added dummy config entries for externalId, tenant, user and password in the agent.ini. If I remove them bootstrapping is working again.

Any way how this can be improved that both modes can run in parallel e.g. detect if ENV variables are set overwrite the whole config entries otherwise use config file values.

6293 commented 3 years ago

thank you @switschel, I was not aware of it.

Now the override is done by modifying agent.ini when the creation of Configuration object, instead of modifying interpolation logic. This enables you to override values even if agent.ini does not have a corresponding category/key yet.

It looks like I don't have a permission to accept device bootstrapping in my tenant, so please check if bootstrapping is working fine (I have checked that a device can connect to bootstrapping tenant though).

switschel commented 3 years ago

On start with ./start.sh without setting the env variables I get this scripts/start_docker.sh: line 8: C8YDM_MQTT_CERT_AUTH: unbound variable I think this can be avoided by using if [ -n "${C8YDM_MQTT_CERT_AUTH:-}"

6293 commented 3 years ago

Thank you for the support. will add test modules