Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Use direct references for some configuration variables #10798

Merged
merged 9 commits into from
Sep 13, 2021
1 change: 1 addition & 0 deletions changelog.d/10798.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Use direct references to config flags.
4 changes: 2 additions & 2 deletions synapse/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ def __init__(self, hs_config):
"""
if hs_config.form_secret is None:
raise ConfigError("form_secret not set in config")
if hs_config.public_baseurl is None:
if hs_config.server.public_baseurl is None:
raise ConfigError("public_baseurl not set in config")

self._hmac_secret = hs_config.form_secret.encode("utf-8")
self._public_baseurl = hs_config.public_baseurl
self._public_baseurl = hs_config.server.public_baseurl

def build_user_consent_uri(self, user_id):
"""Build a URI which we can give to the user to do their privacy
Expand Down
12 changes: 8 additions & 4 deletions synapse/app/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def start_worker_reactor(appname, config, run_command=reactor.run):
run_command (Callable[]): callable that actually runs the reactor
"""

logger = logging.getLogger(config.worker_app)
logger = logging.getLogger(config.worker.worker_app)

start_reactor(
appname,
Expand Down Expand Up @@ -398,7 +398,7 @@ def run_sighup(*args, **kwargs):

# If background tasks are running on the main process, start collecting the
# phone home stats.
if hs.config.run_background_tasks:
if hs.config.worker.run_background_tasks:
start_phone_stats_home(hs)

# We now freeze all allocated objects in the hopes that (almost)
Expand Down Expand Up @@ -433,9 +433,13 @@ def setup_sentry(hs):

# We set some default tags that give some context to this instance
with sentry_sdk.configure_scope() as scope:
scope.set_tag("matrix_server_name", hs.config.server_name)
scope.set_tag("matrix_server_name", hs.config.server.server_name)

app = hs.config.worker_app if hs.config.worker_app else "synapse.app.homeserver"
app = (
hs.config.worker.worker_app
if hs.config.worker.worker_app
else "synapse.app.homeserver"
)
name = hs.get_instance_name()
scope.set_tag("worker_app", app)
scope.set_tag("worker_name", name)
Expand Down
10 changes: 5 additions & 5 deletions synapse/app/admin_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,12 @@ def start(config_options):
sys.stderr.write("\n" + str(e) + "\n")
sys.exit(1)

if config.worker_app is not None:
assert config.worker_app == "synapse.app.admin_cmd"
if config.worker.worker_app is not None:
assert config.worker.worker_app == "synapse.app.admin_cmd"

# Update the config with some basic overrides so that don't have to specify
# a full worker config.
config.worker_app = "synapse.app.admin_cmd"
config.worker.worker_app = "synapse.app.admin_cmd"

if (
not config.worker_daemonize
Expand All @@ -196,7 +196,7 @@ def start(config_options):

# Explicitly disable background processes
config.update_user_directory = False
config.run_background_tasks = False
config.worker.run_background_tasks = False
config.start_pushers = False
config.pusher_shard_config.instances = []
config.send_federation = False
Expand All @@ -205,7 +205,7 @@ def start(config_options):
synapse.events.USE_FROZEN_DICTS = config.use_frozen_dicts

ss = AdminCmdServer(
config.server_name,
config.server.server_name,
config=config,
version_string="Synapse/" + get_version_string(synapse),
)
Expand Down
8 changes: 4 additions & 4 deletions synapse/app/generic_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ def start(config_options):
sys.exit(1)

# For backwards compatibility let any of the old app names.
assert config.worker_app in (
assert config.worker.worker_app in (
"synapse.app.appservice",
"synapse.app.client_reader",
"synapse.app.event_creator",
Expand All @@ -430,7 +430,7 @@ def start(config_options):
"synapse.app.user_dir",
)

if config.worker_app == "synapse.app.appservice":
if config.worker.worker_app == "synapse.app.appservice":
if config.appservice.notify_appservices:
sys.stderr.write(
"\nThe appservices must be disabled in the main synapse process"
Expand All @@ -446,7 +446,7 @@ def start(config_options):
# For other worker types we force this to off.
config.appservice.notify_appservices = False

if config.worker_app == "synapse.app.user_dir":
if config.worker.worker_app == "synapse.app.user_dir":
if config.server.update_user_directory:
sys.stderr.write(
"\nThe update_user_directory must be disabled in the main synapse process"
Expand All @@ -469,7 +469,7 @@ def start(config_options):
synapse.metrics.MIN_TIME_BETWEEN_GCS = config.server.gc_seconds

hs = GenericWorkerServer(
config.server_name,
config.server.server_name,
config=config,
version_string="Synapse/" + get_version_string(synapse),
)
Expand Down
2 changes: 1 addition & 1 deletion synapse/app/homeserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ def setup(config_options):
synapse.metrics.MIN_TIME_BETWEEN_GCS = config.server.gc_seconds

hs = SynapseHomeServer(
config.server_name,
config.server.server_name,
config=config,
version_string="Synapse/" + get_version_string(synapse),
)
Expand Down
2 changes: 1 addition & 1 deletion synapse/app/phone_stats_home.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ async def phone_stats_home(hs, stats, stats_process=_stats_process):

store = hs.get_datastore()

stats["homeserver"] = hs.config.server_name
stats["homeserver"] = hs.config.server.server_name
stats["server_context"] = hs.config.server_context
stats["timestamp"] = now
stats["uptime_seconds"] = uptime
Expand Down
4 changes: 2 additions & 2 deletions synapse/config/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def _setup_stdlib_logging(config, log_config_path, logBeginner: LogBeginner) ->
# writes.

log_context_filter = LoggingContextFilter()
log_metadata_filter = MetadataFilter({"server_name": config.server_name})
log_metadata_filter = MetadataFilter({"server_name": config.server.server_name})
old_factory = logging.getLogRecordFactory()

def factory(*args, **kwargs):
Expand Down Expand Up @@ -335,5 +335,5 @@ def setup_logging(
# Log immediately so we can grep backwards.
logging.warning("***** STARTING SERVER *****")
logging.warning("Server %s version %s", sys.argv[0], get_version_string(synapse))
logging.info("Server hostname: %s", config.server_name)
logging.info("Server hostname: %s", config.server.server_name)
logging.info("Instance name: %s", hs.get_instance_name())
2 changes: 1 addition & 1 deletion synapse/events/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def validate_new(self, event: EventBase, config: HomeServerConfig):
self._validate_retention(event)

if event.type == EventTypes.ServerACL:
if not server_matches_acl_event(config.server_name, event):
if not server_matches_acl_event(config.server.server_name, event):
raise SynapseError(
400, "Can't create an ACL event that denies the local server"
)
Expand Down
3 changes: 2 additions & 1 deletion synapse/federation/sender/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,8 @@ def __init__(self, hs: "HomeServer"):
self._queues_awaiting_rr_flush_by_room: Dict[str, Set[PerDestinationQueue]] = {}

self._rr_txn_interval_per_room_ms = (
1000.0 / hs.config.federation_rr_transactions_per_room_per_second
1000.0
/ hs.config.ratelimiting.federation_rr_transactions_per_room_per_second
)

# wake up destinations that have outstanding PDUs to be caught up
Expand Down
2 changes: 1 addition & 1 deletion synapse/groups/attestations.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def __init__(self, hs: "HomeServer"):
self.is_mine_id = hs.is_mine_id
self.attestations = hs.get_groups_attestation_signing()

if not hs.config.worker_app:
if not hs.config.worker.worker_app:
self._renew_attestations_loop = self.clock.looping_call(
self._start_renew_attestations, 30 * 60 * 1000
)
Expand Down
8 changes: 4 additions & 4 deletions synapse/handlers/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,16 @@ def __init__(self, hs: "HomeServer"):
self.request_ratelimiter = Ratelimiter(
store=self.store, clock=self.clock, rate_hz=0, burst_count=0
)
self._rc_message = self.hs.config.rc_message
self._rc_message = self.hs.config.ratelimiting.rc_message

# Check whether ratelimiting room admin message redaction is enabled
# by the presence of rate limits in the config
if self.hs.config.rc_admin_redaction:
if self.hs.config.ratelimiting.rc_admin_redaction:
self.admin_redaction_ratelimiter: Optional[Ratelimiter] = Ratelimiter(
store=self.store,
clock=self.clock,
rate_hz=self.hs.config.rc_admin_redaction.per_second,
burst_count=self.hs.config.rc_admin_redaction.burst_count,
rate_hz=self.hs.config.ratelimiting.rc_admin_redaction.per_second,
burst_count=self.hs.config.ratelimiting.rc_admin_redaction.burst_count,
)
else:
self.admin_redaction_ratelimiter = None
Expand Down
4 changes: 2 additions & 2 deletions synapse/handlers/account_validity.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def __init__(self, hs: "HomeServer"):
)

# Check the renewal emails to send and send them every 30min.
if hs.config.run_background_tasks:
if hs.config.worker.run_background_tasks:
self.clock.looping_call(self._send_renewal_emails, 30 * 60 * 1000)

self._is_user_expired_callbacks: List[IS_USER_EXPIRED_CALLBACK] = []
Expand Down Expand Up @@ -249,7 +249,7 @@ async def _send_renewal_email(self, user_id: str, expiration_ts: int) -> None:

renewal_token = await self._get_renewal_token(user_id)
url = "%s_matrix/client/unstable/account_validity/renew?token=%s" % (
self.hs.config.public_baseurl,
self.hs.config.server.public_baseurl,
renewal_token,
)

Expand Down
16 changes: 8 additions & 8 deletions synapse/handlers/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,8 @@ def __init__(self, hs: "HomeServer"):
self._failed_uia_attempts_ratelimiter = Ratelimiter(
store=self.store,
clock=self.clock,
rate_hz=self.hs.config.rc_login_failed_attempts.per_second,
burst_count=self.hs.config.rc_login_failed_attempts.burst_count,
rate_hz=self.hs.config.ratelimiting.rc_login_failed_attempts.per_second,
burst_count=self.hs.config.ratelimiting.rc_login_failed_attempts.burst_count,
)

# The number of seconds to keep a UI auth session active.
Expand All @@ -255,14 +255,14 @@ def __init__(self, hs: "HomeServer"):
self._failed_login_attempts_ratelimiter = Ratelimiter(
store=self.store,
clock=hs.get_clock(),
rate_hz=self.hs.config.rc_login_failed_attempts.per_second,
burst_count=self.hs.config.rc_login_failed_attempts.burst_count,
rate_hz=self.hs.config.ratelimiting.rc_login_failed_attempts.per_second,
burst_count=self.hs.config.ratelimiting.rc_login_failed_attempts.burst_count,
)

self._clock = self.hs.get_clock()

# Expire old UI auth sessions after a period of time.
if hs.config.run_background_tasks:
if hs.config.worker.run_background_tasks:
self._clock.looping_call(
run_as_background_process,
5 * 60 * 1000,
Expand All @@ -289,7 +289,7 @@ def __init__(self, hs: "HomeServer"):
hs.config.sso_account_deactivated_template
)

self._server_name = hs.config.server_name
self._server_name = hs.config.server.server_name

# cast to tuple for use with str.startswith
self._whitelisted_sso_clients = tuple(hs.config.sso_client_whitelist)
Expand Down Expand Up @@ -749,7 +749,7 @@ def _get_params_terms(self) -> dict:
"name": self.hs.config.user_consent_policy_name,
"url": "%s_matrix/consent?v=%s"
% (
self.hs.config.public_baseurl,
self.hs.config.server.public_baseurl,
self.hs.config.user_consent_version,
),
},
Expand Down Expand Up @@ -1799,7 +1799,7 @@ def generate_delete_pusher_token(self, user_id: str) -> str:

def _generate_base_macaroon(self, user_id: str) -> pymacaroons.Macaroon:
macaroon = pymacaroons.Macaroon(
location=self.hs.config.server_name,
location=self.hs.config.server.server_name,
identifier="key",
key=self.hs.config.macaroon_secret_key,
)
Expand Down
2 changes: 1 addition & 1 deletion synapse/handlers/deactivate_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def __init__(self, hs: "HomeServer"):

# Start the user parter loop so it can resume parting users from rooms where
# it left off (if it has work left to do).
if hs.config.run_background_tasks:
if hs.config.worker.run_background_tasks:
hs.get_reactor().callWhenRunning(self._start_user_parting)

self._account_validity_enabled = (
Expand Down
4 changes: 2 additions & 2 deletions synapse/handlers/devicemessage.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ def __init__(self, hs: "HomeServer"):
self._ratelimiter = Ratelimiter(
store=self.store,
clock=hs.get_clock(),
rate_hz=hs.config.rc_key_requests.per_second,
burst_count=hs.config.rc_key_requests.burst_count,
rate_hz=hs.config.ratelimiting.rc_key_requests.per_second,
burst_count=hs.config.ratelimiting.rc_key_requests.burst_count,
)

async def on_direct_to_device_edu(self, origin: str, content: JsonDict) -> None:
Expand Down
2 changes: 1 addition & 1 deletion synapse/handlers/e2e_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def __init__(self, hs: "HomeServer"):

federation_registry = hs.get_federation_registry()

self._is_master = hs.config.worker_app is None
self._is_master = hs.config.worker.worker_app is None
if not self._is_master:
self._user_device_resync_client = (
ReplicationUserDevicesResyncRestServlet.make_client(hs)
Expand Down
4 changes: 2 additions & 2 deletions synapse/handlers/federation.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def __init__(self, hs: "HomeServer"):
hs
)

if hs.config.worker_app:
if hs.config.worker.worker_app:
self._maybe_store_room_on_outlier_membership = (
ReplicationStoreRoomOnOutlierMembershipRestServlet.make_client(hs)
)
Expand Down Expand Up @@ -1614,7 +1614,7 @@ async def _clean_room_for_join(self, room_id: str) -> None:
Args:
room_id
"""
if self.config.worker_app:
if self.config.worker.worker_app:
await self._clean_room_for_join_client(room_id)
else:
await self.store.clean_room_for_join(room_id)
Expand Down
4 changes: 2 additions & 2 deletions synapse/handlers/federation_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def __init__(self, hs: "HomeServer"):
self._ephemeral_messages_enabled = hs.config.server.enable_ephemeral_messages

self._send_events = ReplicationFederationSendEventsRestServlet.make_client(hs)
if hs.config.worker_app:
if hs.config.worker.worker_app:
self._user_device_resync = (
ReplicationUserDevicesResyncRestServlet.make_client(hs)
)
Expand Down Expand Up @@ -1009,7 +1009,7 @@ async def _resync_device(self, sender: str) -> None:
await self._store.mark_remote_user_device_cache_as_stale(sender)

# Immediately attempt a resync in the background
if self._config.worker_app:
if self._config.worker.worker_app:
await self._user_device_resync(user_id=sender)
else:
await self._device_list_updater.user_device_resync(sender)
Expand Down
4 changes: 2 additions & 2 deletions synapse/handlers/identity.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,13 +540,13 @@ async def requestMsisdnToken(

# It is already checked that public_baseurl is configured since this code
# should only be used if account_threepid_delegate_msisdn is true.
assert self.hs.config.public_baseurl
assert self.hs.config.server.public_baseurl

# we need to tell the client to send the token back to us, since it doesn't
# otherwise know where to send it, so add submit_url response parameter
# (see also MSC2078)
data["submit_url"] = (
self.hs.config.public_baseurl
self.hs.config.server.public_baseurl
+ "_matrix/client/unstable/add_threepid/msisdn/submit_token"
)
return data
Expand Down
4 changes: 2 additions & 2 deletions synapse/handlers/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def __init__(self, hs: "HomeServer"):
# scheduled.
self._scheduled_expiry: Optional[IDelayedCall] = None

if not hs.config.worker_app:
if not hs.config.worker.worker_app:
run_as_background_process(
"_schedule_next_expiry", self._schedule_next_expiry
)
Expand Down Expand Up @@ -461,7 +461,7 @@ def __init__(self, hs: "HomeServer"):
self._dummy_events_threshold = hs.config.dummy_events_threshold

if (
self.config.run_background_tasks
self.config.worker.run_background_tasks
and self.config.cleanup_extremities_with_dummy_events
):
self.clock.looping_call(
Expand Down
2 changes: 1 addition & 1 deletion synapse/handlers/oidc.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ def __init__(
self._allow_existing_users = provider.allow_existing_users

self._http_client = hs.get_proxied_http_client()
self._server_name: str = hs.config.server_name
self._server_name: str = hs.config.server.server_name

# identifier for the external_ids table
self.idp_id = provider.idp_id
Expand Down
2 changes: 1 addition & 1 deletion synapse/handlers/pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def __init__(self, hs: "HomeServer"):
self._retention_allowed_lifetime_min = hs.config.retention_allowed_lifetime_min
self._retention_allowed_lifetime_max = hs.config.retention_allowed_lifetime_max

if hs.config.run_background_tasks and hs.config.retention_enabled:
if hs.config.worker.run_background_tasks and hs.config.retention_enabled:
# Run the purge jobs described in the configuration file.
for job in hs.config.retention_purge_jobs:
logger.info("Setting up purge job with config: %s", job)
Expand Down
Loading