canonical/edgex-snap-hooks

Setting a bad app key removes other keys from env file

Closed this issue · 1 comments

$ snap set edgex-app-service-configurable config.service-startupmsg="testing injection"
$ snap set edgex-app-service-configurable apps.app-service-configurable.config.service-port=11111
$ cat /var/snap/edgex-app-service-configurable/current/config/res/app-service-configurable.env 
export SERVICE_STARTUPMSG="testing injection"
export SERVICE_PORT="11111"

$ snap set edgex-app-service-configurable apps.app-service-configurable.config.service.port=11111
error: cannot perform the following tasks:
- Run configure hook of "edgex-app-service-configurable" snap (run hook "configure": edgex-app-service-configurable.configure: could not process options: error converting config key to environment variable key: config key must not contain dots: service.port)
$ cat /var/snap/edgex-app-service-configurable/current/config/res/app-service-configurable.env 
export SERVICE_STARTUPMSG="testing injection"

The global config processing truncates the file and starts from an empty file. The app config processing appends to it.

When an app config processing fails, the processing of the app options stops and no environment variable for app options gets appended to the file.

Possible solution: perform all processing before replacing the content of original env file.