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

Feature.extendprecommit #375

Open
wants to merge 12 commits into
base: develop
Choose a base branch
from
24 changes: 24 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,27 @@ repos:
rev: 6.1.0
hooks:
- id: flake8
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.1
hooks:
- id: ruff
args: [ --fix, --exit-non-zero-on-fix, --show-fixes ]
exclude: (alembic/.*)
- repo: local
hooks:
- id: mypy
name: mypy
language: system
entry: "mypy"
types: [ python ]
require_serial: true
verbose: true
args:
- --no-warn-incomplete-stub
- --ignore-missing-imports
- --no-warn-unused-ignores
- --allow-untyped-decorators
- --no-namespace-packages
- --allow-untyped-globals
- --check-untyped-defs
exclude: "(alembic/.*)|(.*test.*)"
2 changes: 1 addition & 1 deletion src/cnaas_nms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def setup_package():
from cnaas_nms.api.tests.app_wrapper import TestAppWrapper

app = cnaas_nms.api.app.app
app.wsgi_app = TestAppWrapper(app.wsgi_app, None)
app.wsgi_app = TestAppWrapper(app.wsgi_app, None) # type: ignore
client = app.test_client()
data = {"action": "refresh"}
client.put("/api/v1.0/repository/settings", json=data)
Expand Down
11 changes: 6 additions & 5 deletions src/cnaas_nms/api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ def socketio_on_connect():
if auth_settings.OIDC_ENABLED:
try:
token = oauth_required.get_token_validator("bearer").authenticate_token(token_string)
user = get_oauth_token_info(token)[auth_settings.OIDC_USERNAME_ATTRIBUTE]
token_info = get_oauth_token_info(token)
user = token_info[auth_settings.OIDC_USERNAME_ATTRIBUTE]
except InvalidTokenError as e:
logger.debug("InvalidTokenError: " + format(e))
return False
Expand Down Expand Up @@ -229,21 +230,21 @@ def log_request(response):
elif request.method in ["GET", "POST", "PUT", "DELETE", "PATCH"]:
try:
if auth_settings.OIDC_ENABLED:
token_string = request.headers.get("Authorization").split(" ")[-1]
token_string = str(request.headers.get("Authorization")).split(" ")[-1]
token = oauth_required.get_token_validator("bearer").authenticate_token(token_string)
token_info = get_oauth_token_info(token)
if auth_settings.OIDC_USERNAME_ATTRIBUTE in token_info:
if token_info is not None and auth_settings.OIDC_USERNAME_ATTRIBUTE in token_info:
user = "User: {} ({}), ".format(
get_oauth_token_info(token)[auth_settings.OIDC_USERNAME_ATTRIBUTE],
auth_settings.OIDC_USERNAME_ATTRIBUTE,
)
elif "client_id" in token_info:
elif token_info is not None and "client_id" in token_info:
user = "User: {} (client_id), ".format(get_oauth_token_info(token)["client_id"])
else:
logger.warning("Could not get user info from token")
raise ValueError
else:
token_string = request.headers.get("Authorization").split(" ")[-1]
token_string = str(request.headers.get("Authorization")).split(" ")[-1]
user = "User: {}, ".format(decode_token(token_string).get("sub"))
except Exception:
user = "User: unknown, "
Expand Down
6 changes: 3 additions & 3 deletions src/cnaas_nms/api/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def get(self):

req = PreparedRequest()
req.prepare_url(url, parameters)
resp = redirect(req.url, code=302)
resp = redirect(str(req.url), code=302)
if "refresh_token" in token:
resp.set_cookie(
"REFRESH_TOKEN",
Expand All @@ -106,7 +106,7 @@ class RefreshApi(Resource):
def post(self):
oauth_client = current_app.extensions["authlib.integrations.flask_client"]
oauth_client_connext: FlaskOAuth2App = oauth_client.connext
token_string = request.headers.get("Authorization").split(" ")[-1]
token_string = str(request.headers.get("Authorization")).split(" ")[-1]
oauth_client_connext.token = token_string
oauth_client_connext.load_server_metadata()
url = oauth_client_connext.server_metadata["token_endpoint"]
Expand Down Expand Up @@ -155,7 +155,7 @@ def get(self):
logger.debug("No permissions defined, so nobody is permitted to do any api calls.")
return []
user_info = get_oauth_token_info(current_token)
permissions_of_user = get_permissions_user(permissions_rules, user_info)
permissions_of_user = get_permissions_user(permissions_rules, user_info) # check check

# convert to dictionaries so it can be converted to json
permissions_as_dics = []
Expand Down
Loading
Loading