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

remove HomeServer.get_config #9815

Merged
merged 1 commit into from
Apr 14, 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/9815.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Replace `HomeServer.get_config()` with inline references.
2 changes: 1 addition & 1 deletion synapse/app/generic_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ def start_listening(self, listeners: Iterable[ListenerConfig]):
listener.bind_addresses, listener.port, manhole_globals={"hs": self}
)
elif listener.type == "metrics":
if not self.get_config().enable_metrics:
if not self.config.enable_metrics:
logger.warning(
(
"Metrics listener configured, but "
Expand Down
18 changes: 9 additions & 9 deletions synapse/app/homeserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def _configure_named_resource(self, name, compress=False):
}
)

if self.get_config().threepid_behaviour_email == ThreepidBehaviour.LOCAL:
if self.config.threepid_behaviour_email == ThreepidBehaviour.LOCAL:
from synapse.rest.synapse.client.password_reset import (
PasswordResetSubmitTokenResource,
)
Expand Down Expand Up @@ -230,7 +230,7 @@ def _configure_named_resource(self, name, compress=False):
)

if name in ["media", "federation", "client"]:
if self.get_config().enable_media_repo:
if self.config.enable_media_repo:
media_repo = self.get_media_repository_resource()
resources.update(
{MEDIA_PREFIX: media_repo, LEGACY_MEDIA_PREFIX: media_repo}
Expand All @@ -244,7 +244,7 @@ def _configure_named_resource(self, name, compress=False):
resources[SERVER_KEY_V2_PREFIX] = KeyApiV2Resource(self)

if name == "webclient":
webclient_loc = self.get_config().web_client_location
webclient_loc = self.config.web_client_location

if webclient_loc is None:
logger.warning(
Expand All @@ -265,7 +265,7 @@ def _configure_named_resource(self, name, compress=False):
# https://twistedmatrix.com/trac/ticket/7678
resources[WEB_CLIENT_PREFIX] = File(webclient_loc)

if name == "metrics" and self.get_config().enable_metrics:
if name == "metrics" and self.config.enable_metrics:
resources[METRICS_PREFIX] = MetricsResource(RegistryProxy)

if name == "replication":
Expand All @@ -274,17 +274,17 @@ def _configure_named_resource(self, name, compress=False):
return resources

def start_listening(self, listeners: Iterable[ListenerConfig]):
config = self.get_config()

if config.redis_enabled:
if self.config.redis_enabled:
# If redis is enabled we connect via the replication command handler
# in the same way as the workers (since we're effectively a client
# rather than a server).
self.get_tcp_replication().start_replication(self)

for listener in listeners:
if listener.type == "http":
self._listening_services.extend(self._listener_http(config, listener))
self._listening_services.extend(
self._listener_http(self.config, listener)
)
elif listener.type == "manhole":
_base.listen_manhole(
listener.bind_addresses, listener.port, manhole_globals={"hs": self}
Expand All @@ -298,7 +298,7 @@ def start_listening(self, listeners: Iterable[ListenerConfig]):
for s in services:
reactor.addSystemEventTrigger("before", "shutdown", s.stopListening)
elif listener.type == "metrics":
if not self.get_config().enable_metrics:
if not self.config.enable_metrics:
logger.warning(
(
"Metrics listener configured, but "
Expand Down
2 changes: 1 addition & 1 deletion synapse/crypto/keyring.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ async def get_keys(
class BaseV2KeyFetcher(KeyFetcher):
def __init__(self, hs: "HomeServer"):
self.store = hs.get_datastore()
self.config = hs.get_config()
self.config = hs.config

async def process_v2_response(
self, from_server: str, response_json: JsonDict, time_added_ms: int
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 @@ -136,7 +136,7 @@ def __init__(self, hs: "HomeServer"):
) # type: ResponseCache[Tuple[str, str]]

self._federation_metrics_domains = (
hs.get_config().federation.federation_metrics_domains
hs.config.federation.federation_metrics_domains
)

async def on_backfill_request(
Expand Down
2 changes: 1 addition & 1 deletion synapse/federation/sender/transaction_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def __init__(self, hs: "synapse.server.HomeServer"):
self._transport_layer = hs.get_federation_transport_client()

self._federation_metrics_domains = (
hs.get_config().federation.federation_metrics_domains
hs.config.federation.federation_metrics_domains
)

# HACK to get unique tx id
Expand Down
2 changes: 1 addition & 1 deletion synapse/rest/media/v1/config_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class MediaConfigResource(DirectServeJsonResource):

def __init__(self, hs: "HomeServer"):
super().__init__()
config = hs.get_config()
config = hs.config
self.clock = hs.get_clock()
self.auth = hs.get_auth()
self.limits_dict = {"m.upload.size": config.max_upload_size}
Expand Down
3 changes: 0 additions & 3 deletions synapse/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,6 @@ def get_datastores(self) -> Databases:

return self.datastores

def get_config(self) -> HomeServerConfig:
return self.config

@cache_in_self
def get_distributor(self) -> Distributor:
return Distributor()
Expand Down
2 changes: 1 addition & 1 deletion tests/app/test_openid_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def test_openid_listener(self, names, expectation):
}

# Listen with the config
self.hs._listener_http(self.hs.get_config(), parse_listener_def(config))
self.hs._listener_http(self.hs.config, parse_listener_def(config))

# Grab the resource from the site that was told to listen
site = self.reactor.tcpServers[0][1]
Expand Down