mirror of
https://git.anonymousland.org/anonymousland/synapse-product.git
synced 2024-10-01 08:25:44 -04:00
Use direct references for configuration variables (part 4). (#10893)
This commit is contained in:
parent
a10988983a
commit
47854c71e9
1
changelog.d/10893.misc
Normal file
1
changelog.d/10893.misc
Normal file
@ -0,0 +1 @@
|
|||||||
|
Use direct references to config flags.
|
@ -39,12 +39,12 @@ class ConsentURIBuilder:
|
|||||||
Args:
|
Args:
|
||||||
hs_config (synapse.config.homeserver.HomeServerConfig):
|
hs_config (synapse.config.homeserver.HomeServerConfig):
|
||||||
"""
|
"""
|
||||||
if hs_config.form_secret is None:
|
if hs_config.key.form_secret is None:
|
||||||
raise ConfigError("form_secret not set in config")
|
raise ConfigError("form_secret not set in config")
|
||||||
if hs_config.server.public_baseurl is None:
|
if hs_config.server.public_baseurl is None:
|
||||||
raise ConfigError("public_baseurl not set in config")
|
raise ConfigError("public_baseurl not set in config")
|
||||||
|
|
||||||
self._hmac_secret = hs_config.form_secret.encode("utf-8")
|
self._hmac_secret = hs_config.key.form_secret.encode("utf-8")
|
||||||
self._public_baseurl = hs_config.server.public_baseurl
|
self._public_baseurl = hs_config.server.public_baseurl
|
||||||
|
|
||||||
def build_user_consent_uri(self, user_id):
|
def build_user_consent_uri(self, user_id):
|
||||||
|
@ -424,12 +424,14 @@ def setup_sentry(hs):
|
|||||||
hs (synapse.server.HomeServer)
|
hs (synapse.server.HomeServer)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if not hs.config.sentry_enabled:
|
if not hs.config.metrics.sentry_enabled:
|
||||||
return
|
return
|
||||||
|
|
||||||
import sentry_sdk
|
import sentry_sdk
|
||||||
|
|
||||||
sentry_sdk.init(dsn=hs.config.sentry_dsn, release=get_version_string(synapse))
|
sentry_sdk.init(
|
||||||
|
dsn=hs.config.metrics.sentry_dsn, release=get_version_string(synapse)
|
||||||
|
)
|
||||||
|
|
||||||
# We set some default tags that give some context to this instance
|
# We set some default tags that give some context to this instance
|
||||||
with sentry_sdk.configure_scope() as scope:
|
with sentry_sdk.configure_scope() as scope:
|
||||||
|
@ -192,7 +192,7 @@ def start(config_options):
|
|||||||
):
|
):
|
||||||
# Since we're meant to be run as a "command" let's not redirect stdio
|
# Since we're meant to be run as a "command" let's not redirect stdio
|
||||||
# unless we've actually set log config.
|
# unless we've actually set log config.
|
||||||
config.no_redirect_stdio = True
|
config.logging.no_redirect_stdio = True
|
||||||
|
|
||||||
# Explicitly disable background processes
|
# Explicitly disable background processes
|
||||||
config.update_user_directory = False
|
config.update_user_directory = False
|
||||||
|
@ -395,7 +395,7 @@ class GenericWorkerServer(HomeServer):
|
|||||||
manhole_globals={"hs": self},
|
manhole_globals={"hs": self},
|
||||||
)
|
)
|
||||||
elif listener.type == "metrics":
|
elif listener.type == "metrics":
|
||||||
if not self.config.enable_metrics:
|
if not self.config.metrics.enable_metrics:
|
||||||
logger.warning(
|
logger.warning(
|
||||||
"Metrics listener configured, but "
|
"Metrics listener configured, but "
|
||||||
"enable_metrics is not True!"
|
"enable_metrics is not True!"
|
||||||
@ -488,7 +488,7 @@ def start(config_options):
|
|||||||
register_start(_base.start, hs)
|
register_start(_base.start, hs)
|
||||||
|
|
||||||
# redirect stdio to the logs, if configured.
|
# redirect stdio to the logs, if configured.
|
||||||
if not hs.config.no_redirect_stdio:
|
if not hs.config.logging.no_redirect_stdio:
|
||||||
redirect_stdio_to_logs()
|
redirect_stdio_to_logs()
|
||||||
|
|
||||||
_base.start_worker_reactor("synapse-generic-worker", config)
|
_base.start_worker_reactor("synapse-generic-worker", config)
|
||||||
|
@ -269,7 +269,7 @@ class SynapseHomeServer(HomeServer):
|
|||||||
# https://twistedmatrix.com/trac/ticket/7678
|
# https://twistedmatrix.com/trac/ticket/7678
|
||||||
resources[WEB_CLIENT_PREFIX] = File(webclient_loc)
|
resources[WEB_CLIENT_PREFIX] = File(webclient_loc)
|
||||||
|
|
||||||
if name == "metrics" and self.config.enable_metrics:
|
if name == "metrics" and self.config.metrics.enable_metrics:
|
||||||
resources[METRICS_PREFIX] = MetricsResource(RegistryProxy)
|
resources[METRICS_PREFIX] = MetricsResource(RegistryProxy)
|
||||||
|
|
||||||
if name == "replication":
|
if name == "replication":
|
||||||
@ -278,7 +278,7 @@ class SynapseHomeServer(HomeServer):
|
|||||||
return resources
|
return resources
|
||||||
|
|
||||||
def start_listening(self):
|
def start_listening(self):
|
||||||
if self.config.redis_enabled:
|
if self.config.redis.redis_enabled:
|
||||||
# If redis is enabled we connect via the replication command handler
|
# If redis is enabled we connect via the replication command handler
|
||||||
# in the same way as the workers (since we're effectively a client
|
# in the same way as the workers (since we're effectively a client
|
||||||
# rather than a server).
|
# rather than a server).
|
||||||
@ -305,7 +305,7 @@ class SynapseHomeServer(HomeServer):
|
|||||||
for s in services:
|
for s in services:
|
||||||
reactor.addSystemEventTrigger("before", "shutdown", s.stopListening)
|
reactor.addSystemEventTrigger("before", "shutdown", s.stopListening)
|
||||||
elif listener.type == "metrics":
|
elif listener.type == "metrics":
|
||||||
if not self.config.enable_metrics:
|
if not self.config.metrics.enable_metrics:
|
||||||
logger.warning(
|
logger.warning(
|
||||||
"Metrics listener configured, but "
|
"Metrics listener configured, but "
|
||||||
"enable_metrics is not True!"
|
"enable_metrics is not True!"
|
||||||
@ -366,7 +366,7 @@ def setup(config_options):
|
|||||||
|
|
||||||
async def start():
|
async def start():
|
||||||
# Load the OIDC provider metadatas, if OIDC is enabled.
|
# Load the OIDC provider metadatas, if OIDC is enabled.
|
||||||
if hs.config.oidc_enabled:
|
if hs.config.oidc.oidc_enabled:
|
||||||
oidc = hs.get_oidc_handler()
|
oidc = hs.get_oidc_handler()
|
||||||
# Loading the provider metadata also ensures the provider config is valid.
|
# Loading the provider metadata also ensures the provider config is valid.
|
||||||
await oidc.load_metadata()
|
await oidc.load_metadata()
|
||||||
@ -455,7 +455,7 @@ def main():
|
|||||||
hs = setup(sys.argv[1:])
|
hs = setup(sys.argv[1:])
|
||||||
|
|
||||||
# redirect stdio to the logs, if configured.
|
# redirect stdio to the logs, if configured.
|
||||||
if not hs.config.no_redirect_stdio:
|
if not hs.config.logging.no_redirect_stdio:
|
||||||
redirect_stdio_to_logs()
|
redirect_stdio_to_logs()
|
||||||
|
|
||||||
run(hs)
|
run(hs)
|
||||||
|
@ -131,10 +131,12 @@ async def phone_stats_home(hs, stats, stats_process=_stats_process):
|
|||||||
log_level = synapse_logger.getEffectiveLevel()
|
log_level = synapse_logger.getEffectiveLevel()
|
||||||
stats["log_level"] = logging.getLevelName(log_level)
|
stats["log_level"] = logging.getLevelName(log_level)
|
||||||
|
|
||||||
logger.info("Reporting stats to %s: %s" % (hs.config.report_stats_endpoint, stats))
|
logger.info(
|
||||||
|
"Reporting stats to %s: %s" % (hs.config.metrics.report_stats_endpoint, stats)
|
||||||
|
)
|
||||||
try:
|
try:
|
||||||
await hs.get_proxied_http_client().put_json(
|
await hs.get_proxied_http_client().put_json(
|
||||||
hs.config.report_stats_endpoint, stats
|
hs.config.metrics.report_stats_endpoint, stats
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning("Error reporting stats: %s", e)
|
logger.warning("Error reporting stats: %s", e)
|
||||||
@ -188,7 +190,7 @@ def start_phone_stats_home(hs):
|
|||||||
clock.looping_call(generate_monthly_active_users, 5 * 60 * 1000)
|
clock.looping_call(generate_monthly_active_users, 5 * 60 * 1000)
|
||||||
# End of monthly active user settings
|
# End of monthly active user settings
|
||||||
|
|
||||||
if hs.config.report_stats:
|
if hs.config.metrics.report_stats:
|
||||||
logger.info("Scheduling stats reporting for 3 hour intervals")
|
logger.info("Scheduling stats reporting for 3 hour intervals")
|
||||||
clock.looping_call(phone_stats_home, 3 * 60 * 60 * 1000, hs, stats)
|
clock.looping_call(phone_stats_home, 3 * 60 * 60 * 1000, hs, stats)
|
||||||
|
|
||||||
|
@ -322,7 +322,7 @@ def setup_logging(
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
log_config_path = (
|
log_config_path = (
|
||||||
config.worker_log_config if use_worker_options else config.log_config
|
config.worker_log_config if use_worker_options else config.logging.log_config
|
||||||
)
|
)
|
||||||
|
|
||||||
# Perform one-time logging configuration.
|
# Perform one-time logging configuration.
|
||||||
|
@ -49,7 +49,9 @@ class Authenticator:
|
|||||||
self.keyring = hs.get_keyring()
|
self.keyring = hs.get_keyring()
|
||||||
self.server_name = hs.hostname
|
self.server_name = hs.hostname
|
||||||
self.store = hs.get_datastore()
|
self.store = hs.get_datastore()
|
||||||
self.federation_domain_whitelist = hs.config.federation_domain_whitelist
|
self.federation_domain_whitelist = (
|
||||||
|
hs.config.federation.federation_domain_whitelist
|
||||||
|
)
|
||||||
self.notifier = hs.get_notifier()
|
self.notifier = hs.get_notifier()
|
||||||
|
|
||||||
self.replication_client = None
|
self.replication_client = None
|
||||||
|
@ -847,16 +847,16 @@ class GroupsServerHandler(GroupsServerWorkerHandler):
|
|||||||
UserID.from_string(requester_user_id)
|
UserID.from_string(requester_user_id)
|
||||||
)
|
)
|
||||||
if not is_admin:
|
if not is_admin:
|
||||||
if not self.hs.config.enable_group_creation:
|
if not self.hs.config.groups.enable_group_creation:
|
||||||
raise SynapseError(
|
raise SynapseError(
|
||||||
403, "Only a server admin can create groups on this server"
|
403, "Only a server admin can create groups on this server"
|
||||||
)
|
)
|
||||||
localpart = group_id_obj.localpart
|
localpart = group_id_obj.localpart
|
||||||
if not localpart.startswith(self.hs.config.group_creation_prefix):
|
if not localpart.startswith(self.hs.config.groups.group_creation_prefix):
|
||||||
raise SynapseError(
|
raise SynapseError(
|
||||||
400,
|
400,
|
||||||
"Can only create groups with prefix %r on this server"
|
"Can only create groups with prefix %r on this server"
|
||||||
% (self.hs.config.group_creation_prefix,),
|
% (self.hs.config.groups.group_creation_prefix,),
|
||||||
)
|
)
|
||||||
|
|
||||||
profile = content.get("profile", {})
|
profile = content.get("profile", {})
|
||||||
|
@ -1802,7 +1802,7 @@ class MacaroonGenerator:
|
|||||||
macaroon = pymacaroons.Macaroon(
|
macaroon = pymacaroons.Macaroon(
|
||||||
location=self.hs.config.server.server_name,
|
location=self.hs.config.server.server_name,
|
||||||
identifier="key",
|
identifier="key",
|
||||||
key=self.hs.config.macaroon_secret_key,
|
key=self.hs.config.key.macaroon_secret_key,
|
||||||
)
|
)
|
||||||
macaroon.add_first_party_caveat("gen = 1")
|
macaroon.add_first_party_caveat("gen = 1")
|
||||||
macaroon.add_first_party_caveat("user_id = %s" % (user_id,))
|
macaroon.add_first_party_caveat("user_id = %s" % (user_id,))
|
||||||
|
@ -277,7 +277,7 @@ class OidcProvider:
|
|||||||
self._token_generator = token_generator
|
self._token_generator = token_generator
|
||||||
|
|
||||||
self._config = provider
|
self._config = provider
|
||||||
self._callback_url: str = hs.config.oidc_callback_url
|
self._callback_url: str = hs.config.oidc.oidc_callback_url
|
||||||
|
|
||||||
# Calculate the prefix for OIDC callback paths based on the public_baseurl.
|
# Calculate the prefix for OIDC callback paths based on the public_baseurl.
|
||||||
# We'll insert this into the Path= parameter of any session cookies we set.
|
# We'll insert this into the Path= parameter of any session cookies we set.
|
||||||
|
@ -309,7 +309,7 @@ class ProfileHandler(BaseHandler):
|
|||||||
async def on_profile_query(self, args: JsonDict) -> JsonDict:
|
async def on_profile_query(self, args: JsonDict) -> JsonDict:
|
||||||
"""Handles federation profile query requests."""
|
"""Handles federation profile query requests."""
|
||||||
|
|
||||||
if not self.hs.config.allow_profile_lookup_over_federation:
|
if not self.hs.config.federation.allow_profile_lookup_over_federation:
|
||||||
raise SynapseError(
|
raise SynapseError(
|
||||||
403,
|
403,
|
||||||
"Profile lookup over federation is disabled on this homeserver",
|
"Profile lookup over federation is disabled on this homeserver",
|
||||||
|
@ -465,8 +465,9 @@ class MatrixFederationHttpClient:
|
|||||||
_sec_timeout = self.default_timeout
|
_sec_timeout = self.default_timeout
|
||||||
|
|
||||||
if (
|
if (
|
||||||
self.hs.config.federation_domain_whitelist is not None
|
self.hs.config.federation.federation_domain_whitelist is not None
|
||||||
and request.destination not in self.hs.config.federation_domain_whitelist
|
and request.destination
|
||||||
|
not in self.hs.config.federation.federation_domain_whitelist
|
||||||
):
|
):
|
||||||
raise FederationDeniedError(request.destination)
|
raise FederationDeniedError(request.destination)
|
||||||
|
|
||||||
|
@ -73,7 +73,9 @@ class HttpPusher(Pusher):
|
|||||||
self.failing_since = pusher_config.failing_since
|
self.failing_since = pusher_config.failing_since
|
||||||
self.timed_call: Optional[IDelayedCall] = None
|
self.timed_call: Optional[IDelayedCall] = None
|
||||||
self._is_processing = False
|
self._is_processing = False
|
||||||
self._group_unread_count_by_room = hs.config.push_group_unread_count_by_room
|
self._group_unread_count_by_room = (
|
||||||
|
hs.config.push.push_group_unread_count_by_room
|
||||||
|
)
|
||||||
self._pusherpool = hs.get_pusherpool()
|
self._pusherpool = hs.get_pusherpool()
|
||||||
|
|
||||||
self.data = pusher_config.data
|
self.data = pusher_config.data
|
||||||
|
@ -69,16 +69,16 @@ class LoginRestServlet(RestServlet):
|
|||||||
self.hs = hs
|
self.hs = hs
|
||||||
|
|
||||||
# JWT configuration variables.
|
# JWT configuration variables.
|
||||||
self.jwt_enabled = hs.config.jwt_enabled
|
self.jwt_enabled = hs.config.jwt.jwt_enabled
|
||||||
self.jwt_secret = hs.config.jwt_secret
|
self.jwt_secret = hs.config.jwt.jwt_secret
|
||||||
self.jwt_algorithm = hs.config.jwt_algorithm
|
self.jwt_algorithm = hs.config.jwt.jwt_algorithm
|
||||||
self.jwt_issuer = hs.config.jwt_issuer
|
self.jwt_issuer = hs.config.jwt.jwt_issuer
|
||||||
self.jwt_audiences = hs.config.jwt_audiences
|
self.jwt_audiences = hs.config.jwt.jwt_audiences
|
||||||
|
|
||||||
# SSO configuration.
|
# SSO configuration.
|
||||||
self.saml2_enabled = hs.config.saml2_enabled
|
self.saml2_enabled = hs.config.saml2_enabled
|
||||||
self.cas_enabled = hs.config.cas.cas_enabled
|
self.cas_enabled = hs.config.cas.cas_enabled
|
||||||
self.oidc_enabled = hs.config.oidc_enabled
|
self.oidc_enabled = hs.config.oidc.oidc_enabled
|
||||||
self._msc2918_enabled = hs.config.access_token_lifetime is not None
|
self._msc2918_enabled = hs.config.access_token_lifetime is not None
|
||||||
|
|
||||||
self.auth = hs.get_auth()
|
self.auth = hs.get_auth()
|
||||||
|
@ -100,13 +100,13 @@ class ConsentResource(DirectServeHtmlResource):
|
|||||||
loader=loader, autoescape=jinja2.select_autoescape(["html", "htm", "xml"])
|
loader=loader, autoescape=jinja2.select_autoescape(["html", "htm", "xml"])
|
||||||
)
|
)
|
||||||
|
|
||||||
if hs.config.form_secret is None:
|
if hs.config.key.form_secret is None:
|
||||||
raise ConfigError(
|
raise ConfigError(
|
||||||
"Consent resource is enabled but form_secret is not set in "
|
"Consent resource is enabled but form_secret is not set in "
|
||||||
"config file. It should be set to an arbitrary secret string."
|
"config file. It should be set to an arbitrary secret string."
|
||||||
)
|
)
|
||||||
|
|
||||||
self._hmac_secret = hs.config.form_secret.encode("utf-8")
|
self._hmac_secret = hs.config.key.form_secret.encode("utf-8")
|
||||||
|
|
||||||
async def _async_render_GET(self, request: Request) -> None:
|
async def _async_render_GET(self, request: Request) -> None:
|
||||||
version = parse_string(request, "v", default=self._default_consent_version)
|
version = parse_string(request, "v", default=self._default_consent_version)
|
||||||
|
@ -70,19 +70,19 @@ class LocalKey(Resource):
|
|||||||
Resource.__init__(self)
|
Resource.__init__(self)
|
||||||
|
|
||||||
def update_response_body(self, time_now_msec: int) -> None:
|
def update_response_body(self, time_now_msec: int) -> None:
|
||||||
refresh_interval = self.config.key_refresh_interval
|
refresh_interval = self.config.key.key_refresh_interval
|
||||||
self.valid_until_ts = int(time_now_msec + refresh_interval)
|
self.valid_until_ts = int(time_now_msec + refresh_interval)
|
||||||
self.response_body = encode_canonical_json(self.response_json_object())
|
self.response_body = encode_canonical_json(self.response_json_object())
|
||||||
|
|
||||||
def response_json_object(self) -> JsonDict:
|
def response_json_object(self) -> JsonDict:
|
||||||
verify_keys = {}
|
verify_keys = {}
|
||||||
for key in self.config.signing_key:
|
for key in self.config.key.signing_key:
|
||||||
verify_key_bytes = key.verify_key.encode()
|
verify_key_bytes = key.verify_key.encode()
|
||||||
key_id = "%s:%s" % (key.alg, key.version)
|
key_id = "%s:%s" % (key.alg, key.version)
|
||||||
verify_keys[key_id] = {"key": encode_base64(verify_key_bytes)}
|
verify_keys[key_id] = {"key": encode_base64(verify_key_bytes)}
|
||||||
|
|
||||||
old_verify_keys = {}
|
old_verify_keys = {}
|
||||||
for key_id, key in self.config.old_signing_keys.items():
|
for key_id, key in self.config.key.old_signing_keys.items():
|
||||||
verify_key_bytes = key.encode()
|
verify_key_bytes = key.encode()
|
||||||
old_verify_keys[key_id] = {
|
old_verify_keys[key_id] = {
|
||||||
"key": encode_base64(verify_key_bytes),
|
"key": encode_base64(verify_key_bytes),
|
||||||
@ -95,13 +95,13 @@ class LocalKey(Resource):
|
|||||||
"verify_keys": verify_keys,
|
"verify_keys": verify_keys,
|
||||||
"old_verify_keys": old_verify_keys,
|
"old_verify_keys": old_verify_keys,
|
||||||
}
|
}
|
||||||
for key in self.config.signing_key:
|
for key in self.config.key.signing_key:
|
||||||
json_object = sign_json(json_object, self.config.server.server_name, key)
|
json_object = sign_json(json_object, self.config.server.server_name, key)
|
||||||
return json_object
|
return json_object
|
||||||
|
|
||||||
def render_GET(self, request: Request) -> int:
|
def render_GET(self, request: Request) -> int:
|
||||||
time_now = self.clock.time_msec()
|
time_now = self.clock.time_msec()
|
||||||
# Update the expiry time if less than half the interval remains.
|
# Update the expiry time if less than half the interval remains.
|
||||||
if time_now + self.config.key_refresh_interval / 2 > self.valid_until_ts:
|
if time_now + self.config.key.key_refresh_interval / 2 > self.valid_until_ts:
|
||||||
self.update_response_body(time_now)
|
self.update_response_body(time_now)
|
||||||
return respond_with_json_bytes(request, 200, self.response_body)
|
return respond_with_json_bytes(request, 200, self.response_body)
|
||||||
|
@ -97,7 +97,9 @@ class RemoteKey(DirectServeJsonResource):
|
|||||||
self.fetcher = ServerKeyFetcher(hs)
|
self.fetcher = ServerKeyFetcher(hs)
|
||||||
self.store = hs.get_datastore()
|
self.store = hs.get_datastore()
|
||||||
self.clock = hs.get_clock()
|
self.clock = hs.get_clock()
|
||||||
self.federation_domain_whitelist = hs.config.federation_domain_whitelist
|
self.federation_domain_whitelist = (
|
||||||
|
hs.config.federation.federation_domain_whitelist
|
||||||
|
)
|
||||||
self.config = hs.config
|
self.config = hs.config
|
||||||
|
|
||||||
async def _async_render_GET(self, request: Request) -> None:
|
async def _async_render_GET(self, request: Request) -> None:
|
||||||
@ -235,7 +237,7 @@ class RemoteKey(DirectServeJsonResource):
|
|||||||
signed_keys = []
|
signed_keys = []
|
||||||
for key_json in json_results:
|
for key_json in json_results:
|
||||||
key_json = json_decoder.decode(key_json.decode("utf-8"))
|
key_json = json_decoder.decode(key_json.decode("utf-8"))
|
||||||
for signing_key in self.config.key_server_signing_keys:
|
for signing_key in self.config.key.key_server_signing_keys:
|
||||||
key_json = sign_json(
|
key_json = sign_json(
|
||||||
key_json, self.config.server.server_name, signing_key
|
key_json, self.config.server.server_name, signing_key
|
||||||
)
|
)
|
||||||
|
@ -92,7 +92,9 @@ class MediaRepository:
|
|||||||
self.recently_accessed_remotes: Set[Tuple[str, str]] = set()
|
self.recently_accessed_remotes: Set[Tuple[str, str]] = set()
|
||||||
self.recently_accessed_locals: Set[str] = set()
|
self.recently_accessed_locals: Set[str] = set()
|
||||||
|
|
||||||
self.federation_domain_whitelist = hs.config.federation_domain_whitelist
|
self.federation_domain_whitelist = (
|
||||||
|
hs.config.federation.federation_domain_whitelist
|
||||||
|
)
|
||||||
|
|
||||||
# List of StorageProviders where we should search for media and
|
# List of StorageProviders where we should search for media and
|
||||||
# potentially upload to.
|
# potentially upload to.
|
||||||
|
@ -45,7 +45,7 @@ def build_synapse_client_resource_tree(hs: "HomeServer") -> Mapping[str, Resourc
|
|||||||
|
|
||||||
# provider-specific SSO bits. Only load these if they are enabled, since they
|
# provider-specific SSO bits. Only load these if they are enabled, since they
|
||||||
# rely on optional dependencies.
|
# rely on optional dependencies.
|
||||||
if hs.config.oidc_enabled:
|
if hs.config.oidc.oidc_enabled:
|
||||||
from synapse.rest.synapse.client.oidc import OIDCResource
|
from synapse.rest.synapse.client.oidc import OIDCResource
|
||||||
|
|
||||||
resources["/_synapse/client/oidc"] = OIDCResource(hs)
|
resources["/_synapse/client/oidc"] = OIDCResource(hs)
|
||||||
|
@ -82,7 +82,7 @@ class RoomMemberWorkerStore(EventsWorkerStore):
|
|||||||
|
|
||||||
if (
|
if (
|
||||||
self.hs.config.worker.run_background_tasks
|
self.hs.config.worker.run_background_tasks
|
||||||
and self.hs.config.metrics_flags.known_servers
|
and self.hs.config.metrics.metrics_flags.known_servers
|
||||||
):
|
):
|
||||||
self._known_servers_count = 1
|
self._known_servers_count = 1
|
||||||
self.hs.get_clock().looping_call(
|
self.hs.get_clock().looping_call(
|
||||||
|
@ -217,7 +217,7 @@ class AuthTestCase(unittest.HomeserverTestCase):
|
|||||||
macaroon = pymacaroons.Macaroon(
|
macaroon = pymacaroons.Macaroon(
|
||||||
location=self.hs.config.server_name,
|
location=self.hs.config.server_name,
|
||||||
identifier="key",
|
identifier="key",
|
||||||
key=self.hs.config.macaroon_secret_key,
|
key=self.hs.config.key.macaroon_secret_key,
|
||||||
)
|
)
|
||||||
macaroon.add_first_party_caveat("gen = 1")
|
macaroon.add_first_party_caveat("gen = 1")
|
||||||
macaroon.add_first_party_caveat("type = access")
|
macaroon.add_first_party_caveat("type = access")
|
||||||
@ -239,7 +239,7 @@ class AuthTestCase(unittest.HomeserverTestCase):
|
|||||||
macaroon = pymacaroons.Macaroon(
|
macaroon = pymacaroons.Macaroon(
|
||||||
location=self.hs.config.server_name,
|
location=self.hs.config.server_name,
|
||||||
identifier="key",
|
identifier="key",
|
||||||
key=self.hs.config.macaroon_secret_key,
|
key=self.hs.config.key.macaroon_secret_key,
|
||||||
)
|
)
|
||||||
macaroon.add_first_party_caveat("gen = 1")
|
macaroon.add_first_party_caveat("gen = 1")
|
||||||
macaroon.add_first_party_caveat("type = access")
|
macaroon.add_first_party_caveat("type = access")
|
||||||
|
@ -172,7 +172,7 @@ class PhoneHomeR30V2TestCase(HomeserverTestCase):
|
|||||||
|
|
||||||
# We don't want our tests to actually report statistics, so check
|
# We don't want our tests to actually report statistics, so check
|
||||||
# that it's not enabled
|
# that it's not enabled
|
||||||
assert not hs.config.report_stats
|
assert not hs.config.metrics.report_stats
|
||||||
|
|
||||||
# This starts the needed data collection that we rely on to calculate
|
# This starts the needed data collection that we rely on to calculate
|
||||||
# R30v2 metrics.
|
# R30v2 metrics.
|
||||||
|
@ -52,10 +52,10 @@ class ConfigLoadingTestCase(unittest.TestCase):
|
|||||||
hasattr(config, "macaroon_secret_key"),
|
hasattr(config, "macaroon_secret_key"),
|
||||||
"Want config to have attr macaroon_secret_key",
|
"Want config to have attr macaroon_secret_key",
|
||||||
)
|
)
|
||||||
if len(config.macaroon_secret_key) < 5:
|
if len(config.key.macaroon_secret_key) < 5:
|
||||||
self.fail(
|
self.fail(
|
||||||
"Want macaroon secret key to be string of at least length 5,"
|
"Want macaroon secret key to be string of at least length 5,"
|
||||||
"was: %r" % (config.macaroon_secret_key,)
|
"was: %r" % (config.key.macaroon_secret_key,)
|
||||||
)
|
)
|
||||||
|
|
||||||
config = HomeServerConfig.load_or_generate_config("", ["-c", self.file])
|
config = HomeServerConfig.load_or_generate_config("", ["-c", self.file])
|
||||||
@ -63,10 +63,10 @@ class ConfigLoadingTestCase(unittest.TestCase):
|
|||||||
hasattr(config, "macaroon_secret_key"),
|
hasattr(config, "macaroon_secret_key"),
|
||||||
"Want config to have attr macaroon_secret_key",
|
"Want config to have attr macaroon_secret_key",
|
||||||
)
|
)
|
||||||
if len(config.macaroon_secret_key) < 5:
|
if len(config.key.macaroon_secret_key) < 5:
|
||||||
self.fail(
|
self.fail(
|
||||||
"Want macaroon secret key to be string of at least length 5,"
|
"Want macaroon secret key to be string of at least length 5,"
|
||||||
"was: %r" % (config.macaroon_secret_key,)
|
"was: %r" % (config.key.macaroon_secret_key,)
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_load_succeeds_if_macaroon_secret_key_missing(self):
|
def test_load_succeeds_if_macaroon_secret_key_missing(self):
|
||||||
@ -101,7 +101,7 @@ class ConfigLoadingTestCase(unittest.TestCase):
|
|||||||
|
|
||||||
# The default Metrics Flags are off by default.
|
# The default Metrics Flags are off by default.
|
||||||
config = HomeServerConfig.load_config("", ["-c", self.file])
|
config = HomeServerConfig.load_config("", ["-c", self.file])
|
||||||
self.assertFalse(config.metrics_flags.known_servers)
|
self.assertFalse(config.metrics.metrics_flags.known_servers)
|
||||||
|
|
||||||
def generate_config(self):
|
def generate_config(self):
|
||||||
with redirect_stdout(StringIO()):
|
with redirect_stdout(StringIO()):
|
||||||
|
@ -30,7 +30,7 @@ class RatelimitConfigTestCase(TestCase):
|
|||||||
|
|
||||||
config = HomeServerConfig()
|
config = HomeServerConfig()
|
||||||
config.parse_config_dict(config_dict, "", "")
|
config.parse_config_dict(config_dict, "", "")
|
||||||
config_obj = config.rc_federation
|
config_obj = config.ratelimiting.rc_federation
|
||||||
|
|
||||||
self.assertEqual(config_obj.window_size, 20000)
|
self.assertEqual(config_obj.window_size, 20000)
|
||||||
self.assertEqual(config_obj.sleep_limit, 693)
|
self.assertEqual(config_obj.sleep_limit, 693)
|
||||||
|
@ -67,7 +67,7 @@ class AuthTestCase(unittest.HomeserverTestCase):
|
|||||||
v.satisfy_general(verify_type)
|
v.satisfy_general(verify_type)
|
||||||
v.satisfy_general(verify_nonce)
|
v.satisfy_general(verify_nonce)
|
||||||
v.satisfy_general(verify_guest)
|
v.satisfy_general(verify_guest)
|
||||||
v.verify(macaroon, self.hs.config.macaroon_secret_key)
|
v.verify(macaroon, self.hs.config.key.macaroon_secret_key)
|
||||||
|
|
||||||
def test_short_term_login_token_gives_user_id(self):
|
def test_short_term_login_token_gives_user_id(self):
|
||||||
token = self.macaroon_generator.generate_short_term_login_token(
|
token = self.macaroon_generator.generate_short_term_login_token(
|
||||||
|
@ -328,7 +328,7 @@ class BaseMultiWorkerStreamTestCase(unittest.HomeserverTestCase):
|
|||||||
|
|
||||||
# Set up TCP replication between master and the new worker if we don't
|
# Set up TCP replication between master and the new worker if we don't
|
||||||
# have Redis support enabled.
|
# have Redis support enabled.
|
||||||
if not worker_hs.config.redis_enabled:
|
if not worker_hs.config.redis.redis_enabled:
|
||||||
repl_handler = ReplicationCommandHandler(worker_hs)
|
repl_handler = ReplicationCommandHandler(worker_hs)
|
||||||
client = ClientReplicationStreamProtocol(
|
client = ClientReplicationStreamProtocol(
|
||||||
worker_hs,
|
worker_hs,
|
||||||
|
@ -815,9 +815,9 @@ class JWTTestCase(unittest.HomeserverTestCase):
|
|||||||
|
|
||||||
def make_homeserver(self, reactor, clock):
|
def make_homeserver(self, reactor, clock):
|
||||||
self.hs = self.setup_test_homeserver()
|
self.hs = self.setup_test_homeserver()
|
||||||
self.hs.config.jwt_enabled = True
|
self.hs.config.jwt.jwt_enabled = True
|
||||||
self.hs.config.jwt_secret = self.jwt_secret
|
self.hs.config.jwt.jwt_secret = self.jwt_secret
|
||||||
self.hs.config.jwt_algorithm = self.jwt_algorithm
|
self.hs.config.jwt.jwt_algorithm = self.jwt_algorithm
|
||||||
return self.hs
|
return self.hs
|
||||||
|
|
||||||
def jwt_encode(self, payload: Dict[str, Any], secret: str = jwt_secret) -> str:
|
def jwt_encode(self, payload: Dict[str, Any], secret: str = jwt_secret) -> str:
|
||||||
@ -1023,9 +1023,9 @@ class JWTPubKeyTestCase(unittest.HomeserverTestCase):
|
|||||||
|
|
||||||
def make_homeserver(self, reactor, clock):
|
def make_homeserver(self, reactor, clock):
|
||||||
self.hs = self.setup_test_homeserver()
|
self.hs = self.setup_test_homeserver()
|
||||||
self.hs.config.jwt_enabled = True
|
self.hs.config.jwt.jwt_enabled = True
|
||||||
self.hs.config.jwt_secret = self.jwt_pubkey
|
self.hs.config.jwt.jwt_secret = self.jwt_pubkey
|
||||||
self.hs.config.jwt_algorithm = "RS256"
|
self.hs.config.jwt.jwt_algorithm = "RS256"
|
||||||
return self.hs
|
return self.hs
|
||||||
|
|
||||||
def jwt_encode(self, payload: Dict[str, Any], secret: str = jwt_privatekey) -> str:
|
def jwt_encode(self, payload: Dict[str, Any], secret: str = jwt_privatekey) -> str:
|
||||||
|
@ -146,7 +146,7 @@ class RegisterRestServletTestCase(unittest.HomeserverTestCase):
|
|||||||
self.assertEquals(channel.json_body["errcode"], "M_FORBIDDEN")
|
self.assertEquals(channel.json_body["errcode"], "M_FORBIDDEN")
|
||||||
|
|
||||||
def test_POST_guest_registration(self):
|
def test_POST_guest_registration(self):
|
||||||
self.hs.config.macaroon_secret_key = "test"
|
self.hs.config.key.macaroon_secret_key = "test"
|
||||||
self.hs.config.allow_guest_access = True
|
self.hs.config.allow_guest_access = True
|
||||||
|
|
||||||
channel = self.make_request(b"POST", self.url + b"?kind=guest", b"{}")
|
channel = self.make_request(b"POST", self.url + b"?kind=guest", b"{}")
|
||||||
|
@ -513,7 +513,6 @@ class ApplicationServiceStoreConfigTestCase(unittest.TestCase):
|
|||||||
|
|
||||||
hs.config.appservice.app_service_config_files = [f1, f2]
|
hs.config.appservice.app_service_config_files = [f1, f2]
|
||||||
hs.config.caches.event_cache_size = 1
|
hs.config.caches.event_cache_size = 1
|
||||||
hs.config.password_providers = []
|
|
||||||
|
|
||||||
with self.assertRaises(ConfigError) as cm:
|
with self.assertRaises(ConfigError) as cm:
|
||||||
database = hs.get_datastores().databases[0]
|
database = hs.get_datastores().databases[0]
|
||||||
|
@ -95,4 +95,4 @@ def build_rc_config(settings: Optional[dict] = None):
|
|||||||
config_dict.update(settings or {})
|
config_dict.update(settings or {})
|
||||||
config = HomeServerConfig()
|
config = HomeServerConfig()
|
||||||
config.parse_config_dict(config_dict, "", "")
|
config.parse_config_dict(config_dict, "", "")
|
||||||
return config.rc_federation
|
return config.ratelimiting.rc_federation
|
||||||
|
Loading…
Reference in New Issue
Block a user