From 17466d8d37e838c45e2c81df930959a916a092c3 Mon Sep 17 00:00:00 2001 From: Evgeniy Alekseev Date: Wed, 25 Jan 2023 15:25:42 +0200 Subject: [PATCH] make oauth client trully optional (#84) Same old song, after migraiton to packages some optional modules are being imported globally which lead to making hard dependency --- src/ahriman/core/auth/__init__.py | 3 --- src/ahriman/core/auth/auth.py | 4 ++-- src/ahriman/core/auth/oauth.py | 2 +- src/ahriman/web/views/user/login.py | 2 +- tests/ahriman/core/auth/conftest.py | 3 ++- tests/ahriman/core/auth/test_auth.py | 4 +++- tests/ahriman/core/auth/test_mapping.py | 2 +- tests/ahriman/core/auth/test_oauth.py | 2 +- tests/ahriman/web/conftest.py | 2 +- 9 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/ahriman/core/auth/__init__.py b/src/ahriman/core/auth/__init__.py index 76cdd8f9..17c96868 100644 --- a/src/ahriman/core/auth/__init__.py +++ b/src/ahriman/core/auth/__init__.py @@ -18,6 +18,3 @@ # along with this program. If not, see . # from ahriman.core.auth.auth import Auth - -from ahriman.core.auth.mapping import Mapping -from ahriman.core.auth.oauth import OAuth diff --git a/src/ahriman/core/auth/auth.py b/src/ahriman/core/auth/auth.py index 2edcf00f..99fedc6d 100644 --- a/src/ahriman/core/auth/auth.py +++ b/src/ahriman/core/auth/auth.py @@ -78,10 +78,10 @@ class Auth(LazyLogging): """ provider = AuthSettings.from_option(configuration.get("auth", "target", fallback="disabled")) if provider == AuthSettings.Configuration: - from ahriman.core.auth import Mapping + from ahriman.core.auth.mapping import Mapping return Mapping(configuration, database) if provider == AuthSettings.OAuth: - from ahriman.core.auth import OAuth + from ahriman.core.auth.oauth import OAuth return OAuth(configuration, database) return cls(configuration) diff --git a/src/ahriman/core/auth/oauth.py b/src/ahriman/core/auth/oauth.py index f8cc00bd..6628375e 100644 --- a/src/ahriman/core/auth/oauth.py +++ b/src/ahriman/core/auth/oauth.py @@ -21,7 +21,7 @@ import aioauth_client from typing import Optional, Type -from ahriman.core.auth import Mapping +from ahriman.core.auth.mapping import Mapping from ahriman.core.configuration import Configuration from ahriman.core.database import SQLite from ahriman.core.exceptions import OptionError diff --git a/src/ahriman/web/views/user/login.py b/src/ahriman/web/views/user/login.py index 4d3970e0..e579060b 100644 --- a/src/ahriman/web/views/user/login.py +++ b/src/ahriman/web/views/user/login.py @@ -53,7 +53,7 @@ class LoginView(BaseView): Examples: This request must not be used directly. """ - from ahriman.core.auth import OAuth + from ahriman.core.auth.oauth import OAuth oauth_provider = self.validator if not isinstance(oauth_provider, OAuth): # there is actually property, but mypy does not like it anyway diff --git a/tests/ahriman/core/auth/conftest.py b/tests/ahriman/core/auth/conftest.py index 6c60788b..57d1dc35 100644 --- a/tests/ahriman/core/auth/conftest.py +++ b/tests/ahriman/core/auth/conftest.py @@ -1,6 +1,7 @@ import pytest -from ahriman.core.auth import Mapping, OAuth +from ahriman.core.auth.mapping import Mapping +from ahriman.core.auth.oauth import OAuth from ahriman.core.configuration import Configuration from ahriman.core.database import SQLite diff --git a/tests/ahriman/core/auth/test_auth.py b/tests/ahriman/core/auth/test_auth.py index 7a740929..600d521d 100644 --- a/tests/ahriman/core/auth/test_auth.py +++ b/tests/ahriman/core/auth/test_auth.py @@ -1,4 +1,6 @@ -from ahriman.core.auth import Auth, Mapping, OAuth +from ahriman.core.auth import Auth +from ahriman.core.auth.mapping import Mapping +from ahriman.core.auth.oauth import OAuth from ahriman.core.configuration import Configuration from ahriman.core.database import SQLite from ahriman.models.user import User diff --git a/tests/ahriman/core/auth/test_mapping.py b/tests/ahriman/core/auth/test_mapping.py index f28c45cd..094f48aa 100644 --- a/tests/ahriman/core/auth/test_mapping.py +++ b/tests/ahriman/core/auth/test_mapping.py @@ -1,6 +1,6 @@ from pytest_mock import MockerFixture -from ahriman.core.auth import Mapping +from ahriman.core.auth.mapping import Mapping from ahriman.models.user import User from ahriman.models.user_access import UserAccess diff --git a/tests/ahriman/core/auth/test_oauth.py b/tests/ahriman/core/auth/test_oauth.py index 475e8b9c..a2dc330c 100644 --- a/tests/ahriman/core/auth/test_oauth.py +++ b/tests/ahriman/core/auth/test_oauth.py @@ -3,7 +3,7 @@ import pytest from pytest_mock import MockerFixture -from ahriman.core.auth import OAuth +from ahriman.core.auth.oauth import OAuth from ahriman.core.exceptions import OptionError diff --git a/tests/ahriman/web/conftest.py b/tests/ahriman/web/conftest.py index c1ee8172..0c6dd87e 100644 --- a/tests/ahriman/web/conftest.py +++ b/tests/ahriman/web/conftest.py @@ -9,7 +9,7 @@ from unittest.mock import MagicMock import ahriman.core.auth.helpers -from ahriman.core.auth import OAuth +from ahriman.core.auth.oauth import OAuth from ahriman.core.configuration import Configuration from ahriman.core.database import SQLite from ahriman.core.repository import Repository