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

Add a decorator function for passing the OIDC URL #164

Merged
merged 1 commit into from
Jul 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions fedcloudclient/checkin.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
DEFAULT_OIDC_URL,
oidc_access_token_params,
oidc_params,
oidc_params_with_url,
oidc_refresh_token_params,
)

Expand Down Expand Up @@ -319,11 +320,10 @@ def check(oidc_refresh_token, oidc_access_token):


@token.command()
@oidc_params
def list_vos(access_token):
@oidc_params_with_url
def list_vos(access_token, oidc_url):
"""
List VO membership(s) of access token
"""

vos = token_list_vos(access_token, DEFAULT_OIDC_URL)
vos = token_list_vos(access_token, oidc_url)
print("\n".join(vos))
67 changes: 67 additions & 0 deletions fedcloudclient/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,73 @@ def wrapper(*args, **kwargs):
return wrapper


def oidc_params_with_url(func):
"""
Decorator for OIDC parameters.
Get access token from oidc-* parameters and replace them in the wrapper function
Also adds the OIDC URL as part of the call to the inner function
"""

@optgroup.group("OIDC token", help="Choose one of options for providing token")
@optgroup.option(
"--oidc-agent-account",
help="Account name in oidc-agent",
envvar="OIDC_AGENT_ACCOUNT",
metavar="account",
)
@optgroup.option(
"--oidc-access-token",
help="OIDC access token",
envvar="OIDC_ACCESS_TOKEN",
metavar="token",
)
@optgroup.option(
"--oidc-refresh-token",
help="OIDC refresh token. Require also client ID and secret",
envvar="OIDC_REFRESH_TOKEN",
metavar="token",
)
@optgroup.option(
"--oidc-client-id",
help="OIDC client ID",
envvar="OIDC_CLIENT_ID",
metavar="id",
)
@optgroup.option(
"--oidc-client-secret",
help="OIDC client secret",
envvar="OIDC_CLIENT_SECRET",
metavar="secret",
)
@optgroup.option(
"--oidc-url",
help="OIDC identity provider URL",
envvar="OIDC_URL",
default=DEFAULT_OIDC_URL,
show_default=True,
metavar="provider-url",
)
@wraps(func)
def wrapper(*args, **kwargs):
from fedcloudclient.checkin import get_access_token

oidc_url = kwargs.pop("oidc_url")

access_token = get_access_token(
kwargs.pop("oidc_access_token"),
kwargs.pop("oidc_refresh_token"),
kwargs.pop("oidc_client_id"),
kwargs.pop("oidc_client_secret"),
oidc_url,
kwargs.pop("oidc_agent_account"),
)
kwargs["access_token"] = access_token
kwargs["oidc_url"] = oidc_url
return func(*args, **kwargs)

return wrapper


def openstack_params(func):
"""
Decorator for OpenStack authentication parameters
Expand Down