-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
An federation whitelist query endpoint extension
- Loading branch information
1 parent
c925b45
commit e03916c
Showing
6 changed files
with
133 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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 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,29 @@ | ||
# | ||
# This file is licensed under the Affero General Public License (AGPL) version 3. | ||
# | ||
# Copyright (C) 2023 New Vector, Ltd | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as | ||
# published by the Free Software Foundation, either version 3 of the | ||
# License, or (at your option) any later version. | ||
# | ||
# See the GNU Affero General Public License for more details: | ||
# <https://www.gnu.org/licenses/agpl-3.0.html>. | ||
# | ||
|
||
from typing import Any | ||
|
||
from synapse.config._base import Config | ||
from synapse.types import JsonDict | ||
|
||
|
||
class ExtensionsConfig(Config): | ||
"""Config section for enabling extension features""" | ||
|
||
section = "extensions" | ||
|
||
def read_config(self, config: JsonDict, **kwargs: Any) -> None: | ||
self.federation_whitelist_endpoint: bool = config.get( | ||
"extension_federation_whitelist_endpoint", False | ||
) |
This file contains 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 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 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,65 @@ | ||
# | ||
# This file is licensed under the Affero General Public License (AGPL) version 3. | ||
# | ||
# Copyright (C) 2024 New Vector, Ltd | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as | ||
# published by the Free Software Foundation, either version 3 of the | ||
# License, or (at your option) any later version. | ||
# | ||
# See the GNU Affero General Public License for more details: | ||
# <https://www.gnu.org/licenses/agpl-3.0.html>. | ||
# | ||
|
||
import logging | ||
from typing import TYPE_CHECKING, Tuple | ||
|
||
|
||
from synapse.http.server import ( | ||
DirectServeJsonResource, | ||
) | ||
from synapse.http.site import SynapseRequest | ||
from synapse.types import JsonDict | ||
|
||
if TYPE_CHECKING: | ||
from synapse.server import HomeServer | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class FederationWhitelistResource(DirectServeJsonResource): | ||
"""Custom endpoint (disabled by default) to fetch the federation whitelist | ||
config. | ||
Only enabled if `federation_whitelist_endpoint` extension feature is | ||
enabled. | ||
Response format: | ||
{ | ||
"whitelist_enabled": true, // Whether there is a federation whitelist | ||
"whitelist": [ // Which hosts are allowed by the whitelist | ||
"example.com" | ||
] | ||
} | ||
""" | ||
|
||
PATH = "/_synapse/client/config/federation_whitelist" | ||
|
||
def __init__(self, hs: "HomeServer"): | ||
super().__init__() | ||
|
||
self._federation_whitelist = hs.config.federation.federation_domain_whitelist | ||
|
||
self._auth = hs.get_auth() | ||
|
||
async def _async_render_GET(self, request: SynapseRequest) -> Tuple[int, JsonDict]: | ||
await self._auth.get_user_by_req(request) | ||
|
||
return_dict: JsonDict = { | ||
"whitelist_enabled": self._federation_whitelist is not None, | ||
"whitelist": self._federation_whitelist or [], | ||
} | ||
|
||
return 200, return_dict |