Header environment placeholder not compatible with oauth2
gnthibault opened this issue · comments
To whom it may concern,
I think there is an issue with the get_header_value method:
ariadne-codegen/ariadne_codegen/settings.py
Line 246 in 8bc4388
In particular, the value.startswith won't work in case you have the following type of config for oauth2:
remote_schema_headers = {"Authorization" = "Bearer $AUTH_TOKEN"} # extra headers that are passed along with introspection query
As a workaround you can do something like
export BEARER_AUTH_TOKEN="Bearer $AUTH_TOKEN"
and use the variable $BEARER_AUTH_TOKEN
instead.
Another alternative is to extend the BaseClient
and set the header yourself, this is what I've done.
proposed naive version:
def get_header_value(value: str) -> str:
env_var_prefix = "$"
l_keys = value.strip().split(sep=" ")
compiled_keys = []
for key in l_keys:
token_pos = key.rfind(env_var_prefix)
if token_pos >= 0 and token_pos<len(key)-1:
env_var_name = key[token_pos+1:]
var_value = os.environ.get(env_var_name)
if not var_value:
raise InvalidConfiguration(
f"Environment variable {env_var_name} not found."
)
else:
key = key[:token_pos] + var_value
compiled_keys.append(key)
return " ".join(compiled_keys)
@bombsimon solution is the way to do it. We could add the note in the docs that we are not doing any complex parsing on setting values.
@bombsimon This utility is used only for headers attached to remote schema introspection query (remote_schema_headers
config option). Extending BaseClient
won't have an effect here, so 1st approach with export ...
is the way to do it.
Ok good for me, I will close the issue