Permit passing config object via env vars #461
+4
−16
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What I'm changing
If a config value is an object, the tooling to convert it from an environment var to JS will keep it as a string (see #460).
This PR will instead retain its state as a JSON object.
This will allow the following configurations to be correctly set via environment variables:
How I did it
The inability to pass in objects via ENV vars was caused by the fact that when we parse the
SB_*
environment values based on their type as specified in theconfig.schema.json
; however, we don't specifically handle theobject
type so it is run through the catch-allsafe_echo
code:stac-browser/config.schema.json
Lines 225 to 236 in 108947e
stac-browser/docker/docker-entrypoint.sh
Lines 58 to 92 in 108947e
This keeps it as a string:
stac-browser/docker/docker-entrypoint.sh
Lines 1 to 2 in 108947e
However, if we permit configurations of type "object" to encoded directly into the JSON via the
object()
function in the bash script, we can use them as standard configuration.How you can test this
Before
On the
main
branch:docker build -t stac-browser
docker run -it -e SB_authConfig='{"foo": "bar"}' --name stac-browser stac-browser
docker exec stac-browser cat /usr/share/nginx/html/config.js
You should see an object where the
authConfig
property is a string rather than an object:After
Following the above steps on this branch, you should see now see an object where the
authConfig
property is an object:closes #460