This repository was archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Standardise the module interface #10062
Merged
Merged
Changes from 14 commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
e388397
First cut at a standardised module interface
babolivier 11f525c
Don't use a centralised handler and let modules register what they ne…
babolivier ceb9904
Specify where the new methods need to be called from
babolivier c4d09a8
Implement new module interface for the spam checker
babolivier f5098c9
Don't centralise registration of hooks and web resources
babolivier 7da2fd3
Don't use a class if a simple function works just as well
babolivier f1c0889
Fix CI
babolivier 817fc75
Lint
babolivier a988b8c
Incorporate comments
babolivier ba4e678
Lint
babolivier a06649c
Don't inhibit rejection reason from spamchecker
babolivier d55b17b
Make mypy happy
babolivier 2c8d6d5
Fix tests
babolivier 10153fc
Lint
babolivier eda9658
Merge branch 'develop' into babolivier/modules
babolivier 1c9e3d4
Document the new module interface
babolivier 870647d
Merge branch 'develop' into babolivier/modules
babolivier b92965c
Add new doc to the summary, and add a deprecation notice to the spam …
babolivier d440297
Fix a typo in registration docs
babolivier ce4347b
Point to the new docs in the sample configuration
babolivier 79ee967
Improve example
babolivier 7bf8fdb
Apply suggestions from code review
babolivier a63a060
Merge branch 'develop' into babolivier/modules
babolivier c6ed049
Incorporate review comments
babolivier 39a02b1
Lint
babolivier 8e28b3e
Use async callbacks in tests
babolivier 9c5bffd
Correctly wrap check_registration_for_spam
babolivier 468b900
Lint
babolivier 5a9f391
Move support for 3-arg check_registration_for_spam to legacy code
babolivier 6a326f9
Remove unused import
babolivier 575556f
Remove other unused import
babolivier 12774dc
Explicitely type legacy callback as not None
babolivier b12855c
Don't import cast again
babolivier cd596f5
Be more vague in upgrade notes and add deprecation notice to changelog
babolivier 3a28f6a
Phrasing
babolivier 9cbe1e6
Merge branch 'develop' into babolivier/modules
babolivier 387d41b
Types don't like commas
babolivier 249c607
Fix tests and phrasing
babolivier File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Standardised the module interface. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Modules | ||
|
||
Synapse supports extending its functionalities by configuring external modules. | ||
|
||
## Using modules | ||
|
||
To use a module on Synapse, add it to the `modules` section of the configuration file: | ||
|
||
```yaml | ||
modules: | ||
- module: my_super_module.MySuperClass | ||
config: | ||
do_thing: true | ||
- module: my_other_super_module.SomeClass | ||
config: {} | ||
``` | ||
|
||
Each module is defined by a path to a Python class as well as a configuration. This | ||
information for a given module should be available in the module's own documentation. | ||
|
||
**Note**: When using third-party modules, you effectively allow someone else to run | ||
custom code on your Synapse homeserver. Server admins are encouraged to verify the | ||
provenance of the modules they use on their homeserver and make sure the modules aren't | ||
running malicious code on their instance. | ||
|
||
babolivier marked this conversation as resolved.
Show resolved
Hide resolved
|
||
## Writing a module | ||
|
||
TODO |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# 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 synapse.config._base import Config, ConfigError | ||
from synapse.util.module_loader import load_module | ||
|
||
|
||
class ModulesConfig(Config): | ||
section = "modules" | ||
|
||
def read_config(self, config: dict, **kwargs): | ||
self.loaded_modules = [] | ||
babolivier marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
configured_modules = config.get("modules") or [] | ||
for i, module in enumerate(configured_modules): | ||
config_path = ("modules", "<item %i>" % i) | ||
if not isinstance(module, dict): | ||
raise ConfigError("expected a mapping", config_path) | ||
|
||
self.loaded_modules.append(load_module(module, config_path)) | ||
|
||
def generate_config_section(self, **kwargs): | ||
return """ | ||
## Modules ## | ||
|
||
# Server admins can expand Synapse's functionalities by using external modules | ||
# to complement certain operations. | ||
babolivier marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# | ||
# See https://github.com/matrix-org/synapse/tree/master/docs/modules.md for | ||
# more documentation on how to configure or create custom modules for Synapse. | ||
# | ||
modules: | ||
# - module: my_super_module.MySuperClass | ||
# config: | ||
# do_thing: true | ||
# - module: my_other_super_module.SomeClass | ||
# config: {} | ||
babolivier marked this conversation as resolved.
Show resolved
Hide resolved
|
||
""" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.