From a6f40e47431d075eebd73716d8846f909fb63bc8 Mon Sep 17 00:00:00 2001 From: Marcus Date: Thu, 29 Feb 2024 10:08:39 +0100 Subject: [PATCH] black --- conftest.py | 3 ++- examples/example_fastapi.py | 2 ++ examples/example_flask.py | 12 +++++++----- flaat/__init__.py | 1 + flaat/aio/overrides_test.py | 1 + flaat/flaat_userinfo.py | 8 +++++--- flaat/requirements.py | 1 + flaat/tests/issuers_test.py | 1 + 8 files changed, 20 insertions(+), 9 deletions(-) diff --git a/conftest.py b/conftest.py index 7879d69..8302bf0 100644 --- a/conftest.py +++ b/conftest.py @@ -3,6 +3,7 @@ If the tests are run by CI, we mock user infos here. """ + import logging from typing import Optional @@ -87,7 +88,7 @@ def mock_user_for_ci(): "get_user_infos_from_access_token", _mock_get_user_infos_from_access_token, ) - for (key, value) in [ + for key, value in [ ("FLAAT_ISS", _jwt_issuer), ("NON_JWT_FLAAT_ISS", _non_jwt_issuer), ("FLAAT_TRUSTED_OPS_LIST", [_jwt_issuer, _non_jwt_issuer]), diff --git a/examples/example_fastapi.py b/examples/example_fastapi.py index 420932d..288e7db 100644 --- a/examples/example_fastapi.py +++ b/examples/example_fastapi.py @@ -133,6 +133,7 @@ def authorized_level( match=1, ) + @app.get("/authorized_claim") @flaat.requires(email_requirement) def authorized_claim( @@ -154,6 +155,7 @@ def authorized_claim( match=2, ) + @app.get("/authorized_vo") @flaat.requires(vo_requirement) def authorized_vo( diff --git a/examples/example_flask.py b/examples/example_flask.py index af0be80..27ccb06 100644 --- a/examples/example_flask.py +++ b/examples/example_flask.py @@ -24,13 +24,15 @@ # Set a list of access levels to use def is_admin(user_infos): - return user_infos.user_info['email'] in current_app.config['ADMIN_EMAILS'] + return user_infos.user_info["email"] in current_app.config["ADMIN_EMAILS"] -flaat = Flaat([ - AccessLevel("user", HasSubIss()), - AccessLevel("admin", IsTrue(is_admin)), -]) +flaat = Flaat( + [ + AccessLevel("user", HasSubIss()), + AccessLevel("admin", IsTrue(is_admin)), + ] +) class Config(object): diff --git a/flaat/__init__.py b/flaat/__init__.py index 5fc9a6d..e4c6c8e 100644 --- a/flaat/__init__.py +++ b/flaat/__init__.py @@ -2,6 +2,7 @@ Python support for OIDC Access Tokens -- FLAAT. Use decorators for authorising access to OIDC authenticated REST APIs. """ + # This code is distributed under the MIT License from __future__ import annotations diff --git a/flaat/aio/overrides_test.py b/flaat/aio/overrides_test.py index d57e0ff..0c762e9 100644 --- a/flaat/aio/overrides_test.py +++ b/flaat/aio/overrides_test.py @@ -3,6 +3,7 @@ FIXME The environment overrides in here are crude and will not work if run concurrently! """ + import os from typing import Optional diff --git a/flaat/flaat_userinfo.py b/flaat/flaat_userinfo.py index e8f6c4a..cf0fb7f 100755 --- a/flaat/flaat_userinfo.py +++ b/flaat/flaat_userinfo.py @@ -354,9 +354,11 @@ def print_human_readable(self, args): if self.user_infos.valid_for_secs is not None: logger.info( - "Your token is valid for %s." - if self.user_infos.valid_for_secs > 0 - else "Your token has EXPIRED for %s!", + ( + "Your token is valid for %s." + if self.user_infos.valid_for_secs > 0 + else "Your token has EXPIRED for %s!" + ), format_timespan(self.user_infos.valid_for_secs), ) diff --git a/flaat/requirements.py b/flaat/requirements.py index 8fd3bfa..88d8268 100644 --- a/flaat/requirements.py +++ b/flaat/requirements.py @@ -5,6 +5,7 @@ If you want to combine multiple requirements use the "meta requirements" :class:`AllOf` and :class:`N_Of`. """ + import logging from dataclasses import dataclass from typing import Any, Callable, List, Optional, Union diff --git a/flaat/tests/issuers_test.py b/flaat/tests/issuers_test.py index b765589..dce6a02 100644 --- a/flaat/tests/issuers_test.py +++ b/flaat/tests/issuers_test.py @@ -25,6 +25,7 @@ def test_valid_url_https_path(self): def test_valid_url_https_port_path(self): assert is_url("https://heise.de:9000/thi_s&is=difficult") + def test_short_url(self): assert is_url("https://keycloak")