element-hq / element-hq/synapse

Module API: Provide a way to access homeserver config

Open
#18,340 0 comments 0 reactions 0 assignees View on GitHub
A-Config A-Modules T-Enhancement
Dominant language
Python
Stars
4.6k
Forks
600
Avg merge
5d 22h
Merged PRs (30d)
51

Description

Provide a way to access homeserver config in the Module API.

### Use case

We have two modules where one provides room retention functionality and other provides API's to modify those room retention settings. We would like to read the module config of one module in the other module so that the API can respond with a default value if the setting hasn't been set in the database yet

### Current state of things

Currently, you only have explicit access to your own modules config which is passed in the module constructor

### Workaround

We're currently working around this by accessing the private/internal `module_api._hs` field.

```python
class MyModule:
def __init__(
self, config: MyModuleConfig, module_api: ModuleApi
):
# Access homeserver config
logger.info(module_api._hs.config)
# Access config of other modules
logger.info(module_api._hs.config.modules.loaded_modules)
```

### Alternatives

We could have the room retention module itself expose an HTTP API to fetch the config which our other module can consume.

This might even be deemed the correct approach to all of this when we have two modules that can cooperate. Better separation of concerns.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.