geopython / pygeoapi

pygeoapi is a Python server implementation of the OGC API suite of standards. The project emerged as part of the next generation OGC API efforts in 2018 and provides the capability for organizations to deploy a RESTful OGC API endpoint using OpenAPI, GeoJSON, and HTML. pygeoapi is open source and released under an MIT license.
https://pygeoapi.io
MIT License
483 stars 258 forks source link

implement env variables inside PYGEOAPI_CONFIG file #248

Closed jorgejesus closed 4 years ago

jorgejesus commented 4 years ago

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

devop systems (docker, k8) use enviroment variable to set parameters like database connections of set passwords inside containers.

For example running pygeopai in openshift and we want to connect to a database that has a secret password. Currentely we would have to set the password on the yaml configuration file and this could be a security problem, while openshift can set the secret env inside the pod from a secure source

Describe the solution you'd like Parse the PYGEOAPI_CONFIG yaml file with python module envyaml (https://github.com/thesimj/envyaml). The current default module yaml should be replaced by envyaml as parser allowing for env variables to be injected into the yaml file

Describe alternatives you've considered The dataprovider would get the env variables by it self, IMHO this is less elegant and we may need the described solutions for other configurations

Additional context Add any other context or screenshots about the feature request here. image

jorgejesus commented 4 years ago

Suggestion for implementation: @francbartoli I’ve used this package in the past https://configurator.readthedocs.io/en/latest/patterns.html#config-file-overlaid-with-environment-variables

jorgejesus commented 4 years ago

@tomkralidis Another suggestion is to code en stackoverflow that can replace the yaml variables https://stackoverflow.com/questions/52412297/how-to-replace-environment-variable-value-in-yaml-file-to-be-parsed-using-python/52412796#52412796

jorgejesus commented 4 years ago

Code examples: https://www.programcreek.com/python/example/61563/yaml.add_implicit_resolver

ayan-usgs commented 4 years ago

I have a similar use case (e.g. I want to pass configuration in via environment variables).

@jorgejesus -- If you're already working on this, I'll refrain from working on this. Otherwise, I'm up for taking on the implementation of this.

alpha-beta-soup commented 4 years ago

An alternative strategy is to implement something like an inheritance model, like Docker Compose does: docker-compose -f docker-compose.base.yml -f docker-compose.dev.yml build service where the second configuration (docker-compose.yml) only contains information that overrides key/values in the first configuration. I use that pattern frequently; I commit the base configuration, but not the configuration for a particular stage (since it's where I keep secrets). I find this easier than working with environment variables, as it's more portable and I don't need to worry about collisions. It would also allow for configurations to be split into multiple files as a secondary advantage.

jorgejesus commented 4 years ago

@ayan-usgs Thank you for the info that you are implementing thing, if you are working on this ticket please go ahead and change the ticket to inprogress, I will not go ahead

ayan-usgs commented 4 years ago

Looks like @tomkralidis already has a PR for this. :smile: