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

Conversation

Azrenbeth
Copy link
Contributor

@Azrenbeth Azrenbeth commented Sep 8, 2021

Seperates the config parsing from the rest of the code

Advantages of parsing the config before doing anything else:

  • More similar to Synapse
  • Better seperates out the different config sections
  • Removes calls to confusing ConfigParser.get() from the rest of the code
  • Allows for easy migration to different config format in the future (e.g. YAML like Synapse's)

All of the parsing should be exactly the same as it was before, but just done earlier


A lot of the changes are one of these two forms:

  1. self.sydent.cfg.get("section","option") => self.sydent.config.section.option
  2. self.sydent.option => self.sydent.config.general.option

Sydent.get_branded_template() no longer has a deprecated_template_name argument

  • All calls to this method now check the deprecated option first
  • Needed to change all calls to this anyway but I'm unsure if this was correct approach

Can be reviewed commit to commit

Configuration handling will be slowly moved over to this SydentConfig
class and away from the rest of the code.
@Azrenbeth Azrenbeth force-pushed the azren/move_config_code_out branch from e8d9964 to bdaffc6 Compare September 8, 2021 09:55
Azrenbeth added 13 commits September 8, 2021 10:57
The SydentEd25519 class is no longer needed as all it did was
handle the signingkey config option before (which is now done
in CryptoConfig)

In the current setup, if no key is present a new one is generated
and saved back to file. This is a special case for the crypto config
and so the line `return self.crypto.save_key` isn't more general.

In the future this might not be needed (e.g. by having sydent only
do key generation when it first creates a config file for you, rather
than everytime one is not found) and so this special casing can be
removed.
test_jinja_templates used `("email", "email.verification_template")`
for this argument, however this config option isn't mentioned
anywhere else in the code (or even in the test's config) so it's ok
to remove it
- Move config file and dict handling over to SydentConfig
- Alter all places where Sydent object is constructed
- Remove parse_cfg_bool and set_from_comma_set_string from sydent.py
  as these functions were only used for config parsing
- Remove save_config from sydent.py as this can now be done from
  SydentConfig
@Azrenbeth Azrenbeth force-pushed the azren/move_config_code_out branch from bdaffc6 to 37b928b Compare September 8, 2021 09:58
@Azrenbeth Azrenbeth requested a review from richvdh September 8, 2021 10:17
@Azrenbeth Azrenbeth marked this pull request as ready for review September 8, 2021 10:19
@richvdh richvdh changed the title Move the configuration file handling code into a seperate module Move the configuration file handling code into a separate module Sep 9, 2021
Copy link
Member

@richvdh richvdh left a comment

Choose a reason for hiding this comment

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

This was much clearer - thank you so much @Azrenbeth!

sydent/config/__init__.py Show resolved Hide resolved
sydent/config/database.py Outdated Show resolved Hide resolved
sydent/config/__init__.py Outdated Show resolved Hide resolved
sydent/sydent.py Outdated Show resolved Hide resolved
changelog.d/385.misc Outdated Show resolved Hide resolved
sydent/config/general.py Outdated Show resolved Hide resolved
sydent/terms/terms.py Outdated Show resolved Hide resolved
sydent/sydent.py Outdated Show resolved Hide resolved
sydent/sydent.py Outdated Show resolved Hide resolved
sydent/config/__init__.py Show resolved Hide resolved
Azrenbeth added 5 commits September 10, 2021 10:32
- Fix typo in changelog
- Remove ... between params and return in docstrings
- Update copyright year
- Remove conditional import for type checking if conditional not needed
- Use fallback for email templates instead of has_option
- Fix typo in blank server.name warning
- Add template path used to template path not found warning
- Set values for prometheus and sentry settings even when not enabled
- Use fallback for verify_response_template instead of has_option
- Set value for internal_bind_address even when API not enabled
- Remove random capitilisation in ca_cert_file
- Add type hint to ClientTLSOptionsFactory constructor
- Add 'is deprecated' comments near old template usages
- Move terms_path config option read outside of try:
Azrenbeth added 2 commits September 10, 2021 11:37
@Azrenbeth Azrenbeth requested a review from richvdh September 10, 2021 10:43
Copy link
Member

@richvdh richvdh left a comment

Choose a reason for hiding this comment

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

nearly there!

sydent/config/__init__.py Outdated Show resolved Hide resolved
sydent/config/__init__.py Outdated Show resolved Hide resolved
scripts/casefold_db.py Show resolved Hide resolved
sydent/config/http.py Show resolved Hide resolved
sydent/config/general.py Outdated Show resolved Hide resolved

self.sentry_enabled = cfg.has_option("general", "sentry_dsn")
if self.sentry_enabled:
self.sentry_dsn = cfg.get("general", "sentry_dsn")
Copy link
Member

Choose a reason for hiding this comment

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

Would it not be better to leave sentry_enabled in as a config setting?

you mean, as a property in this class, as opposed to a setting in the config file? It just feels a bit redundant to me - why have sentry_enabled as well as sentry_dsn?

As to consistency - I'd probably argue we get rid of prometheus_enabled and internal_api_enabled too.

Anyway, it's not a big deal, let's leave it for now.

(The eventual aim of the XYZ_enabled options being to have enabled settings in the config if/when it gets migrated to YAML)

I'm not entirely convinced we should migrate to YAML, and I'm also not convinced that we need explicit enabled settings :)

if self.prometheus_enabled:
self.prometheus_port = cfg.getint("general", "prometheus_port")
self.prometheus_addr = cfg.get("general", "prometheus_addr")
self.prometheus_port = cfg.getint("general", "prometheus_port", fallback=None)
Copy link
Member

Choose a reason for hiding this comment

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

to confirm: have you checked that getint is happy with fallback=None as opposed to an integer?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Azrenbeth added 2 commits September 10, 2021 13:45
- `parse_config` now returns bool
- Add BaseConfig class
- Fix typo
- Update licence
@Azrenbeth Azrenbeth requested a review from richvdh September 10, 2021 13:06
Copy link
Member

@richvdh richvdh left a comment

Choose a reason for hiding this comment

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

lgtm otherwise!

sydent/config/http.py Outdated Show resolved Hide resolved
Azrenbeth added 2 commits September 13, 2021 11:35
- Update remaining parse-configs to return bool
- Add in some type hints
- Parse IPs into lists not set (just needs to be Iterable)
- Add missing import to __init__.py
@Azrenbeth Azrenbeth merged commit d6db3b1 into main Sep 13, 2021
@Azrenbeth Azrenbeth deleted the azren/move_config_code_out branch September 13, 2021 10:47
Azrenbeth pushed a commit that referenced this pull request Sep 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants