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

Merged
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
10f2f1a
replace fcntl lib to portalocker
Oct 7, 2024
687d393
replace the fcntl locker with portalocker to make os independent
Oct 9, 2024
2319870
Added ruff to the pre-commit
Josephine-Rutten Oct 17, 2024
52d76c6
add mypy to pre-commit and solved mypy errors
Oct 25, 2024
c7457af
fix bugs unittests
Oct 28, 2024
9dd2a92
replace fcntl lib to portalocker
Oct 7, 2024
51cd87a
replace the fcntl locker with portalocker to make os independent
Oct 9, 2024
4916854
Added ruff to the pre-commit
Josephine-Rutten Oct 17, 2024
2d69f8b
add mypy to pre-commit and solved mypy errors
Oct 25, 2024
bdf62ec
fix bugs unittests
Oct 28, 2024
45f16c0
fix last mypy issues
Oct 28, 2024
2a806ed
small fix
Oct 29, 2024
7c101c2
small code improvements based on sonar cloud warnings
Nov 8, 2024
15f4e0c
solve severity high issues of sonar cloud
Nov 8, 2024
2be1736
changes based on Johan's feedback
Nov 26, 2024
33780df
merge + mypy
Nov 26, 2024
674e054
Replace packages by ruff
Nov 27, 2024
2920582
more typing etc based on johans feedback
Nov 28, 2024
33791b1
added mypy.ini
Nov 29, 2024
18b4b26
update requirements
Nov 29, 2024
f615ac9
updated requirements
Dec 3, 2024
9de0063
fix requirement + mypy.ini + remove | None for optional
Dec 3, 2024
a13ce48
reworked change based on johan's comment
Dec 3, 2024
e14bec0
changed base don johan's review
Dec 3, 2024
e8b925d
formatting problem
Dec 3, 2024
7e52b03
formatting issues
Dec 3, 2024
a83cea3
Merge branch 'develop' into feature.extendprecommit
Dec 3, 2024
7f27aa5
small issue + more formatting issues
Dec 3, 2024
caaca59
fix bug in device_upgrade_task
Dec 4, 2024
8cb6d73
remove the extra unneccsary condition to appease the integration tests
Dec 4, 2024
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
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
indy-independence marked this conversation as resolved.
Show resolved Hide resolved
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Were these required for cnaas-nms or like a basic config copied from somewhere?

Copy link
Collaborator Author

@Josephine-Rutten Josephine-Rutten Nov 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The args have been checked and are needed for cnaas-nms. Might be good to keep an eye on that. It could be a good idea to check if the issues we ignore now could be good code improvements, but for now I thought this code improvement was getting really big and it was better to improve it incremental. The other settings I took from Workflow Orchestrator.

- --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
Josephine-Rutten marked this conversation as resolved.
Show resolved Hide resolved

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