Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move the configuration file handling code into a separate module #385

Merged
merged 28 commits into from
Sep 13, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
cf17843
Add SydentConfig class and use when calling Sydent constructor
Sep 7, 2021
2985b37
Move database config handling over to SydentConfig
Sep 7, 2021
3a1a400
Move crypto config handling over to SydentConfig
Sep 7, 2021
91fdc6b
Move sms config handling over to SydentConfig
Sep 7, 2021
4b0a900
Move deprecated email template config over to SydentConfig
Sep 7, 2021
21b030a
Move email config handled by synapse.py over to SynapseConfig
Sep 7, 2021
11f8711
Move rest of email config over to SydenConfig
Sep 7, 2021
f09779b
Move deprecated http template config over to SydentConfig
Sep 7, 2021
25aac48
Move rest of http config handling over to SynapseConfig
Sep 7, 2021
1492c1c
Move server name config handling to SydentConfig
Sep 7, 2021
bb02656
Move 'general' template config handling over to SydentConfig
Sep 7, 2021
2d460ee
Move rest of 'general' config handling over to SydentConfig
Sep 7, 2021
4b0eb67
Remove deprecated template argument from get_branded_template
Sep 8, 2021
37b928b
Remove old cfg argument from Sydent constructor
Sep 8, 2021
a9415f4
Add changelog
Sep 8, 2021
c0b7b03
Merge remote-tracking branch 'origin/main' into azren/move_config_cod…
Sep 9, 2021
cf58f3a
Add file that got lost while fixing merge conflicts
Sep 9, 2021
85bd376
Apply suggestions from code review
Sep 10, 2021
6cf0090
Run linters
Sep 10, 2021
b0ad7d0
Make initial read of internalapi.http.port a local variable
Sep 10, 2021
760963e
Standardize it being one empty line after licence
Sep 10, 2021
d2c24c3
Document more clearly that parse_config_file sets up logging
Sep 10, 2021
e4b0bcb
Merge remote-tracking branch 'origin/main' into azren/move_config_cod…
Sep 10, 2021
64d3d34
Readd lines between licence and code to make linters happy
Sep 10, 2021
e57fa59
Apply suggestions from code review
Sep 10, 2021
d12d283
Add missing file from last commit
Sep 10, 2021
e4ce136
Fix type issues in config code
Sep 13, 2021
98bc803
Merge remote-tracking branch 'origin/main' into azren/move_config_cod…
Sep 13, 2021
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 scripts/casefold_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ def update_global_associations(
config = parse_config_file(args.config_path)

sydent_config = SydentConfig()
sydent_config.parse_from_config_parser(config)

reactor = ResolvingMemoryReactorClock()
sydent = Sydent(config, sydent_config, reactor, False)
Expand Down
14 changes: 13 additions & 1 deletion sydent/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

from configparser import ConfigParser

from sydent.config.database import DatabaseConfig


class ConfigError(Exception):
pass
Expand All @@ -26,7 +28,9 @@ class SydentConfig:
"""

def __init__(self):
self.config_sections = []
self.database = DatabaseConfig()

self.config_sections = [self.database]

def _parse_config(self, cfg: ConfigParser) -> None:
Azrenbeth marked this conversation as resolved.
Show resolved Hide resolved
"""
Expand All @@ -37,3 +41,11 @@ def _parse_config(self, cfg: ConfigParser) -> None:
"""
for section in self.config_sections:
section.parse_config(cfg)

def parse_from_config_parser(self, cfg: ConfigParser) -> None:
"""
Parse the configuration from a ConfigParser object

:param cfg: the configuration to be parsed
"""
self._parse_config(cfg)
28 changes: 28 additions & 0 deletions sydent/config/database.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# 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.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# 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.

from typing import TYPE_CHECKING

if TYPE_CHECKING:
Azrenbeth marked this conversation as resolved.
Show resolved Hide resolved
from configparser import ConfigParser


class DatabaseConfig:
def parse_config(self, cfg: "ConfigParser") -> None:
"""
Parse the database section of the config

:param cfg: the configuration to be parsed
"""
self.database_path = cfg.get("db", "db.file")
2 changes: 1 addition & 1 deletion sydent/db/sqlitedb.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class SqliteDatabase:
def __init__(self, syd: "Sydent") -> None:
self.sydent = syd

dbFilePath = self.sydent.cfg.get("db", "db.file")
dbFilePath = self.sydent.config.database.database_path
logger.info("Using DB file %s", dbFilePath)

self.db = sqlite3.connect(dbFilePath)
Expand Down
2 changes: 2 additions & 0 deletions sydent/sydent.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,5 +610,7 @@ def run_gc():
setup_logging(cfg)

sydent_config = SydentConfig()
sydent_config.parse_from_config_parser(cfg)

syd = Sydent(cfg, sydent_config=sydent_config)
syd.run()
5 changes: 4 additions & 1 deletion tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,14 @@ def make_sydent(test_config={}):

reactor = ResolvingMemoryReactorClock()

cfg = parse_config_dict(test_config)

sydent_config = SydentConfig()
sydent_config.parse_from_config_parser(cfg)

return Sydent(
reactor=reactor,
cfg=parse_config_dict(test_config),
cfg=cfg,
sydent_config=sydent_config,
use_tls_for_federation=False,
)
Expand Down