From b4278a0dfd1aaa1c95cc811aa15f3cf9ea4a54bc Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Tue, 23 Apr 2024 17:08:18 +0300 Subject: pylint: Fix linting errors. --- gn_auth/__init__.py | 2 +- .../oauth2/grants/authorisation_code_grant.py | 8 ++++---- .../auth/authentication/oauth2/grants/jwt_bearer_grant.py | 15 +++++---------- gn_auth/auth/authorisation/resources/models.py | 3 +-- gn_auth/auth/authorisation/resources/phenotype.py | 1 - 5 files changed, 11 insertions(+), 18 deletions(-) diff --git a/gn_auth/__init__.py b/gn_auth/__init__.py index 0d0eb12..881ae1e 100644 --- a/gn_auth/__init__.py +++ b/gn_auth/__init__.py @@ -63,7 +63,7 @@ def load_secrets_conf(app: Flask) -> None: def parse_ssl_keys(app): """Parse the SSL keys.""" def __parse_key__(keypath: Path) -> JsonWebKey: - with open(keypath) as _sslkey: + with open(keypath) as _sslkey:# pylint: disable=[unspecified-encoding] return JsonWebKey.import_key(_sslkey.read()) key_storage_dir = Path(app.config["UPLOADS_DIR"]).joinpath( diff --git a/gn_auth/auth/authentication/oauth2/grants/authorisation_code_grant.py b/gn_auth/auth/authentication/oauth2/grants/authorisation_code_grant.py index ae604df..a40292e 100644 --- a/gn_auth/auth/authentication/oauth2/grants/authorisation_code_grant.py +++ b/gn_auth/auth/authentication/oauth2/grants/authorisation_code_grant.py @@ -26,16 +26,16 @@ class AuthorisationCodeGrant(grants.AuthorizationCodeGrant): GRANT_TYPE = "authorization_code" RESPONSE_TYPES = {'code'} - def create_authorization_response(self, redirect: str, grant_user): + def create_authorization_response(self, redirect_uri: str, grant_user): """Add some data to the URI""" - response = super().create_authorization_response(redirect, grant_user) + response = super().create_authorization_response( + redirect_uri, grant_user) headers = dict(response[-1]) headers = { **headers, "Location": f"{headers['Location']}&user_id={grant_user.user_id}" } - return (response[0], response[1], [ - (header, value) for header, value in headers.items()]) + return (response[0], response[1], list(headers.items())) def save_authorization_code(self, code, request): """Persist the authorisation code to database.""" diff --git a/gn_auth/auth/authentication/oauth2/grants/jwt_bearer_grant.py b/gn_auth/auth/authentication/oauth2/grants/jwt_bearer_grant.py index 85c8d2e..895acb7 100644 --- a/gn_auth/auth/authentication/oauth2/grants/jwt_bearer_grant.py +++ b/gn_auth/auth/authentication/oauth2/grants/jwt_bearer_grant.py @@ -1,19 +1,12 @@ """JWT as Authorisation Grant""" -import uuid -from urllib.parse import urlparse -from datetime import datetime, timedelta - -from flask import request, current_app as app - -from authlib.jose import jwt +from flask import current_app as app from authlib.oauth2.rfc7523.jwt_bearer import JWTBearerGrant as _JWTBearerGrant from authlib.oauth2.rfc7523.token import ( JWTBearerTokenGenerator as _JWTBearerTokenGenerator) +from gn_auth.auth.db.sqlite3 import with_db_connection from gn_auth.auth.authentication.users import user_by_id -from gn_auth.auth.db.sqlite3 import connection, with_db_connection -from gn_auth.auth.authentication.oauth2.models.oauth2client import client class JWTBearerTokenGenerator(_JWTBearerTokenGenerator): @@ -23,7 +16,9 @@ class JWTBearerTokenGenerator(_JWTBearerTokenGenerator): DEFAULT_EXPIRES_IN = 300 - def get_token_data(self, grant_type, client, expires_in=300, user=None, scope=None): + def get_token_data(#pylint: disable=[too-many-arguments] + self, grant_type, client, expires_in=300, user=None, scope=None + ): """Post process data to prevent JSON serialization problems.""" tokendata = super().get_token_data( grant_type, client, expires_in, user, scope) diff --git a/gn_auth/auth/authorisation/resources/models.py b/gn_auth/auth/authorisation/resources/models.py index 9186380..9931559 100644 --- a/gn_auth/auth/authorisation/resources/models.py +++ b/gn_auth/auth/authorisation/resources/models.py @@ -15,8 +15,7 @@ from gn_auth.auth.authorisation.errors import NotFoundError, AuthorisationError from .checks import authorised_for from .base import Resource, ResourceCategory -from .groups.models import ( - Group, GroupRole, user_group, resource_owner, is_group_leader) +from .groups.models import Group, GroupRole, user_group, is_group_leader from .mrna import ( resource_data as mrna_resource_data, attach_resources_data as mrna_attach_resources_data, diff --git a/gn_auth/auth/authorisation/resources/phenotype.py b/gn_auth/auth/authorisation/resources/phenotype.py index 6af3b0a..7005db3 100644 --- a/gn_auth/auth/authorisation/resources/phenotype.py +++ b/gn_auth/auth/authorisation/resources/phenotype.py @@ -6,7 +6,6 @@ import sqlite3 import gn_auth.auth.db.sqlite3 as db -from .groups import Group from .base import Resource from .data import __attach_data__ -- cgit v1.2.3