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

Header environment placeholder not compatible with oauth2 #231

Closed
gnthibault opened this issue Oct 19, 2023 · 5 comments
Closed

Header environment placeholder not compatible with oauth2 #231

gnthibault opened this issue Oct 19, 2023 · 5 comments

Comments

@gnthibault
Copy link

To whom it may concern,
I think there is an issue with the get_header_value method:

env_var_prefix = "$"

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

@bombsimon
Copy link
Contributor

bombsimon commented Oct 19, 2023

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.

@gnthibault
Copy link
Author

gnthibault commented Oct 19, 2023

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)

@rafalp
Copy link
Contributor

rafalp commented Oct 30, 2023

@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.

@mat-sop
Copy link
Contributor

mat-sop commented Oct 30, 2023

@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.

@gnthibault
Copy link
Author

Ok good for me, I will close the issue

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

No branches or pull requests

4 participants