Created
April 20, 2022 15:49
-
-
Save pivotaljohn/b70c10220c159847e49617df6fc06ace to your computer and use it in GitHub Desktop.
Extracting environment variable-set config for a Backstage app.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#@ load("@ytt:data", "data") | |
#@ def removeprefix(prefix, s): | |
#@ return s[len(prefix):] if s.startswith(prefix) else s | |
#@ end | |
#@ def config_key_for(auth_var_expr): | |
#@ var_name_parts = \ | |
#@ removeprefix("..._", auth_var_expr) \ | |
#@ .split("_") | |
#@ config_key_parts = \ | |
#@ [var_name_parts[0].lower()] + \ | |
#@ [part.capitalize() for part in var_name_parts[1:]] | |
#@ return "".join(config_key_parts) | |
#@ end | |
#@ def env_var_for(provider_name, auth_var_expr): | |
#@ return "${AUTH_" + provider_name.upper() + "_" + removeprefix("..._", auth_var_expr) + "}" | |
#@ end | |
--- | |
#@yaml/text-templated-strings | |
auth: | |
#@ for provider in data.values.auth: | |
(@= provider @): | |
#@ for auth_var in data.values.auth[provider]: | |
(@= config_key_for(auth_var) @): #@ env_var_for(provider, auth_var) | |
#@ end | |
#@ end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#@data/values | |
--- | |
auth: | |
google: ['..._CLIENT_ID', '..._CLIENT_SECRET'] | |
auth0: ['..._CLIENT_ID', '..._CLIENT_SECRET'] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment