Allow dependency errors to pass through (#13113)

Signed-off-by: Jacek Kusnierz <jacek.kusnierz@tum.de>
Co-authored-by: Brendan Abolivier <babolivier@matrix.org>
pull/13148/head
Jacek Kuśnierz 2022-06-30 19:48:04 +02:00 committed by GitHub
parent b0366853ca
commit 50f0e4028b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 16 additions and 58 deletions

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

@ -0,0 +1 @@
Raise a `DependencyError` on missing dependencies instead of a `ConfigError`.

View File

@ -21,7 +21,7 @@ from typing import Any, Callable, Dict, Optional
import attr import attr
from synapse.types import JsonDict from synapse.types import JsonDict
from synapse.util.check_dependencies import DependencyException, check_requirements from synapse.util.check_dependencies import check_requirements
from ._base import Config, ConfigError from ._base import Config, ConfigError
@ -159,12 +159,7 @@ class CacheConfig(Config):
self.track_memory_usage = cache_config.get("track_memory_usage", False) self.track_memory_usage = cache_config.get("track_memory_usage", False)
if self.track_memory_usage: if self.track_memory_usage:
try: check_requirements("cache_memory")
check_requirements("cache_memory")
except DependencyException as e:
raise ConfigError(
e.message # noqa: B306, DependencyException.message is a property
)
expire_caches = cache_config.get("expire_caches", True) expire_caches = cache_config.get("expire_caches", True)
cache_entry_ttl = cache_config.get("cache_entry_ttl", "30m") cache_entry_ttl = cache_config.get("cache_entry_ttl", "30m")

View File

@ -15,14 +15,9 @@
from typing import Any from typing import Any
from synapse.types import JsonDict from synapse.types import JsonDict
from synapse.util.check_dependencies import check_requirements
from ._base import Config, ConfigError from ._base import Config
MISSING_AUTHLIB = """Missing authlib library. This is required for jwt login.
Install by running:
pip install synapse[jwt]
"""
class JWTConfig(Config): class JWTConfig(Config):
@ -41,13 +36,7 @@ class JWTConfig(Config):
# that the claims exist on the JWT. # that the claims exist on the JWT.
self.jwt_issuer = jwt_config.get("issuer") self.jwt_issuer = jwt_config.get("issuer")
self.jwt_audiences = jwt_config.get("audiences") self.jwt_audiences = jwt_config.get("audiences")
check_requirements("jwt")
try:
from authlib.jose import JsonWebToken
JsonWebToken # To stop unused lint.
except ImportError:
raise ConfigError(MISSING_AUTHLIB)
else: else:
self.jwt_enabled = False self.jwt_enabled = False
self.jwt_secret = None self.jwt_secret = None

View File

@ -18,7 +18,7 @@ from typing import Any, Optional
import attr import attr
from synapse.types import JsonDict from synapse.types import JsonDict
from synapse.util.check_dependencies import DependencyException, check_requirements from synapse.util.check_dependencies import check_requirements
from ._base import Config, ConfigError from ._base import Config, ConfigError
@ -57,12 +57,7 @@ class MetricsConfig(Config):
self.sentry_enabled = "sentry" in config self.sentry_enabled = "sentry" in config
if self.sentry_enabled: if self.sentry_enabled:
try: check_requirements("sentry")
check_requirements("sentry")
except DependencyException as e:
raise ConfigError(
e.message # noqa: B306, DependencyException.message is a property
)
self.sentry_dsn = config["sentry"].get("dsn") self.sentry_dsn = config["sentry"].get("dsn")
if not self.sentry_dsn: if not self.sentry_dsn:

View File

@ -24,7 +24,7 @@ from synapse.types import JsonDict
from synapse.util.module_loader import load_module from synapse.util.module_loader import load_module
from synapse.util.stringutils import parse_and_validate_mxc_uri from synapse.util.stringutils import parse_and_validate_mxc_uri
from ..util.check_dependencies import DependencyException, check_requirements from ..util.check_dependencies import check_requirements
from ._base import Config, ConfigError, read_file from ._base import Config, ConfigError, read_file
DEFAULT_USER_MAPPING_PROVIDER = "synapse.handlers.oidc.JinjaOidcMappingProvider" DEFAULT_USER_MAPPING_PROVIDER = "synapse.handlers.oidc.JinjaOidcMappingProvider"
@ -41,12 +41,7 @@ class OIDCConfig(Config):
if not self.oidc_providers: if not self.oidc_providers:
return return
try: check_requirements("oidc")
check_requirements("oidc")
except DependencyException as e:
raise ConfigError(
e.message # noqa: B306, DependencyException.message is a property
) from e
# check we don't have any duplicate idp_ids now. (The SSO handler will also # check we don't have any duplicate idp_ids now. (The SSO handler will also
# check for duplicates when the REST listeners get registered, but that happens # check for duplicates when the REST listeners get registered, but that happens
@ -146,7 +141,6 @@ OIDC_PROVIDER_CONFIG_WITH_ID_SCHEMA = {
"allOf": [OIDC_PROVIDER_CONFIG_SCHEMA, {"required": ["idp_id", "idp_name"]}] "allOf": [OIDC_PROVIDER_CONFIG_SCHEMA, {"required": ["idp_id", "idp_name"]}]
} }
# the `oidc_providers` list can either be None (as it is in the default config), or # the `oidc_providers` list can either be None (as it is in the default config), or
# a list of provider configs, each of which requires an explicit ID and name. # a list of provider configs, each of which requires an explicit ID and name.
OIDC_PROVIDER_LIST_SCHEMA = { OIDC_PROVIDER_LIST_SCHEMA = {

View File

@ -21,7 +21,7 @@ import attr
from synapse.config.server import generate_ip_set from synapse.config.server import generate_ip_set
from synapse.types import JsonDict from synapse.types import JsonDict
from synapse.util.check_dependencies import DependencyException, check_requirements from synapse.util.check_dependencies import check_requirements
from synapse.util.module_loader import load_module from synapse.util.module_loader import load_module
from ._base import Config, ConfigError from ._base import Config, ConfigError
@ -184,13 +184,7 @@ class ContentRepositoryConfig(Config):
) )
self.url_preview_enabled = config.get("url_preview_enabled", False) self.url_preview_enabled = config.get("url_preview_enabled", False)
if self.url_preview_enabled: if self.url_preview_enabled:
try: check_requirements("url_preview")
check_requirements("url_preview")
except DependencyException as e:
raise ConfigError(
e.message # noqa: B306, DependencyException.message is a property
)
proxy_env = getproxies_environment() proxy_env = getproxies_environment()
if "url_preview_ip_range_blacklist" not in config: if "url_preview_ip_range_blacklist" not in config:

View File

@ -18,7 +18,7 @@ from typing import Any, List, Set
from synapse.config.sso import SsoAttributeRequirement from synapse.config.sso import SsoAttributeRequirement
from synapse.types import JsonDict from synapse.types import JsonDict
from synapse.util.check_dependencies import DependencyException, check_requirements from synapse.util.check_dependencies import check_requirements
from synapse.util.module_loader import load_module, load_python_module from synapse.util.module_loader import load_module, load_python_module
from ._base import Config, ConfigError from ._base import Config, ConfigError
@ -76,12 +76,7 @@ class SAML2Config(Config):
if not saml2_config.get("sp_config") and not saml2_config.get("config_path"): if not saml2_config.get("sp_config") and not saml2_config.get("config_path"):
return return
try: check_requirements("saml2")
check_requirements("saml2")
except DependencyException as e:
raise ConfigError(
e.message # noqa: B306, DependencyException.message is a property
)
self.saml2_enabled = True self.saml2_enabled = True

View File

@ -15,7 +15,7 @@
from typing import Any, List, Set from typing import Any, List, Set
from synapse.types import JsonDict from synapse.types import JsonDict
from synapse.util.check_dependencies import DependencyException, check_requirements from synapse.util.check_dependencies import check_requirements
from ._base import Config, ConfigError from ._base import Config, ConfigError
@ -40,12 +40,7 @@ class TracerConfig(Config):
if not self.opentracer_enabled: if not self.opentracer_enabled:
return return
try: check_requirements("opentracing")
check_requirements("opentracing")
except DependencyException as e:
raise ConfigError(
e.message # noqa: B306, DependencyException.message is a property
)
# The tracer is enabled so sanitize the config # The tracer is enabled so sanitize the config