1# Copyright 2018 New Vector Ltd
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#     http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15from typing import TYPE_CHECKING
16
17from synapse.http.server import JsonResource
18from synapse.replication.http import (
19    account_data,
20    devices,
21    federation,
22    login,
23    membership,
24    presence,
25    push,
26    register,
27    send_event,
28    streams,
29)
30
31if TYPE_CHECKING:
32    from synapse.server import HomeServer
33
34REPLICATION_PREFIX = "/_synapse/replication"
35
36
37class ReplicationRestResource(JsonResource):
38    def __init__(self, hs: "HomeServer"):
39        # We enable extracting jaeger contexts here as these are internal APIs.
40        super().__init__(hs, canonical_json=False, extract_context=True)
41        self.register_servlets(hs)
42
43    def register_servlets(self, hs: "HomeServer"):
44        send_event.register_servlets(hs, self)
45        federation.register_servlets(hs, self)
46        presence.register_servlets(hs, self)
47        membership.register_servlets(hs, self)
48        streams.register_servlets(hs, self)
49        account_data.register_servlets(hs, self)
50        push.register_servlets(hs, self)
51
52        # The following can't currently be instantiated on workers.
53        if hs.config.worker.worker_app is None:
54            login.register_servlets(hs, self)
55            register.register_servlets(hs, self)
56            devices.register_servlets(hs, self)
57