Rename handler and config modules which end in handler/config. (#9816)

This commit is contained in:
Patrick Cloke 2021-04-20 14:55:20 -04:00 committed by GitHub
parent eccacd72cb
commit 683d6f75af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 43 additions and 35 deletions

1
changelog.d/9816.misc Normal file
View File

@ -0,0 +1 @@
Rename some handlers and config modules to not duplicate the top-level module.

View File

@ -1900,7 +1900,7 @@ saml2_config:
# sub-properties: # sub-properties:
# #
# module: The class name of a custom mapping module. Default is # module: The class name of a custom mapping module. Default is
# 'synapse.handlers.oidc_handler.JinjaOidcMappingProvider'. # 'synapse.handlers.oidc.JinjaOidcMappingProvider'.
# See https://github.com/matrix-org/synapse/blob/master/docs/sso_mapping_providers.md#openid-mapping-providers # See https://github.com/matrix-org/synapse/blob/master/docs/sso_mapping_providers.md#openid-mapping-providers
# for information on implementing a custom mapping provider. # for information on implementing a custom mapping provider.
# #

View File

@ -106,7 +106,7 @@ A custom mapping provider must specify the following methods:
Synapse has a built-in OpenID mapping provider if a custom provider isn't Synapse has a built-in OpenID mapping provider if a custom provider isn't
specified in the config. It is located at specified in the config. It is located at
[`synapse.handlers.oidc_handler.JinjaOidcMappingProvider`](../synapse/handlers/oidc_handler.py). [`synapse.handlers.oidc.JinjaOidcMappingProvider`](../synapse/handlers/oidc.py).
## SAML Mapping Providers ## SAML Mapping Providers
@ -190,4 +190,4 @@ A custom mapping provider must specify the following methods:
Synapse has a built-in SAML mapping provider if a custom provider isn't Synapse has a built-in SAML mapping provider if a custom provider isn't
specified in the config. It is located at specified in the config. It is located at
[`synapse.handlers.saml_handler.DefaultSamlMappingProvider`](../synapse/handlers/saml_handler.py). [`synapse.handlers.saml.DefaultSamlMappingProvider`](../synapse/handlers/saml.py).

View File

@ -7,16 +7,16 @@ from synapse.config import (
auth, auth,
captcha, captcha,
cas, cas,
consent_config, consent,
database, database,
emailconfig, emailconfig,
experimental, experimental,
groups, groups,
jwt_config, jwt,
key, key,
logger, logger,
metrics, metrics,
oidc_config, oidc,
password_auth_providers, password_auth_providers,
push, push,
ratelimiting, ratelimiting,
@ -24,9 +24,9 @@ from synapse.config import (
registration, registration,
repository, repository,
room_directory, room_directory,
saml2_config, saml2,
server, server,
server_notices_config, server_notices,
spam_checker, spam_checker,
sso, sso,
stats, stats,
@ -65,11 +65,11 @@ class RootConfig:
api: api.ApiConfig api: api.ApiConfig
appservice: appservice.AppServiceConfig appservice: appservice.AppServiceConfig
key: key.KeyConfig key: key.KeyConfig
saml2: saml2_config.SAML2Config saml2: saml2.SAML2Config
cas: cas.CasConfig cas: cas.CasConfig
sso: sso.SSOConfig sso: sso.SSOConfig
oidc: oidc_config.OIDCConfig oidc: oidc.OIDCConfig
jwt: jwt_config.JWTConfig jwt: jwt.JWTConfig
auth: auth.AuthConfig auth: auth.AuthConfig
email: emailconfig.EmailConfig email: emailconfig.EmailConfig
worker: workers.WorkerConfig worker: workers.WorkerConfig
@ -78,9 +78,9 @@ class RootConfig:
spamchecker: spam_checker.SpamCheckerConfig spamchecker: spam_checker.SpamCheckerConfig
groups: groups.GroupsConfig groups: groups.GroupsConfig
userdirectory: user_directory.UserDirectoryConfig userdirectory: user_directory.UserDirectoryConfig
consent: consent_config.ConsentConfig consent: consent.ConsentConfig
stats: stats.StatsConfig stats: stats.StatsConfig
servernotices: server_notices_config.ServerNoticesConfig servernotices: server_notices.ServerNoticesConfig
roomdirectory: room_directory.RoomDirectoryConfig roomdirectory: room_directory.RoomDirectoryConfig
thirdpartyrules: third_party_event_rules.ThirdPartyRulesConfig thirdpartyrules: third_party_event_rules.ThirdPartyRulesConfig
tracer: tracer.TracerConfig tracer: tracer.TracerConfig

View File

@ -20,17 +20,17 @@ from .auth import AuthConfig
from .cache import CacheConfig from .cache import CacheConfig
from .captcha import CaptchaConfig from .captcha import CaptchaConfig
from .cas import CasConfig from .cas import CasConfig
from .consent_config import ConsentConfig from .consent import ConsentConfig
from .database import DatabaseConfig from .database import DatabaseConfig
from .emailconfig import EmailConfig from .emailconfig import EmailConfig
from .experimental import ExperimentalConfig from .experimental import ExperimentalConfig
from .federation import FederationConfig from .federation import FederationConfig
from .groups import GroupsConfig from .groups import GroupsConfig
from .jwt_config import JWTConfig from .jwt import JWTConfig
from .key import KeyConfig from .key import KeyConfig
from .logger import LoggingConfig from .logger import LoggingConfig
from .metrics import MetricsConfig from .metrics import MetricsConfig
from .oidc_config import OIDCConfig from .oidc import OIDCConfig
from .password_auth_providers import PasswordAuthProviderConfig from .password_auth_providers import PasswordAuthProviderConfig
from .push import PushConfig from .push import PushConfig
from .ratelimiting import RatelimitConfig from .ratelimiting import RatelimitConfig
@ -39,9 +39,9 @@ from .registration import RegistrationConfig
from .repository import ContentRepositoryConfig from .repository import ContentRepositoryConfig
from .room import RoomConfig from .room import RoomConfig
from .room_directory import RoomDirectoryConfig from .room_directory import RoomDirectoryConfig
from .saml2_config import SAML2Config from .saml2 import SAML2Config
from .server import ServerConfig from .server import ServerConfig
from .server_notices_config import ServerNoticesConfig from .server_notices import ServerNoticesConfig
from .spam_checker import SpamCheckerConfig from .spam_checker import SpamCheckerConfig
from .sso import SSOConfig from .sso import SSOConfig
from .stats import StatsConfig from .stats import StatsConfig

View File

@ -27,7 +27,10 @@ from synapse.util.stringutils import parse_and_validate_mxc_uri
from ._base import Config, ConfigError, read_file from ._base import Config, ConfigError, read_file
DEFAULT_USER_MAPPING_PROVIDER = "synapse.handlers.oidc_handler.JinjaOidcMappingProvider" DEFAULT_USER_MAPPING_PROVIDER = "synapse.handlers.oidc.JinjaOidcMappingProvider"
# The module that JinjaOidcMappingProvider is in was renamed, we want to
# transparently handle both the same.
LEGACY_USER_MAPPING_PROVIDER = "synapse.handlers.oidc_handler.JinjaOidcMappingProvider"
class OIDCConfig(Config): class OIDCConfig(Config):
@ -403,6 +406,8 @@ def _parse_oidc_config_dict(
""" """
ump_config = oidc_config.get("user_mapping_provider", {}) ump_config = oidc_config.get("user_mapping_provider", {})
ump_config.setdefault("module", DEFAULT_USER_MAPPING_PROVIDER) ump_config.setdefault("module", DEFAULT_USER_MAPPING_PROVIDER)
if ump_config.get("module") == LEGACY_USER_MAPPING_PROVIDER:
ump_config["module"] = DEFAULT_USER_MAPPING_PROVIDER
ump_config.setdefault("config", {}) ump_config.setdefault("config", {})
( (

View File

@ -25,7 +25,10 @@ from ._util import validate_config
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
DEFAULT_USER_MAPPING_PROVIDER = ( DEFAULT_USER_MAPPING_PROVIDER = "synapse.handlers.saml.DefaultSamlMappingProvider"
# The module that DefaultSamlMappingProvider is in was renamed, we want to
# transparently handle both the same.
LEGACY_USER_MAPPING_PROVIDER = (
"synapse.handlers.saml_handler.DefaultSamlMappingProvider" "synapse.handlers.saml_handler.DefaultSamlMappingProvider"
) )
@ -97,6 +100,8 @@ class SAML2Config(Config):
# Use the default user mapping provider if not set # Use the default user mapping provider if not set
ump_dict.setdefault("module", DEFAULT_USER_MAPPING_PROVIDER) ump_dict.setdefault("module", DEFAULT_USER_MAPPING_PROVIDER)
if ump_dict.get("module") == LEGACY_USER_MAPPING_PROVIDER:
ump_dict["module"] = DEFAULT_USER_MAPPING_PROVIDER
# Ensure a config is present # Ensure a config is present
ump_dict["config"] = ump_dict.get("config") or {} ump_dict["config"] = ump_dict.get("config") or {}

View File

@ -37,10 +37,7 @@ from twisted.web.client import readBody
from twisted.web.http_headers import Headers from twisted.web.http_headers import Headers
from synapse.config import ConfigError from synapse.config import ConfigError
from synapse.config.oidc_config import ( from synapse.config.oidc import OidcProviderClientSecretJwtKey, OidcProviderConfig
OidcProviderClientSecretJwtKey,
OidcProviderConfig,
)
from synapse.handlers.sso import MappingException, UserAttributes from synapse.handlers.sso import MappingException, UserAttributes
from synapse.http.site import SynapseRequest from synapse.http.site import SynapseRequest
from synapse.logging.context import make_deferred_yieldable from synapse.logging.context import make_deferred_yieldable

View File

@ -30,7 +30,7 @@ from synapse.api.errors import (
) )
from synapse.config import ConfigError from synapse.config import ConfigError
from synapse.config.captcha import CaptchaConfig from synapse.config.captcha import CaptchaConfig
from synapse.config.consent_config import ConsentConfig from synapse.config.consent import ConsentConfig
from synapse.config.emailconfig import ThreepidBehaviour from synapse.config.emailconfig import ThreepidBehaviour
from synapse.config.ratelimiting import FederationRateLimitConfig from synapse.config.ratelimiting import FederationRateLimitConfig
from synapse.config.registration import RegistrationConfig from synapse.config.registration import RegistrationConfig

View File

@ -70,7 +70,7 @@ from synapse.handlers.acme import AcmeHandler
from synapse.handlers.admin import AdminHandler from synapse.handlers.admin import AdminHandler
from synapse.handlers.appservice import ApplicationServicesHandler from synapse.handlers.appservice import ApplicationServicesHandler
from synapse.handlers.auth import AuthHandler, MacaroonGenerator from synapse.handlers.auth import AuthHandler, MacaroonGenerator
from synapse.handlers.cas_handler import CasHandler from synapse.handlers.cas import CasHandler
from synapse.handlers.deactivate_account import DeactivateAccountHandler from synapse.handlers.deactivate_account import DeactivateAccountHandler
from synapse.handlers.device import DeviceHandler, DeviceWorkerHandler from synapse.handlers.device import DeviceHandler, DeviceWorkerHandler
from synapse.handlers.devicemessage import DeviceMessageHandler from synapse.handlers.devicemessage import DeviceMessageHandler
@ -145,8 +145,8 @@ logger = logging.getLogger(__name__)
if TYPE_CHECKING: if TYPE_CHECKING:
from txredisapi import RedisProtocol from txredisapi import RedisProtocol
from synapse.handlers.oidc_handler import OidcHandler from synapse.handlers.oidc import OidcHandler
from synapse.handlers.saml_handler import SamlHandler from synapse.handlers.saml import SamlHandler
T = TypeVar("T", bound=Callable[..., Any]) T = TypeVar("T", bound=Callable[..., Any])
@ -696,13 +696,13 @@ class HomeServer(metaclass=abc.ABCMeta):
@cache_in_self @cache_in_self
def get_saml_handler(self) -> "SamlHandler": def get_saml_handler(self) -> "SamlHandler":
from synapse.handlers.saml_handler import SamlHandler from synapse.handlers.saml import SamlHandler
return SamlHandler(self) return SamlHandler(self)
@cache_in_self @cache_in_self
def get_oidc_handler(self) -> "OidcHandler": def get_oidc_handler(self) -> "OidcHandler":
from synapse.handlers.oidc_handler import OidcHandler from synapse.handlers.oidc import OidcHandler
return OidcHandler(self) return OidcHandler(self)

View File

@ -13,7 +13,7 @@
# limitations under the License. # limitations under the License.
from unittest.mock import Mock from unittest.mock import Mock
from synapse.handlers.cas_handler import CasResponse from synapse.handlers.cas import CasResponse
from tests.test_utils import simple_async_mock from tests.test_utils import simple_async_mock
from tests.unittest import HomeserverTestCase, override_config from tests.unittest import HomeserverTestCase, override_config

View File

@ -499,7 +499,7 @@ class OidcHandlerTestCase(HomeserverTestCase):
self.assertRenderedError("fetch_error") self.assertRenderedError("fetch_error")
# Handle code exchange failure # Handle code exchange failure
from synapse.handlers.oidc_handler import OidcError from synapse.handlers.oidc import OidcError
self.provider._exchange_code = simple_async_mock( self.provider._exchange_code = simple_async_mock(
raises=OidcError("invalid_request") raises=OidcError("invalid_request")
@ -583,7 +583,7 @@ class OidcHandlerTestCase(HomeserverTestCase):
body=b'{"error": "foo", "error_description": "bar"}', body=b'{"error": "foo", "error_description": "bar"}',
) )
) )
from synapse.handlers.oidc_handler import OidcError from synapse.handlers.oidc import OidcError
exc = self.get_failure(self.provider._exchange_code(code), OidcError) exc = self.get_failure(self.provider._exchange_code(code), OidcError)
self.assertEqual(exc.value.error, "foo") self.assertEqual(exc.value.error, "foo")
@ -1126,7 +1126,7 @@ class OidcHandlerTestCase(HomeserverTestCase):
client_redirect_url: str, client_redirect_url: str,
ui_auth_session_id: str = "", ui_auth_session_id: str = "",
) -> str: ) -> str:
from synapse.handlers.oidc_handler import OidcSessionData from synapse.handlers.oidc import OidcSessionData
return self.handler._token_generator.generate_oidc_session_token( return self.handler._token_generator.generate_oidc_session_token(
state=state, state=state,
@ -1152,7 +1152,7 @@ async def _make_callback_with_userinfo(
userinfo: the OIDC userinfo dict userinfo: the OIDC userinfo dict
client_redirect_url: the URL to redirect to on success. client_redirect_url: the URL to redirect to on success.
""" """
from synapse.handlers.oidc_handler import OidcSessionData from synapse.handlers.oidc import OidcSessionData
handler = hs.get_oidc_handler() handler = hs.get_oidc_handler()
provider = handler._providers["oidc"] provider = handler._providers["oidc"]