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

Remove use of next keyword as a variable #3131

Merged
merged 2 commits into from
Dec 23, 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
6 changes: 3 additions & 3 deletions lib/pbench/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,10 +436,10 @@ def get_list(self, **kwargs) -> Iterator[Dataset]:
while True:
for d in json["results"]:
yield Dataset(d)
next = json.get("next_url")
if "offset" in args or not next:
next_url = json.get("next_url")
if "offset" in args or not next_url:
break
json = self.get(uri=next).json()
json = self.get(uri=next_url).json()

def get_metadata(self, dataset_id: str, metadata: list[str]) -> JSONOBJECT:
"""Return requested metadata for a specified dataset.
Expand Down
16 changes: 10 additions & 6 deletions lib/pbench/server/auth/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
import os
from typing import Optional

from flask import abort, request
from flask import request
from flask_httpauth import HTTPTokenAuth
from flask_restful import abort
import jwt

from pbench.server.auth import OpenIDClient, OpenIDClientError
Expand Down Expand Up @@ -60,26 +61,29 @@ def get_secret_key(self):

def get_auth_token(self, logger):
# get auth token
example = (
"Please add Authorization header with Bearer token as,"
" 'Authorization: Bearer <session_token>'"
)
auth_header = request.headers.get("Authorization")

if not auth_header:
abort(
HTTPStatus.FORBIDDEN,
message="Please add authorization token as 'Authorization: Bearer <session_token>'",
message=f"No Authorization header provided. {example}",
)

try:
auth_schema, auth_token = auth_header.split()
auth_schema, auth_token = auth_header.split(" ", 1)
except ValueError:
abort(
HTTPStatus.UNAUTHORIZED,
message="Malformed Authorization header, please add request header as Authorization: Bearer <session_token>",
message=f"Malformed Authorization header. {example}",
)
else:
if auth_schema.lower() != "bearer":
abort(
HTTPStatus.UNAUTHORIZED,
message="Malformed Authorization header, request needs bearer token: Bearer <session_token>",
message=f"Malformed Authorization header. {example}",
)
return auth_token

Expand Down