diff options
author | Sean Quah <seanq@element.io> | 2021-12-07 16:38:29 +0000 |
---|---|---|
committer | Sean Quah <seanq@element.io> | 2021-12-07 16:47:31 +0000 |
commit | 158d73ebdd61eef33831ae5f6990acf07244fc55 (patch) | |
tree | 723f79596374042e349d55a6195cbe2b5eea29eb /synapse/config | |
parent | Sort internal changes in changelog (diff) | |
download | synapse-158d73ebdd61eef33831ae5f6990acf07244fc55.tar.xz |
Revert accidental fast-forward merge from v1.49.0rc1
Revert "Sort internal changes in changelog" Revert "Update CHANGES.md" Revert "1.49.0rc1" Revert "Revert "Move `glob_to_regex` and `re_word_boundary` to `matrix-python-common` (#11505) (#11527)" Revert "Refactors in `_generate_sync_entry_for_rooms` (#11515)" Revert "Correctly register shutdown handler for presence workers (#11518)" Revert "Fix `ModuleApi.looping_background_call` for non-async functions (#11524)" Revert "Fix 'delete room' admin api to work on incomplete rooms (#11523)" Revert "Correctly ignore invites from ignored users (#11511)" Revert "Fix the test breakage introduced by #11435 as a result of concurrent PRs (#11522)" Revert "Stabilise support for MSC2918 refresh tokens as they have now been merged into the Matrix specification. (#11435)" Revert "Save the OIDC session ID (sid) with the device on login (#11482)" Revert "Add admin API to get some information about federation status (#11407)" Revert "Include bundled aggregations in /sync and related fixes (#11478)" Revert "Move `glob_to_regex` and `re_word_boundary` to `matrix-python-common` (#11505)" Revert "Update backward extremity docs to make it clear that it does not indicate whether we have fetched an events' `prev_events` (#11469)" Revert "Support configuring the lifetime of non-refreshable access tokens separately to refreshable access tokens. (#11445)" Revert "Add type hints to `synapse/tests/rest/admin` (#11501)" Revert "Revert accidental commits to develop." Revert "Newsfile" Revert "Give `tests.server.setup_test_homeserver` (nominally!) the same behaviour" Revert "Move `tests.utils.setup_test_homeserver` to `tests.server`" Revert "Convert one of the `setup_test_homeserver`s to `make_test_homeserver_synchronous`" Revert "Disambiguate queries on `state_key` (#11497)" Revert "Comments on the /sync tentacles (#11494)" Revert "Clean up tests.storage.test_appservice (#11492)" Revert "Clean up `tests.storage.test_main` to remove use of legacy code. (#11493)" Revert "Clean up `tests.test_visibility` to remove legacy code. (#11495)" Revert "Minor cleanup on recently ported doc pages (#11466)" Revert "Add most of the missing type hints to `synapse.federation`. (#11483)" Revert "Avoid waiting for zombie processes in `synctl stop` (#11490)" Revert "Fix media repository failing when media store path contains symlinks (#11446)" Revert "Add type annotations to `tests.storage.test_appservice`. (#11488)" Revert "`scripts-dev/sign_json`: support for signing events (#11486)" Revert "Add MSC3030 experimental client and federation API endpoints to get the closest event to a given timestamp (#9445)" Revert "Port wiki pages to documentation website (#11402)" Revert "Add a license header and comment. (#11479)" Revert "Clean-up get_version_string (#11468)" Revert "Link background update controller docs to summary (#11475)" Revert "Additional type hints for config module. (#11465)" Revert "Register the login redirect endpoint for v3. (#11451)" Revert "Update openid.md" Revert "Remove mention of OIDC certification from Dex (#11470)" Revert "Add a note about huge pages to our Postgres doc (#11467)" Revert "Don't start Synapse master process if `worker_app` is set (#11416)" Revert "Expose worker & homeserver as entrypoints in `setup.py` (#11449)" Revert "Bundle relations of relations into the `/relations` result. (#11284)" Revert "Fix `LruCache` corruption bug with a `size_callback` that can return 0 (#11454)" Revert "Eliminate a few `Any`s in `LruCache` type hints (#11453)" Revert "Remove unnecessary `json.dumps` from `tests.rest.admin` (#11461)" Revert "Merge branch 'master' into develop" This reverts commit 26b5d2320f62b5eb6262c7614fbdfc364a4dfc02. This reverts commit bce4220f387bf5448387f0ed7d14ed1e41e40747. This reverts commit 966b5d0fa0893c3b628c942dfc232e285417f46d. This reverts commit 088d748f2cb51f03f3bcacc0fb3af1e0f9607737. This reverts commit 14d593f72d10b4d8cb67e3288bb3131ee30ccf59. This reverts commit 2a3ec6facf79f6aae011d9fb6f9ed5e43c7b6bec. This reverts commit eccc49d7554d1fab001e1fefb0fda8ffb254b630. This reverts commit b1ecd19c5d19815b69e425d80f442bf2877cab76. This reverts commit 9c55dedc8c4484e6269451a8c3c10b3e314aeb4a. This reverts commit 2d42e586a8c54be1a83643148358b1651c1ca666. This reverts commit 2f053f3f82ca174cc1c858c75afffae51af8ce0d. This reverts commit a15a893df8428395df7cb95b729431575001c38a. This reverts commit 8b4b153c9e86c04c7db8c74fde4b6a04becbc461. This reverts commit 494ebd7347ba52d702802fba4c3bb13e7bfbc2cf. This reverts commit a77c36989785c0d5565ab9a1169f4f88e512ce8a. This reverts commit 4eb77965cd016181d2111f37d93526e9bb0434f0. This reverts commit 637df95de63196033a6da4a6e286e1d58ea517b6. This reverts commit e5f426cd54609e7f05f8241d845e6e36c5f10d9a. This reverts commit 8cd68b8102eeab1b525712097c1b2e9679c11896. This reverts commit 6cae125e20865c52d770b24278bb7ab8fde5bc0d. This reverts commit 7be88fbf48156b36b6daefb228e1258e7d48cae4. This reverts commit b3fd99b74a3f6f42a9afd1b19ee4c60e38e8e91a. This reverts commit f7ec6e7d9e0dc360d9fb41f3a1afd7bdba1475c7. This reverts commit 5640992d176a499204a0756b1677c9b1575b0a49. This reverts commit d26808dd854006bd26a2366c675428ce0737238c. This reverts commit f91624a5950e14ba9007eed9bfa1c828676d4745. This reverts commit 16d39a5490ce74c901c7a8dbb990c6e83c379207. This reverts commit 8a4c2969874c0b7d72003f2523883eba8a348e83. This reverts commit 49e1356ee3d5d72929c91f778b3a231726c1413c. This reverts commit d2279f471ba8f44d9f578e62b286897a338d8aa1. This reverts commit b50e39df578adc3f86c5efa16bee9035cfdab61b. This reverts commit 858d80bf0f9f656a03992794874081b806e49222. This reverts commit 435f04480728c5d982e1a63c1b2777784bf9cd26. This reverts commit f61462e1be36a51dbf571076afa8e1930cb182f4. This reverts commit a6f1a3abecf8e8fd3e1bff439a06b853df18f194. This reverts commit 84dc50e160a2ec6590813374b5a1e58b97f7a18d. This reverts commit ed635d32853ee0a3e5ec1078679b27e7844a4ac7. This reverts commit 7b62791e001d6a4f8897ed48b3232d7f8fe6aa48. This reverts commit 153194c7717d8016b0eb974c81b1baee7dc1917d. This reverts commit f44d729d4ccae61bc0cdd5774acb3233eb5f7c13. This reverts commit a265fbd397ae72b2d3ea4c9310591ff1d0f3e05c. This reverts commit b9fef1a7cdfcc128fa589a32160e6aa7ed8964d7. This reverts commit b0eb64ff7bf6bde42046e091f8bdea9b7aab5f04. This reverts commit f1795463bf503a6fca909d77f598f641f9349f56. This reverts commit 70cbb1a5e311f609b624e3fae1a1712db639c51e. This reverts commit 42bf0204635213e2c75188b19ee66dc7e7d8a35e. This reverts commit 379f2650cf875f50c59524147ec0e33cfd5ef60c. This reverts commit 7ff22d6da41cd5ca80db95c18b409aea38e49fcd. This reverts commit 5a0b652d36ae4b6d423498c1f2c82c97a49c6f75. This reverts commit 432a174bc192740ac7a0a755009f6099b8363ad9. This reverts commit b14f8a1baf6f500997ae4c1d6a6d72094ce14270, reversing changes made to e713855dca17a7605bae99ea8d71bc7f8657e4b8.
Diffstat (limited to 'synapse/config')
-rw-r--r-- | synapse/config/__main__.py | 3 | ||||
-rw-r--r-- | synapse/config/appservice.py | 23 | ||||
-rw-r--r-- | synapse/config/cache.py | 26 | ||||
-rw-r--r-- | synapse/config/cas.py | 5 | ||||
-rw-r--r-- | synapse/config/database.py | 13 | ||||
-rw-r--r-- | synapse/config/experimental.py | 3 | ||||
-rw-r--r-- | synapse/config/logger.py | 24 | ||||
-rw-r--r-- | synapse/config/oidc.py | 58 | ||||
-rw-r--r-- | synapse/config/registration.py | 116 | ||||
-rw-r--r-- | synapse/config/repository.py | 9 | ||||
-rw-r--r-- | synapse/config/saml2.py | 21 | ||||
-rw-r--r-- | synapse/config/server.py | 20 | ||||
-rw-r--r-- | synapse/config/sso.py | 12 | ||||
-rw-r--r-- | synapse/config/workers.py | 4 |
14 files changed, 113 insertions, 224 deletions
diff --git a/synapse/config/__main__.py b/synapse/config/__main__.py index b2a7a89a35..c555f5f914 100644 --- a/synapse/config/__main__.py +++ b/synapse/config/__main__.py @@ -13,13 +13,12 @@ # See the License for the specific language governing permissions and # limitations under the License. import sys -from typing import List from synapse.config._base import ConfigError from synapse.config.homeserver import HomeServerConfig -def main(args: List[str]) -> None: +def main(args): action = args[1] if len(args) > 1 and args[1] == "read" else None # If we're reading a key in the config file, then `args[1]` will be `read` and `args[2]` # will be the key to read. diff --git a/synapse/config/appservice.py b/synapse/config/appservice.py index e4bb7224a4..1ebea88db2 100644 --- a/synapse/config/appservice.py +++ b/synapse/config/appservice.py @@ -1,5 +1,4 @@ # Copyright 2015, 2016 OpenMarket Ltd -# Copyright 2021 The Matrix.org Foundation C.I.C. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,14 +13,14 @@ # limitations under the License. import logging -from typing import Dict, List +from typing import Dict from urllib import parse as urlparse import yaml from netaddr import IPSet from synapse.appservice import ApplicationService -from synapse.types import JsonDict, UserID +from synapse.types import UserID from ._base import Config, ConfigError @@ -31,12 +30,12 @@ logger = logging.getLogger(__name__) class AppServiceConfig(Config): section = "appservice" - def read_config(self, config, **kwargs) -> None: + def read_config(self, config, **kwargs): self.app_service_config_files = config.get("app_service_config_files", []) self.notify_appservices = config.get("notify_appservices", True) self.track_appservice_user_ips = config.get("track_appservice_user_ips", False) - def generate_config_section(cls, **kwargs) -> str: + def generate_config_section(cls, **kwargs): return """\ # A list of application service config files to use # @@ -51,9 +50,7 @@ class AppServiceConfig(Config): """ -def load_appservices( - hostname: str, config_files: List[str] -) -> List[ApplicationService]: +def load_appservices(hostname, config_files): """Returns a list of Application Services from the config files.""" if not isinstance(config_files, list): logger.warning("Expected %s to be a list of AS config files.", config_files) @@ -96,9 +93,7 @@ def load_appservices( return appservices -def _load_appservice( - hostname: str, as_info: JsonDict, config_filename: str -) -> ApplicationService: +def _load_appservice(hostname, as_info, config_filename): required_string_fields = ["id", "as_token", "hs_token", "sender_localpart"] for field in required_string_fields: if not isinstance(as_info.get(field), str): @@ -120,9 +115,9 @@ def _load_appservice( user_id = user.to_string() # Rate limiting for users of this AS is on by default (excludes sender) - rate_limited = as_info.get("rate_limited") - if not isinstance(rate_limited, bool): - rate_limited = True + rate_limited = True + if isinstance(as_info.get("rate_limited"), bool): + rate_limited = as_info.get("rate_limited") # namespace checks if not isinstance(as_info.get("namespaces"), dict): diff --git a/synapse/config/cache.py b/synapse/config/cache.py index d9d85f98e1..f054455534 100644 --- a/synapse/config/cache.py +++ b/synapse/config/cache.py @@ -1,4 +1,4 @@ -# Copyright 2019-2021 Matrix.org Foundation C.I.C. +# Copyright 2019 Matrix.org Foundation C.I.C. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -17,8 +17,6 @@ import re import threading from typing import Callable, Dict, Optional -import attr - from synapse.python_dependencies import DependencyException, check_requirements from ._base import Config, ConfigError @@ -36,13 +34,13 @@ _DEFAULT_FACTOR_SIZE = 0.5 _DEFAULT_EVENT_CACHE_SIZE = "10K" -@attr.s(slots=True, auto_attribs=True) class CacheProperties: - # The default factor size for all caches - default_factor_size: float = float( - os.environ.get(_CACHE_PREFIX, _DEFAULT_FACTOR_SIZE) - ) - resize_all_caches_func: Optional[Callable[[], None]] = None + def __init__(self): + # The default factor size for all caches + self.default_factor_size = float( + os.environ.get(_CACHE_PREFIX, _DEFAULT_FACTOR_SIZE) + ) + self.resize_all_caches_func = None properties = CacheProperties() @@ -64,7 +62,7 @@ def _canonicalise_cache_name(cache_name: str) -> str: def add_resizable_cache( cache_name: str, cache_resize_callback: Callable[[float], None] -) -> None: +): """Register a cache that's size can dynamically change Args: @@ -93,7 +91,7 @@ class CacheConfig(Config): _environ = os.environ @staticmethod - def reset() -> None: + def reset(): """Resets the caches to their defaults. Used for tests.""" properties.default_factor_size = float( os.environ.get(_CACHE_PREFIX, _DEFAULT_FACTOR_SIZE) @@ -102,7 +100,7 @@ class CacheConfig(Config): with _CACHES_LOCK: _CACHES.clear() - def generate_config_section(self, **kwargs) -> str: + def generate_config_section(self, **kwargs): return """\ ## Caching ## @@ -164,7 +162,7 @@ class CacheConfig(Config): #sync_response_cache_duration: 2m """ - def read_config(self, config, **kwargs) -> None: + def read_config(self, config, **kwargs): self.event_cache_size = self.parse_size( config.get("event_cache_size", _DEFAULT_EVENT_CACHE_SIZE) ) @@ -234,7 +232,7 @@ class CacheConfig(Config): # needing an instance of Config properties.resize_all_caches_func = self.resize_all_caches - def resize_all_caches(self) -> None: + def resize_all_caches(self): """Ensure all cache sizes are up to date For each cache, run the mapped callback function with either diff --git a/synapse/config/cas.py b/synapse/config/cas.py index 6f2754092e..3f81814043 100644 --- a/synapse/config/cas.py +++ b/synapse/config/cas.py @@ -1,5 +1,4 @@ # Copyright 2015, 2016 OpenMarket Ltd -# Copyright 2021 The Matrix.org Foundation C.I.C. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -29,7 +28,7 @@ class CasConfig(Config): section = "cas" - def read_config(self, config, **kwargs) -> None: + def read_config(self, config, **kwargs): cas_config = config.get("cas_config", None) self.cas_enabled = cas_config and cas_config.get("enabled", True) @@ -52,7 +51,7 @@ class CasConfig(Config): self.cas_displayname_attribute = None self.cas_required_attributes = [] - def generate_config_section(self, config_dir_path, server_name, **kwargs) -> str: + def generate_config_section(self, config_dir_path, server_name, **kwargs): return """\ # Enable Central Authentication Service (CAS) for registration and login. # diff --git a/synapse/config/database.py b/synapse/config/database.py index 06ccf15cd9..651e31b576 100644 --- a/synapse/config/database.py +++ b/synapse/config/database.py @@ -1,5 +1,5 @@ # Copyright 2014-2016 OpenMarket Ltd -# Copyright 2020-2021 The Matrix.org Foundation C.I.C. +# Copyright 2020 The Matrix.org Foundation C.I.C. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -12,7 +12,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -import argparse import logging import os @@ -120,7 +119,7 @@ class DatabaseConfig(Config): self.databases = [] - def read_config(self, config, **kwargs) -> None: + def read_config(self, config, **kwargs): # We *experimentally* support specifying multiple databases via the # `databases` key. This is a map from a label to database config in the # same format as the `database` config option, plus an extra @@ -164,12 +163,12 @@ class DatabaseConfig(Config): self.databases = [DatabaseConnectionConfig("master", database_config)] self.set_databasepath(database_path) - def generate_config_section(self, data_dir_path, **kwargs) -> str: + def generate_config_section(self, data_dir_path, **kwargs): return DEFAULT_CONFIG % { "database_path": os.path.join(data_dir_path, "homeserver.db") } - def read_arguments(self, args: argparse.Namespace) -> None: + def read_arguments(self, args): """ Cases for the cli input: - If no databases are configured and no database_path is set, raise. @@ -195,7 +194,7 @@ class DatabaseConfig(Config): else: logger.warning(NON_SQLITE_DATABASE_PATH_WARNING) - def set_databasepath(self, database_path: str) -> None: + def set_databasepath(self, database_path): if database_path != ":memory:": database_path = self.abspath(database_path) @@ -203,7 +202,7 @@ class DatabaseConfig(Config): self.databases[0].config["args"]["database"] = database_path @staticmethod - def add_arguments(parser: argparse.ArgumentParser) -> None: + def add_arguments(parser): db_group = parser.add_argument_group("database") db_group.add_argument( "-d", diff --git a/synapse/config/experimental.py b/synapse/config/experimental.py index d78a15097c..8b098ad48d 100644 --- a/synapse/config/experimental.py +++ b/synapse/config/experimental.py @@ -46,6 +46,3 @@ class ExperimentalConfig(Config): # MSC3266 (room summary api) self.msc3266_enabled: bool = experimental.get("msc3266_enabled", False) - - # MSC3030 (Jump to date API endpoint) - self.msc3030_enabled: bool = experimental.get("msc3030_enabled", False) diff --git a/synapse/config/logger.py b/synapse/config/logger.py index ea69b9bd9b..63aab0babe 100644 --- a/synapse/config/logger.py +++ b/synapse/config/logger.py @@ -1,5 +1,4 @@ # Copyright 2014-2016 OpenMarket Ltd -# Copyright 2021 The Matrix.org Foundation C.I.C. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -19,7 +18,7 @@ import os import sys import threading from string import Template -from typing import TYPE_CHECKING, Any, Dict, Optional +from typing import TYPE_CHECKING, Any, Dict import yaml from zope.interface import implementer @@ -41,7 +40,6 @@ from synapse.util.versionstring import get_version_string from ._base import Config, ConfigError if TYPE_CHECKING: - from synapse.config.homeserver import HomeServerConfig from synapse.server import HomeServer DEFAULT_LOG_CONFIG = Template( @@ -143,13 +141,13 @@ removed in Synapse 1.3.0. You should instead set up a separate log configuration class LoggingConfig(Config): section = "logging" - def read_config(self, config, **kwargs) -> None: + def read_config(self, config, **kwargs): if config.get("log_file"): raise ConfigError(LOG_FILE_ERROR) self.log_config = self.abspath(config.get("log_config")) self.no_redirect_stdio = config.get("no_redirect_stdio", False) - def generate_config_section(self, config_dir_path, server_name, **kwargs) -> str: + def generate_config_section(self, config_dir_path, server_name, **kwargs): log_config = os.path.join(config_dir_path, server_name + ".log.config") return ( """\ @@ -163,14 +161,14 @@ class LoggingConfig(Config): % locals() ) - def read_arguments(self, args: argparse.Namespace) -> None: + def read_arguments(self, args): if args.no_redirect_stdio is not None: self.no_redirect_stdio = args.no_redirect_stdio if args.log_file is not None: raise ConfigError(LOG_FILE_ERROR) @staticmethod - def add_arguments(parser: argparse.ArgumentParser) -> None: + def add_arguments(parser): logging_group = parser.add_argument_group("logging") logging_group.add_argument( "-n", @@ -199,9 +197,7 @@ class LoggingConfig(Config): log_config_file.write(DEFAULT_LOG_CONFIG.substitute(log_file=log_file)) -def _setup_stdlib_logging( - config: "HomeServerConfig", log_config_path: Optional[str], logBeginner: LogBeginner -) -> None: +def _setup_stdlib_logging(config, log_config_path, logBeginner: LogBeginner) -> None: """ Set up Python standard library logging. """ @@ -234,7 +230,7 @@ def _setup_stdlib_logging( log_metadata_filter = MetadataFilter({"server_name": config.server.server_name}) old_factory = logging.getLogRecordFactory() - def factory(*args: Any, **kwargs: Any) -> logging.LogRecord: + def factory(*args, **kwargs): record = old_factory(*args, **kwargs) log_context_filter.filter(record) log_metadata_filter.filter(record) @@ -301,7 +297,7 @@ def _load_logging_config(log_config_path: str) -> None: logging.config.dictConfig(log_config) -def _reload_logging_config(log_config_path: Optional[str]) -> None: +def _reload_logging_config(log_config_path): """ Reload the log configuration from the file and apply it. """ @@ -315,8 +311,8 @@ def _reload_logging_config(log_config_path: Optional[str]) -> None: def setup_logging( hs: "HomeServer", - config: "HomeServerConfig", - use_worker_options: bool = False, + config, + use_worker_options=False, logBeginner: LogBeginner = globalLogBeginner, ) -> None: """ diff --git a/synapse/config/oidc.py b/synapse/config/oidc.py index 79c400fe30..42f113cd24 100644 --- a/synapse/config/oidc.py +++ b/synapse/config/oidc.py @@ -14,7 +14,7 @@ # limitations under the License. from collections import Counter -from typing import Any, Collection, Iterable, List, Mapping, Optional, Tuple, Type +from typing import Collection, Iterable, List, Mapping, Optional, Tuple, Type import attr @@ -36,7 +36,7 @@ LEGACY_USER_MAPPING_PROVIDER = "synapse.handlers.oidc_handler.JinjaOidcMappingPr class OIDCConfig(Config): section = "oidc" - def read_config(self, config, **kwargs) -> None: + def read_config(self, config, **kwargs): self.oidc_providers = tuple(_parse_oidc_provider_configs(config)) if not self.oidc_providers: return @@ -66,7 +66,7 @@ class OIDCConfig(Config): # OIDC is enabled if we have a provider return bool(self.oidc_providers) - def generate_config_section(self, config_dir_path, server_name, **kwargs) -> str: + def generate_config_section(self, config_dir_path, server_name, **kwargs): return """\ # List of OpenID Connect (OIDC) / OAuth 2.0 identity providers, for registration # and login. @@ -495,89 +495,89 @@ def _parse_oidc_config_dict( ) -@attr.s(slots=True, frozen=True, auto_attribs=True) +@attr.s(slots=True, frozen=True) class OidcProviderClientSecretJwtKey: # a pem-encoded signing key - key: str + key = attr.ib(type=str) # properties to include in the JWT header - jwt_header: Mapping[str, str] + jwt_header = attr.ib(type=Mapping[str, str]) # properties to include in the JWT payload. - jwt_payload: Mapping[str, str] + jwt_payload = attr.ib(type=Mapping[str, str]) -@attr.s(slots=True, frozen=True, auto_attribs=True) +@attr.s(slots=True, frozen=True) class OidcProviderConfig: # a unique identifier for this identity provider. Used in the 'user_external_ids' # table, as well as the query/path parameter used in the login protocol. - idp_id: str + idp_id = attr.ib(type=str) # user-facing name for this identity provider. - idp_name: str + idp_name = attr.ib(type=str) # Optional MXC URI for icon for this IdP. - idp_icon: Optional[str] + idp_icon = attr.ib(type=Optional[str]) # Optional brand identifier for this IdP. - idp_brand: Optional[str] + idp_brand = attr.ib(type=Optional[str]) # whether the OIDC discovery mechanism is used to discover endpoints - discover: bool + discover = attr.ib(type=bool) # the OIDC issuer. Used to validate tokens and (if discovery is enabled) to # discover the provider's endpoints. - issuer: str + issuer = attr.ib(type=str) # oauth2 client id to use - client_id: str + client_id = attr.ib(type=str) # oauth2 client secret to use. if `None`, use client_secret_jwt_key to generate # a secret. - client_secret: Optional[str] + client_secret = attr.ib(type=Optional[str]) # key to use to construct a JWT to use as a client secret. May be `None` if # `client_secret` is set. - client_secret_jwt_key: Optional[OidcProviderClientSecretJwtKey] + client_secret_jwt_key = attr.ib(type=Optional[OidcProviderClientSecretJwtKey]) # auth method to use when exchanging the token. # Valid values are 'client_secret_basic', 'client_secret_post' and # 'none'. - client_auth_method: str + client_auth_method = attr.ib(type=str) # list of scopes to request - scopes: Collection[str] + scopes = attr.ib(type=Collection[str]) # the oauth2 authorization endpoint. Required if discovery is disabled. - authorization_endpoint: Optional[str] + authorization_endpoint = attr.ib(type=Optional[str]) # the oauth2 token endpoint. Required if discovery is disabled. - token_endpoint: Optional[str] + token_endpoint = attr.ib(type=Optional[str]) # the OIDC userinfo endpoint. Required if discovery is disabled and the # "openid" scope is not requested. - userinfo_endpoint: Optional[str] + userinfo_endpoint = attr.ib(type=Optional[str]) # URI where to fetch the JWKS. Required if discovery is disabled and the # "openid" scope is used. - jwks_uri: Optional[str] + jwks_uri = attr.ib(type=Optional[str]) # Whether to skip metadata verification - skip_verification: bool + skip_verification = attr.ib(type=bool) # Whether to fetch the user profile from the userinfo endpoint. Valid # values are: "auto" or "userinfo_endpoint". - user_profile_method: str + user_profile_method = attr.ib(type=str) # whether to allow a user logging in via OIDC to match a pre-existing account # instead of failing - allow_existing_users: bool + allow_existing_users = attr.ib(type=bool) # the class of the user mapping provider - user_mapping_provider_class: Type + user_mapping_provider_class = attr.ib(type=Type) # the config of the user mapping provider - user_mapping_provider_config: Any + user_mapping_provider_config = attr.ib() # required attributes to require in userinfo to allow login/registration - attribute_requirements: List[SsoAttributeRequirement] + attribute_requirements = attr.ib(type=List[SsoAttributeRequirement]) diff --git a/synapse/config/registration.py b/synapse/config/registration.py index 7a059c6dec..61e569d412 100644 --- a/synapse/config/registration.py +++ b/synapse/config/registration.py @@ -1,5 +1,4 @@ # Copyright 2015, 2016 OpenMarket Ltd -# Copyright 2021 The Matrix.org Foundation C.I.C. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -12,8 +11,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -import argparse -from typing import Optional from synapse.api.constants import RoomCreationPreset from synapse.config._base import Config, ConfigError @@ -116,73 +113,32 @@ class RegistrationConfig(Config): self.session_lifetime = session_lifetime # The `refreshable_access_token_lifetime` applies for tokens that can be renewed - # using a refresh token, as per MSC2918. - # If it is `None`, the refresh token mechanism is disabled. + # using a refresh token, as per MSC2918. If it is `None`, the refresh + # token mechanism is disabled. + # + # Since it is incompatible with the `session_lifetime` mechanism, it is set to + # `None` by default if a `session_lifetime` is set. refreshable_access_token_lifetime = config.get( "refreshable_access_token_lifetime", - "5m", + "5m" if session_lifetime is None else None, ) if refreshable_access_token_lifetime is not None: refreshable_access_token_lifetime = self.parse_duration( refreshable_access_token_lifetime ) - self.refreshable_access_token_lifetime: Optional[ - int - ] = refreshable_access_token_lifetime + self.refreshable_access_token_lifetime = refreshable_access_token_lifetime if ( - self.session_lifetime is not None - and "refreshable_access_token_lifetime" in config + session_lifetime is not None + and refreshable_access_token_lifetime is not None ): - if self.session_lifetime < self.refreshable_access_token_lifetime: - raise ConfigError( - "Both `session_lifetime` and `refreshable_access_token_lifetime` " - "configuration options have been set, but `refreshable_access_token_lifetime` " - " exceeds `session_lifetime`!" - ) - - # The `nonrefreshable_access_token_lifetime` applies for tokens that can NOT be - # refreshed using a refresh token. - # If it is None, then these tokens last for the entire length of the session, - # which is infinite by default. - # The intention behind this configuration option is to help with requiring - # all clients to use refresh tokens, if the homeserver administrator requires. - nonrefreshable_access_token_lifetime = config.get( - "nonrefreshable_access_token_lifetime", - None, - ) - if nonrefreshable_access_token_lifetime is not None: - nonrefreshable_access_token_lifetime = self.parse_duration( - nonrefreshable_access_token_lifetime + raise ConfigError( + "The refresh token mechanism is incompatible with the " + "`session_lifetime` option. Consider disabling the " + "`session_lifetime` option or disabling the refresh token " + "mechanism by removing the `refreshable_access_token_lifetime` " + "option." ) - self.nonrefreshable_access_token_lifetime = nonrefreshable_access_token_lifetime - - if ( - self.session_lifetime is not None - and self.nonrefreshable_access_token_lifetime is not None - ): - if self.session_lifetime < self.nonrefreshable_access_token_lifetime: - raise ConfigError( - "Both `session_lifetime` and `nonrefreshable_access_token_lifetime` " - "configuration options have been set, but `nonrefreshable_access_token_lifetime` " - " exceeds `session_lifetime`!" - ) - - refresh_token_lifetime = config.get("refresh_token_lifetime") - if refresh_token_lifetime is not None: - refresh_token_lifetime = self.parse_duration(refresh_token_lifetime) - self.refresh_token_lifetime: Optional[int] = refresh_token_lifetime - - if ( - self.session_lifetime is not None - and self.refresh_token_lifetime is not None - ): - if self.session_lifetime < self.refresh_token_lifetime: - raise ConfigError( - "Both `session_lifetime` and `refresh_token_lifetime` " - "configuration options have been set, but `refresh_token_lifetime` " - " exceeds `session_lifetime`!" - ) # The fallback template used for authenticating using a registration token self.registration_token_template = self.read_template("registration_token.html") @@ -220,44 +176,6 @@ class RegistrationConfig(Config): # #session_lifetime: 24h - # Time that an access token remains valid for, if the session is - # using refresh tokens. - # For more information about refresh tokens, please see the manual. - # Note that this only applies to clients which advertise support for - # refresh tokens. - # - # Note also that this is calculated at login time and refresh time: - # changes are not applied to existing sessions until they are refreshed. - # - # By default, this is 5 minutes. - # - #refreshable_access_token_lifetime: 5m - - # Time that a refresh token remains valid for (provided that it is not - # exchanged for another one first). - # This option can be used to automatically log-out inactive sessions. - # Please see the manual for more information. - # - # Note also that this is calculated at login time and refresh time: - # changes are not applied to existing sessions until they are refreshed. - # - # By default, this is infinite. - # - #refresh_token_lifetime: 24h - - # Time that an access token remains valid for, if the session is NOT - # using refresh tokens. - # Please note that not all clients support refresh tokens, so setting - # this to a short value may be inconvenient for some users who will - # then be logged out frequently. - # - # Note also that this is calculated at login time: changes are not applied - # retrospectively to existing sessions for users that have already logged in. - # - # By default, this is infinite. - # - #nonrefreshable_access_token_lifetime: 24h - # The user must provide all of the below types of 3PID when registering. # #registrations_require_3pid: @@ -451,7 +369,7 @@ class RegistrationConfig(Config): ) @staticmethod - def add_arguments(parser: argparse.ArgumentParser) -> None: + def add_arguments(parser): reg_group = parser.add_argument_group("registration") reg_group.add_argument( "--enable-registration", @@ -460,6 +378,6 @@ class RegistrationConfig(Config): help="Enable registration for new users.", ) - def read_arguments(self, args: argparse.Namespace) -> None: + def read_arguments(self, args): if args.enable_registration is not None: self.enable_registration = strtobool(str(args.enable_registration)) diff --git a/synapse/config/repository.py b/synapse/config/repository.py index b129b9dd68..69906a98d4 100644 --- a/synapse/config/repository.py +++ b/synapse/config/repository.py @@ -15,12 +15,11 @@ import logging import os from collections import namedtuple -from typing import Dict, List, Tuple +from typing import Dict, List from urllib.request import getproxies_environment # type: ignore from synapse.config.server import DEFAULT_IP_RANGE_BLACKLIST, generate_ip_set from synapse.python_dependencies import DependencyException, check_requirements -from synapse.types import JsonDict from synapse.util.module_loader import load_module from ._base import Config, ConfigError @@ -58,9 +57,7 @@ MediaStorageProviderConfig = namedtuple( ) -def parse_thumbnail_requirements( - thumbnail_sizes: List[JsonDict], -) -> Dict[str, Tuple[ThumbnailRequirement, ...]]: +def parse_thumbnail_requirements(thumbnail_sizes): """Takes a list of dictionaries with "width", "height", and "method" keys and creates a map from image media types to the thumbnail size, thumbnailing method, and thumbnail media type to precalculate @@ -72,7 +69,7 @@ def parse_thumbnail_requirements( Dictionary mapping from media type string to list of ThumbnailRequirement tuples. """ - requirements: Dict[str, List[ThumbnailRequirement]] = {} + requirements: Dict[str, List] = {} for size in thumbnail_sizes: width = size["width"] height = size["height"] diff --git a/synapse/config/saml2.py b/synapse/config/saml2.py index ec9d9f65e7..ba2b0905ff 100644 --- a/synapse/config/saml2.py +++ b/synapse/config/saml2.py @@ -1,5 +1,5 @@ # Copyright 2018 New Vector Ltd -# Copyright 2019-2021 The Matrix.org Foundation C.I.C. +# Copyright 2019 The Matrix.org Foundation C.I.C. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,11 +14,10 @@ # limitations under the License. import logging -from typing import Any, List, Set +from typing import Any, List from synapse.config.sso import SsoAttributeRequirement from synapse.python_dependencies import DependencyException, check_requirements -from synapse.types import JsonDict from synapse.util.module_loader import load_module, load_python_module from ._base import Config, ConfigError @@ -34,7 +33,7 @@ LEGACY_USER_MAPPING_PROVIDER = ( ) -def _dict_merge(merge_dict: dict, into_dict: dict) -> None: +def _dict_merge(merge_dict, into_dict): """Do a deep merge of two dicts Recursively merges `merge_dict` into `into_dict`: @@ -44,8 +43,8 @@ def _dict_merge(merge_dict: dict, into_dict: dict) -> None: the value from `merge_dict`. Args: - merge_dict: dict to merge - into_dict: target dict to be modified + merge_dict (dict): dict to merge + into_dict (dict): target dict """ for k, v in merge_dict.items(): if k not in into_dict: @@ -65,7 +64,7 @@ def _dict_merge(merge_dict: dict, into_dict: dict) -> None: class SAML2Config(Config): section = "saml2" - def read_config(self, config, **kwargs) -> None: + def read_config(self, config, **kwargs): self.saml2_enabled = False saml2_config = config.get("saml2_config") @@ -184,8 +183,8 @@ class SAML2Config(Config): ) def _default_saml_config_dict( - self, required_attributes: Set[str], optional_attributes: Set[str] - ) -> JsonDict: + self, required_attributes: set, optional_attributes: set + ): """Generate a configuration dictionary with required and optional attributes that will be needed to process new user registration @@ -196,7 +195,7 @@ class SAML2Config(Config): additional information to Synapse user accounts, but are not required Returns: - A SAML configuration dictionary + dict: A SAML configuration dictionary """ import saml2 @@ -223,7 +222,7 @@ class SAML2Config(Config): }, } - def generate_config_section(self, config_dir_path, server_name, **kwargs) -> str: + def generate_config_section(self, config_dir_path, server_name, **kwargs): return """\ ## Single sign-on integration ## diff --git a/synapse/config/server.py b/synapse/config/server.py index ba5b954263..8445e9dd05 100644 --- a/synapse/config/server.py +++ b/synapse/config/server.py @@ -12,7 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -import argparse import itertools import logging import os.path @@ -28,7 +27,6 @@ from netaddr import AddrFormatError, IPNetwork, IPSet from twisted.conch.ssh.keys import Key from synapse.api.room_versions import KNOWN_ROOM_VERSIONS -from synapse.types import JsonDict from synapse.util.module_loader import load_module from synapse.util.stringutils import parse_and_validate_server_name @@ -1225,7 +1223,7 @@ class ServerConfig(Config): % locals() ) - def read_arguments(self, args: argparse.Namespace) -> None: + def read_arguments(self, args): if args.manhole is not None: self.manhole = args.manhole if args.daemonize is not None: @@ -1234,7 +1232,7 @@ class ServerConfig(Config): self.print_pidfile = args.print_pidfile @staticmethod - def add_arguments(parser: argparse.ArgumentParser) -> None: + def add_arguments(parser): server_group = parser.add_argument_group("server") server_group.add_argument( "-D", @@ -1276,16 +1274,14 @@ class ServerConfig(Config): ) -def is_threepid_reserved( - reserved_threepids: List[JsonDict], threepid: JsonDict -) -> bool: +def is_threepid_reserved(reserved_threepids, threepid): """Check the threepid against the reserved threepid config Args: - reserved_threepids: List of reserved threepids - threepid: The threepid to test for + reserved_threepids([dict]) - list of reserved threepids + threepid(dict) - The threepid to test for Returns: - Is the threepid undertest reserved_user + boolean Is the threepid undertest reserved_user """ for tp in reserved_threepids: @@ -1294,9 +1290,7 @@ def is_threepid_reserved( return False -def read_gc_thresholds( - thresholds: Optional[List[Any]], -) -> Optional[Tuple[int, int, int]]: +def read_gc_thresholds(thresholds): """Reads the three integer thresholds for garbage collection. Ensures that the thresholds are integers if thresholds are supplied. """ diff --git a/synapse/config/sso.py b/synapse/config/sso.py index e4a4243261..60aacb13ea 100644 --- a/synapse/config/sso.py +++ b/synapse/config/sso.py @@ -1,4 +1,4 @@ -# Copyright 2020-2021 The Matrix.org Foundation C.I.C. +# Copyright 2020 The Matrix.org Foundation C.I.C. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -29,13 +29,13 @@ https://matrix-org.github.io/synapse/latest/templates.html ---------------------------------------------------------------------------------------""" -@attr.s(frozen=True, auto_attribs=True) +@attr.s(frozen=True) class SsoAttributeRequirement: """Object describing a single requirement for SSO attributes.""" - attribute: str + attribute = attr.ib(type=str) # If a value is not given, than the attribute must simply exist. - value: Optional[str] + value = attr.ib(type=Optional[str]) JSON_SCHEMA = { "type": "object", @@ -49,7 +49,7 @@ class SSOConfig(Config): section = "sso" - def read_config(self, config, **kwargs) -> None: + def read_config(self, config, **kwargs): sso_config: Dict[str, Any] = config.get("sso") or {} # The sso-specific template_dir @@ -106,7 +106,7 @@ class SSOConfig(Config): ) self.sso_client_whitelist.append(login_fallback_url) - def generate_config_section(self, **kwargs) -> str: + def generate_config_section(self, **kwargs): return """\ # Additional settings to use with single-sign on systems such as OpenID Connect, # SAML2 and CAS. diff --git a/synapse/config/workers.py b/synapse/config/workers.py index 576f519188..4507992031 100644 --- a/synapse/config/workers.py +++ b/synapse/config/workers.py @@ -1,5 +1,4 @@ # Copyright 2016 OpenMarket Ltd -# Copyright 2021 The Matrix.org Foundation C.I.C. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -13,7 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -import argparse from typing import List, Union import attr @@ -345,7 +343,7 @@ class WorkerConfig(Config): #worker_replication_secret: "" """ - def read_arguments(self, args: argparse.Namespace) -> None: + def read_arguments(self, args): # We support a bunch of command line arguments that override options in # the config. A lot of these options have a worker_* prefix when running # on workers so we also have to override them when command line options |