Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot pass in authConfig via environment variable #460

Closed
alukach opened this issue Aug 7, 2024 · 1 comment · May be fixed by #461
Closed

Cannot pass in authConfig via environment variable #460

alukach opened this issue Aug 7, 2024 · 1 comment · May be fixed by #461

Comments

@alukach
Copy link

alukach commented Aug 7, 2024

I don't believe that it is currently possible to set the authConfig via environment variable.

Issue

  1. Build docker image: docker build -t stac-browser
  2. Run docker image with auth config set as environment variable: docker run -it -e SB_authConfig='{"foo": "bar"}' --name stac-browser stac-browser
  3. In another terminal, review the generated config: 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:

window.STAC_BROWSER_CONFIG = {
  authConfig: '{"foo": "bar"}',
}

Cause

This is caused by the fact that when we parse the SB_* environment values based on their type as specified in the config.schema.json we don't handle the object type so it is run through the catch-all safe_echo code:

"authConfig": {
"type": [
"object"
],
"allOf": [
{
"$ref": "https://stac-extensions.github.io/authentication/v1.1.0/schema.json"
}
],
"noCLI": true,
"noEnv": true
}

env -0 | cut -f1 -d= | tr '\0' '\n' | grep "^SB_" | {
echo "window.STAC_BROWSER_CONFIG = {"
while IFS='=' read -r name; do
# Strip the prefix
argname="${name#SB_}"
# Read the variable's value
value="$(eval "echo \"\$$name\"")"
# Get the argument type from the schema
argtype="$(echo "$config_schema" | jq -r ".properties.$argname.type[0]")"
arraytype="$(echo "$config_schema" | jq -r ".properties.$argname.items.type[0]")"
# Encode key/value
echo -n " $argname: "
case "$argtype" in
string)
safe_echo "$value"
;;
boolean)
bool "$value"
;;
integer | number)
object "$value"
;;
array)
array "$value" "$arraytype"
;;
*)
safe_echo "$value"
;;
esac
echo ","
done
echo "}"
} > /usr/share/nginx/html/config.js

This keeps it as a string:

# echo a string, handling different types
safe_echo() {

@alukach
Copy link
Author

alukach commented Aug 9, 2024

As @m-mohr pointed out, the docs do indeed state that this is unsupported. Discussion on whether it should be supported can take place in #461.

@alukach alukach closed this as completed Aug 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant