Skip to content

Commit

Permalink
Follow lint rules and remove debugger statement.
Browse files Browse the repository at this point in the history
Closes pulp#926
  • Loading branch information
decko committed Jul 11, 2024
1 parent c769fd7 commit 8ec3970
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
10 changes: 5 additions & 5 deletions pulp-glue/pulp_glue/common/openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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).
Expand Down
27 changes: 15 additions & 12 deletions pulpcore/cli/common/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)


##############################################################################
Expand Down

0 comments on commit 8ec3970

Please sign in to comment.