From b47403df1ebdbc81cb2aa26423f27e87debdc095 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20=22decko=22=20de=20Brito?= Date: Thu, 11 Jul 2024 18:14:49 -0300 Subject: [PATCH] Follow lint rules and remove debugger statement. Closes #926 --- pulp-glue/pulp_glue/common/openapi.py | 10 +++++----- pulpcore/cli/common/generic.py | 27 +++++++++++++++------------ 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/pulp-glue/pulp_glue/common/openapi.py b/pulp-glue/pulp_glue/common/openapi.py index 0d0a1b80f..6d0b5d2aa 100644 --- a/pulp-glue/pulp_glue/common/openapi.py +++ b/pulp-glue/pulp_glue/common/openapi.py @@ -73,10 +73,10 @@ def __call__( for proposal in security: for name in proposal: authorized_schemes.append(security_schemes[name]) - authorized_schemes_types.add(security_schemes[name]['type']) + authorized_schemes_types.add(security_schemes[name]["type"]) if "oauth2" in authorized_schemes_types: - oauth_flow = [flow for flow in authorized_schemes if flow['type'] == "oauth2"][0] + oauth_flow = [flow for flow in authorized_schemes if flow["type"] == "oauth2"][0] result = self.auth(oauth_flow) elif "http" in authorized_schemes_types: result = self.basic_auth() @@ -106,8 +106,6 @@ def __init__(self, username: str, password: str): self.client_secret = password def auth(self, oauth_payload) -> requests.auth.AuthBase: - __import__('ipdb').set_trace() - response: requests.Response = requests.get() pass @@ -634,7 +632,9 @@ def render_request( # Bad idea, but you wanted it that way. auth = None else: - auth: AuthProviderBase = self.auth_provider(security, self.api_spec["components"]["securitySchemes"]) + auth: AuthProviderBase = self.auth_provider( + security, self.api_spec["components"]["securitySchemes"] + ) else: # No auth required? Don't provide it. # No auth_provider available? Hope for the best (should do the trick for cert auth). diff --git a/pulpcore/cli/common/generic.py b/pulpcore/cli/common/generic.py index 92cd0c28b..fa708fac9 100644 --- a/pulpcore/cli/common/generic.py +++ b/pulpcore/cli/common/generic.py @@ -240,27 +240,30 @@ def auth(self, flow): class OAuth2AuthBase(requests.auth.AuthBase): def __init__(self, *args, **kwargs): - self.client_id = kwargs.get('username') - self.client_secret = kwargs.get('password') - self.flow = kwargs.get('flow') - self.token_url = self.flow['flows']['clientCredentials']['tokenUrl'] - self.scope = [*self.flow['flows']['clientCredentials']['scopes']][0] + self.client_id = kwargs.get("username") + self.client_secret = kwargs.get("password") + self.flow = kwargs.get("flow") + self.token_url = self.flow["flows"]["clientCredentials"]["tokenUrl"] + self.scope = [*self.flow["flows"]["clientCredentials"]["scopes"]][0] def __call__(self, request): - data = {'client_id': self.client_id, - 'client_secret': self.client_secret, - 'scope': self.scope, - 'grant_type': 'client_credentials' - } + data = { + "client_id": self.client_id, + "client_secret": self.client_secret, + "scope": self.scope, + "grant_type": "client_credentials", + } response: requests.Response = requests.post(self.token_url, data=data) token = response.json() if response.status_code == 200 else None - request.headers['Authorization'] = f"Bearer {token['access_token']}" + request.headers["Authorization"] = f"Bearer {token['access_token']}" return request - return OAuth2AuthBase(username=self.pulp_ctx.username, password=self.pulp_ctx.password, flow=flow) + return OAuth2AuthBase( + username=self.pulp_ctx.username, password=self.pulp_ctx.password, flow=flow + ) ##############################################################################