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 (part 2) #10812

Merged
merged 5 commits into from
Sep 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/10812.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/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ def __init__(self, hs: "HomeServer"):

self._auth_blocking = AuthBlocking(self.hs)

self._track_appservice_user_ips = hs.config.track_appservice_user_ips
self._macaroon_secret_key = hs.config.macaroon_secret_key
self._track_appservice_user_ips = hs.config.appservice.track_appservice_user_ips
self._macaroon_secret_key = hs.config.key.macaroon_secret_key
self._force_tracing_for_users = hs.config.tracing.force_tracing_for_users

async def check_user_in_room(
Expand Down
16 changes: 9 additions & 7 deletions synapse/api/auth_blocking.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ class AuthBlocking:
def __init__(self, hs: "HomeServer"):
self.store = hs.get_datastore()

self._server_notices_mxid = hs.config.server_notices_mxid
self._hs_disabled = hs.config.hs_disabled
self._hs_disabled_message = hs.config.hs_disabled_message
self._admin_contact = hs.config.admin_contact
self._max_mau_value = hs.config.max_mau_value
self._limit_usage_by_mau = hs.config.limit_usage_by_mau
self._mau_limits_reserved_threepids = hs.config.mau_limits_reserved_threepids
self._server_notices_mxid = hs.config.servernotices.server_notices_mxid
self._hs_disabled = hs.config.server.hs_disabled
self._hs_disabled_message = hs.config.server.hs_disabled_message
self._admin_contact = hs.config.server.admin_contact
self._max_mau_value = hs.config.server.max_mau_value
self._limit_usage_by_mau = hs.config.server.limit_usage_by_mau
self._mau_limits_reserved_threepids = (
hs.config.server.mau_limits_reserved_threepids
)
self._server_name = hs.hostname
self._track_appservice_user_ips = hs.config.appservice.track_appservice_user_ips

Expand Down
8 changes: 4 additions & 4 deletions synapse/crypto/context_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def __init__(self, config):
self._config = config

# Check if we're using a custom list of a CA certificates
trust_root = config.federation_ca_trust_root
trust_root = config.tls.federation_ca_trust_root
if trust_root is None:
# Use CA root certs provided by OpenSSL
trust_root = platformTrust()
Expand All @@ -113,7 +113,7 @@ def __init__(self, config):
# moving to TLS 1.2 by default, we want to respect the config option if
# it is set to 1.0 (which the alternate option, raiseMinimumTo, will not
# let us do).
minTLS = _TLS_VERSION_MAP[config.federation_client_minimum_tls_version]
minTLS = _TLS_VERSION_MAP[config.tls.federation_client_minimum_tls_version]

_verify_ssl = CertificateOptions(
trustRoot=trust_root, insecurelyLowerMinimumTo=minTLS
Expand All @@ -125,10 +125,10 @@ def __init__(self, config):
self._no_verify_ssl_context = _no_verify_ssl.getContext()
self._no_verify_ssl_context.set_info_callback(_context_info_cb)

self._should_verify = self._config.federation_verify_certificates
self._should_verify = self._config.tls.federation_verify_certificates

self._federation_certificate_verification_whitelist = (
self._config.federation_certificate_verification_whitelist
self._config.tls.federation_certificate_verification_whitelist
)

def get_options(self, host: bytes):
Expand Down
2 changes: 1 addition & 1 deletion synapse/crypto/keyring.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ def __init__(self, hs: "HomeServer"):
super().__init__(hs)
self.clock = hs.get_clock()
self.client = hs.get_federation_http_client()
self.key_servers = self.config.key_servers
self.key_servers = self.config.key.key_servers

async def _fetch_keys(
self, keys_to_fetch: List[_FetchKeyRequest]
Expand Down
2 changes: 1 addition & 1 deletion synapse/federation/federation_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -1237,7 +1237,7 @@ def register_instances_for_edu(
self._edu_type_to_instance[edu_type] = instance_names

async def on_edu(self, edu_type: str, origin: str, content: dict) -> None:
if not self.config.use_presence and edu_type == EduTypes.Presence:
if not self.config.server.use_presence and edu_type == EduTypes.Presence:
return

# Check if we have a handler on this instance
Expand Down
2 changes: 1 addition & 1 deletion synapse/federation/sender/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ def send_presence_to_destinations(
destinations (list[str])
"""

if not states or not self.hs.config.use_presence:
if not states or not self.hs.config.server.use_presence:
# No-op if presence is disabled.
return

Expand Down
2 changes: 1 addition & 1 deletion synapse/handlers/initial_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ async def _room_initial_sync_joined(

async def get_presence():
# If presence is disabled, return an empty list
if not self.hs.config.use_presence:
if not self.hs.config.server.use_presence:
return []

states = await presence_handler.get_states(
Expand Down
12 changes: 6 additions & 6 deletions synapse/handlers/presence.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ def __init__(self, hs: "HomeServer"):

self._presence_writer_instance = hs.config.worker.writers.presence[0]

self._presence_enabled = hs.config.use_presence
self._presence_enabled = hs.config.server.use_presence

# Route presence EDUs to the right worker
hs.get_federation_registry().register_instances_for_edu(
Expand Down Expand Up @@ -584,7 +584,7 @@ async def set_state(
user_id = target_user.to_string()

# If presence is disabled, no-op
if not self.hs.config.use_presence:
if not self.hs.config.server.use_presence:
return

# Proxy request to instance that writes presence
Expand All @@ -601,7 +601,7 @@ async def bump_presence_active_time(self, user: UserID) -> None:
with the app.
"""
# If presence is disabled, no-op
if not self.hs.config.use_presence:
if not self.hs.config.server.use_presence:
return

# Proxy request to instance that writes presence
Expand All @@ -618,7 +618,7 @@ def __init__(self, hs: "HomeServer"):
self.server_name = hs.hostname
self.wheel_timer: WheelTimer[str] = WheelTimer()
self.notifier = hs.get_notifier()
self._presence_enabled = hs.config.use_presence
self._presence_enabled = hs.config.server.use_presence

federation_registry = hs.get_federation_registry()

Expand Down Expand Up @@ -916,7 +916,7 @@ async def bump_presence_active_time(self, user: UserID) -> None:
with the app.
"""
# If presence is disabled, no-op
if not self.hs.config.use_presence:
if not self.hs.config.server.use_presence:
return

user_id = user.to_string()
Expand Down Expand Up @@ -949,7 +949,7 @@ async def user_syncing(
"""
# Override if it should affect the user's presence, if presence is
# disabled.
if not self.hs.config.use_presence:
if not self.hs.config.server.use_presence:
affect_presence = False

if affect_presence:
Expand Down
2 changes: 1 addition & 1 deletion synapse/handlers/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -1090,7 +1090,7 @@ async def generate_sync_result(
block_all_presence_data = (
since_token is None and sync_config.filter_collection.blocks_all_presence()
)
if self.hs_config.use_presence and not block_all_presence_data:
if self.hs_config.server.use_presence and not block_all_presence_data:
logger.debug("Fetching presence data")
await self._generate_sync_entry_for_presence(
sync_result_builder,
Expand Down
7 changes: 5 additions & 2 deletions synapse/http/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,11 @@ def __init__(

self.user_agent = hs.version_string
self.clock = hs.get_clock()
if hs.config.user_agent_suffix:
self.user_agent = "%s %s" % (self.user_agent, hs.config.user_agent_suffix)
if hs.config.server.user_agent_suffix:
self.user_agent = "%s %s" % (
self.user_agent,
hs.config.server.user_agent_suffix,
)

# We use this for our body producers to ensure that they use the correct
# reactor.
Expand Down
2 changes: 1 addition & 1 deletion synapse/push/httppusher.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ async def _build_notification_dict(
if event.type == "m.room.member" and event.is_state():
d["notification"]["membership"] = event.content["membership"]
d["notification"]["user_is_target"] = event.state_key == self.user_id
if self.hs.config.push_include_content and event.content:
if self.hs.config.push.push_include_content and event.content:
d["notification"]["content"] = event.content

# We no longer send aliases separately, instead, we send the human
Expand Down
10 changes: 5 additions & 5 deletions synapse/push/mailer.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def __init__(
self.state_handler = self.hs.get_state_handler()
self.storage = hs.get_storage()
self.app_name = app_name
self.email_subjects: EmailSubjectConfig = hs.config.email_subjects
self.email_subjects: EmailSubjectConfig = hs.config.email.email_subjects

logger.info("Created Mailer for app_name %s" % app_name)

Expand Down Expand Up @@ -796,8 +796,8 @@ def _make_room_link(self, room_id: str) -> str:
Returns:
A link to open a room in the web client.
"""
if self.hs.config.email_riot_base_url:
base_url = "%s/#/room" % (self.hs.config.email_riot_base_url)
if self.hs.config.email.email_riot_base_url:
base_url = "%s/#/room" % (self.hs.config.email.email_riot_base_url)
elif self.app_name == "Vector":
# need /beta for Universal Links to work on iOS
base_url = "https://vector.im/beta/#/room"
Expand All @@ -815,9 +815,9 @@ def _make_notif_link(self, notif: Dict[str, str]) -> str:
Returns:
A link to open the notification in the web client.
"""
if self.hs.config.email_riot_base_url:
if self.hs.config.email.email_riot_base_url:
return "%s/#/room/%s/%s" % (
self.hs.config.email_riot_base_url,
self.hs.config.email.email_riot_base_url,
notif["room_id"],
notif["event_id"],
)
Expand Down
8 changes: 4 additions & 4 deletions synapse/push/pusher.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ def __init__(self, hs: "HomeServer"):
"http": HttpPusher
}

logger.info("email enable notifs: %r", hs.config.email_enable_notifs)
if hs.config.email_enable_notifs:
logger.info("email enable notifs: %r", hs.config.email.email_enable_notifs)
if hs.config.email.email_enable_notifs:
self.mailers: Dict[str, Mailer] = {}

self._notif_template_html = hs.config.email_notif_template_html
self._notif_template_text = hs.config.email_notif_template_text
self._notif_template_html = hs.config.email.email_notif_template_html
self._notif_template_text = hs.config.email.email_notif_template_text

self.pusher_types["email"] = self._create_email_pusher

Expand Down
2 changes: 1 addition & 1 deletion synapse/push/pusherpool.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def __init__(self, hs: "HomeServer"):
self.clock = self.hs.get_clock()

# We shard the handling of push notifications by user ID.
self._pusher_shard_config = hs.config.push.pusher_shard_config
self._pusher_shard_config = hs.config.worker.pusher_shard_config
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm surprised this one used to work since it was specific, but pointing to the wrong one?

self._instance_name = hs.get_instance_name()
self._should_start_pushers = (
self._instance_name in self._pusher_shard_config.instances
Expand Down
16 changes: 8 additions & 8 deletions synapse/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ def get_auth(self) -> Auth:

@cache_in_self
def get_http_client_context_factory(self) -> IPolicyForHTTPS:
if self.config.use_insecure_ssl_client_just_for_testing_do_not_use:
if self.config.tls.use_insecure_ssl_client_just_for_testing_do_not_use:
return InsecureInterceptableContextFactory()
return RegularPolicyForHTTPS()

Expand All @@ -418,8 +418,8 @@ def get_proxied_blacklisted_http_client(self) -> SimpleHttpClient:
"""
return SimpleHttpClient(
self,
ip_whitelist=self.config.ip_range_whitelist,
ip_blacklist=self.config.ip_range_blacklist,
ip_whitelist=self.config.server.ip_range_whitelist,
ip_blacklist=self.config.server.ip_range_blacklist,
use_proxy=True,
)

Expand Down Expand Up @@ -801,18 +801,18 @@ def get_outbound_redis_connection(self) -> Optional["RedisProtocol"]:

logger.info(
"Connecting to redis (host=%r port=%r) for external cache",
self.config.redis_host,
self.config.redis_port,
self.config.redis.redis_host,
self.config.redis.redis_port,
)

return lazyConnection(
hs=self,
host=self.config.redis_host,
port=self.config.redis_port,
host=self.config.redis.redis_host,
port=self.config.redis.redis_port,
password=self.config.redis.redis_password,
reconnect=True,
)

def should_send_federation(self) -> bool:
"Should this server be sending federation traffic directly?"
return self.config.send_federation
return self.config.worker.send_federation