forked from MirrorHub/synapse
Add groundwork for new versions of federation APIs
This commit is contained in:
parent
7e41545e8b
commit
bb63e7ca4f
3 changed files with 73 additions and 68 deletions
|
@ -24,7 +24,8 @@ from synapse.config import ConfigError
|
||||||
|
|
||||||
CLIENT_PREFIX = "/_matrix/client/api/v1"
|
CLIENT_PREFIX = "/_matrix/client/api/v1"
|
||||||
CLIENT_V2_ALPHA_PREFIX = "/_matrix/client/v2_alpha"
|
CLIENT_V2_ALPHA_PREFIX = "/_matrix/client/v2_alpha"
|
||||||
FEDERATION_PREFIX = "/_matrix/federation/v1"
|
FEDERATION_PREFIX = "/_matrix/federation"
|
||||||
|
FEDERATION_V1_PREFIX = FEDERATION_PREFIX + "/v1"
|
||||||
STATIC_PREFIX = "/_matrix/static"
|
STATIC_PREFIX = "/_matrix/static"
|
||||||
WEB_CLIENT_PREFIX = "/_matrix/client"
|
WEB_CLIENT_PREFIX = "/_matrix/client"
|
||||||
CONTENT_REPO_PREFIX = "/_matrix/content"
|
CONTENT_REPO_PREFIX = "/_matrix/content"
|
||||||
|
|
|
@ -21,7 +21,7 @@ from six.moves import urllib
|
||||||
from twisted.internet import defer
|
from twisted.internet import defer
|
||||||
|
|
||||||
from synapse.api.constants import Membership
|
from synapse.api.constants import Membership
|
||||||
from synapse.api.urls import FEDERATION_PREFIX as PREFIX
|
from synapse.api.urls import FEDERATION_V1_PREFIX
|
||||||
from synapse.util.logutils import log_function
|
from synapse.util.logutils import log_function
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
@ -51,7 +51,7 @@ class TransportLayerClient(object):
|
||||||
logger.debug("get_room_state dest=%s, room=%s",
|
logger.debug("get_room_state dest=%s, room=%s",
|
||||||
destination, room_id)
|
destination, room_id)
|
||||||
|
|
||||||
path = _create_path(PREFIX, "/state/%s/", room_id)
|
path = _create_v1_path("/state/%s/", room_id)
|
||||||
return self.client.get_json(
|
return self.client.get_json(
|
||||||
destination, path=path, args={"event_id": event_id},
|
destination, path=path, args={"event_id": event_id},
|
||||||
)
|
)
|
||||||
|
@ -73,7 +73,7 @@ class TransportLayerClient(object):
|
||||||
logger.debug("get_room_state_ids dest=%s, room=%s",
|
logger.debug("get_room_state_ids dest=%s, room=%s",
|
||||||
destination, room_id)
|
destination, room_id)
|
||||||
|
|
||||||
path = _create_path(PREFIX, "/state_ids/%s/", room_id)
|
path = _create_v1_path("/state_ids/%s/", room_id)
|
||||||
return self.client.get_json(
|
return self.client.get_json(
|
||||||
destination, path=path, args={"event_id": event_id},
|
destination, path=path, args={"event_id": event_id},
|
||||||
)
|
)
|
||||||
|
@ -95,7 +95,7 @@ class TransportLayerClient(object):
|
||||||
logger.debug("get_pdu dest=%s, event_id=%s",
|
logger.debug("get_pdu dest=%s, event_id=%s",
|
||||||
destination, event_id)
|
destination, event_id)
|
||||||
|
|
||||||
path = _create_path(PREFIX, "/event/%s/", event_id)
|
path = _create_v1_path("/event/%s/", event_id)
|
||||||
return self.client.get_json(destination, path=path, timeout=timeout)
|
return self.client.get_json(destination, path=path, timeout=timeout)
|
||||||
|
|
||||||
@log_function
|
@log_function
|
||||||
|
@ -121,7 +121,7 @@ class TransportLayerClient(object):
|
||||||
# TODO: raise?
|
# TODO: raise?
|
||||||
return
|
return
|
||||||
|
|
||||||
path = _create_path(PREFIX, "/backfill/%s/", room_id)
|
path = _create_v1_path("/backfill/%s/", room_id)
|
||||||
|
|
||||||
args = {
|
args = {
|
||||||
"v": event_tuples,
|
"v": event_tuples,
|
||||||
|
@ -167,7 +167,7 @@ class TransportLayerClient(object):
|
||||||
# generated by the json_data_callback.
|
# generated by the json_data_callback.
|
||||||
json_data = transaction.get_dict()
|
json_data = transaction.get_dict()
|
||||||
|
|
||||||
path = _create_path(PREFIX, "/send/%s/", transaction.transaction_id)
|
path = _create_v1_path("/send/%s/", transaction.transaction_id)
|
||||||
|
|
||||||
response = yield self.client.put_json(
|
response = yield self.client.put_json(
|
||||||
transaction.destination,
|
transaction.destination,
|
||||||
|
@ -184,7 +184,7 @@ class TransportLayerClient(object):
|
||||||
@log_function
|
@log_function
|
||||||
def make_query(self, destination, query_type, args, retry_on_dns_fail,
|
def make_query(self, destination, query_type, args, retry_on_dns_fail,
|
||||||
ignore_backoff=False):
|
ignore_backoff=False):
|
||||||
path = _create_path(PREFIX, "/query/%s", query_type)
|
path = _create_v1_path("/query/%s", query_type)
|
||||||
|
|
||||||
content = yield self.client.get_json(
|
content = yield self.client.get_json(
|
||||||
destination=destination,
|
destination=destination,
|
||||||
|
@ -231,7 +231,7 @@ class TransportLayerClient(object):
|
||||||
"make_membership_event called with membership='%s', must be one of %s" %
|
"make_membership_event called with membership='%s', must be one of %s" %
|
||||||
(membership, ",".join(valid_memberships))
|
(membership, ",".join(valid_memberships))
|
||||||
)
|
)
|
||||||
path = _create_path(PREFIX, "/make_%s/%s/%s", membership, room_id, user_id)
|
path = _create_v1_path("/make_%s/%s/%s", membership, room_id, user_id)
|
||||||
|
|
||||||
ignore_backoff = False
|
ignore_backoff = False
|
||||||
retry_on_dns_fail = False
|
retry_on_dns_fail = False
|
||||||
|
@ -258,7 +258,7 @@ class TransportLayerClient(object):
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
@log_function
|
@log_function
|
||||||
def send_join(self, destination, room_id, event_id, content):
|
def send_join(self, destination, room_id, event_id, content):
|
||||||
path = _create_path(PREFIX, "/send_join/%s/%s", room_id, event_id)
|
path = _create_v1_path("/send_join/%s/%s", room_id, event_id)
|
||||||
|
|
||||||
response = yield self.client.put_json(
|
response = yield self.client.put_json(
|
||||||
destination=destination,
|
destination=destination,
|
||||||
|
@ -271,7 +271,7 @@ class TransportLayerClient(object):
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
@log_function
|
@log_function
|
||||||
def send_leave(self, destination, room_id, event_id, content):
|
def send_leave(self, destination, room_id, event_id, content):
|
||||||
path = _create_path(PREFIX, "/send_leave/%s/%s", room_id, event_id)
|
path = _create_v1_path("/send_leave/%s/%s", room_id, event_id)
|
||||||
|
|
||||||
response = yield self.client.put_json(
|
response = yield self.client.put_json(
|
||||||
destination=destination,
|
destination=destination,
|
||||||
|
@ -290,7 +290,7 @@ class TransportLayerClient(object):
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
@log_function
|
@log_function
|
||||||
def send_invite(self, destination, room_id, event_id, content):
|
def send_invite(self, destination, room_id, event_id, content):
|
||||||
path = _create_path(PREFIX, "/invite/%s/%s", room_id, event_id)
|
path = _create_v1_path("/invite/%s/%s", room_id, event_id)
|
||||||
|
|
||||||
response = yield self.client.put_json(
|
response = yield self.client.put_json(
|
||||||
destination=destination,
|
destination=destination,
|
||||||
|
@ -306,7 +306,7 @@ class TransportLayerClient(object):
|
||||||
def get_public_rooms(self, remote_server, limit, since_token,
|
def get_public_rooms(self, remote_server, limit, since_token,
|
||||||
search_filter=None, include_all_networks=False,
|
search_filter=None, include_all_networks=False,
|
||||||
third_party_instance_id=None):
|
third_party_instance_id=None):
|
||||||
path = PREFIX + "/publicRooms"
|
path = _create_v1_path("/publicRooms")
|
||||||
|
|
||||||
args = {
|
args = {
|
||||||
"include_all_networks": "true" if include_all_networks else "false",
|
"include_all_networks": "true" if include_all_networks else "false",
|
||||||
|
@ -332,7 +332,7 @@ class TransportLayerClient(object):
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
@log_function
|
@log_function
|
||||||
def exchange_third_party_invite(self, destination, room_id, event_dict):
|
def exchange_third_party_invite(self, destination, room_id, event_dict):
|
||||||
path = _create_path(PREFIX, "/exchange_third_party_invite/%s", room_id,)
|
path = _create_v1_path("/exchange_third_party_invite/%s", room_id,)
|
||||||
|
|
||||||
response = yield self.client.put_json(
|
response = yield self.client.put_json(
|
||||||
destination=destination,
|
destination=destination,
|
||||||
|
@ -345,7 +345,7 @@ class TransportLayerClient(object):
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
@log_function
|
@log_function
|
||||||
def get_event_auth(self, destination, room_id, event_id):
|
def get_event_auth(self, destination, room_id, event_id):
|
||||||
path = _create_path(PREFIX, "/event_auth/%s/%s", room_id, event_id)
|
path = _create_v1_path("/event_auth/%s/%s", room_id, event_id)
|
||||||
|
|
||||||
content = yield self.client.get_json(
|
content = yield self.client.get_json(
|
||||||
destination=destination,
|
destination=destination,
|
||||||
|
@ -357,7 +357,7 @@ class TransportLayerClient(object):
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
@log_function
|
@log_function
|
||||||
def send_query_auth(self, destination, room_id, event_id, content):
|
def send_query_auth(self, destination, room_id, event_id, content):
|
||||||
path = _create_path(PREFIX, "/query_auth/%s/%s", room_id, event_id)
|
path = _create_v1_path("/query_auth/%s/%s", room_id, event_id)
|
||||||
|
|
||||||
content = yield self.client.post_json(
|
content = yield self.client.post_json(
|
||||||
destination=destination,
|
destination=destination,
|
||||||
|
@ -392,7 +392,7 @@ class TransportLayerClient(object):
|
||||||
Returns:
|
Returns:
|
||||||
A dict containg the device keys.
|
A dict containg the device keys.
|
||||||
"""
|
"""
|
||||||
path = PREFIX + "/user/keys/query"
|
path = _create_v1_path("/user/keys/query")
|
||||||
|
|
||||||
content = yield self.client.post_json(
|
content = yield self.client.post_json(
|
||||||
destination=destination,
|
destination=destination,
|
||||||
|
@ -419,7 +419,7 @@ class TransportLayerClient(object):
|
||||||
Returns:
|
Returns:
|
||||||
A dict containg the device keys.
|
A dict containg the device keys.
|
||||||
"""
|
"""
|
||||||
path = _create_path(PREFIX, "/user/devices/%s", user_id)
|
path = _create_v1_path("/user/devices/%s", user_id)
|
||||||
|
|
||||||
content = yield self.client.get_json(
|
content = yield self.client.get_json(
|
||||||
destination=destination,
|
destination=destination,
|
||||||
|
@ -455,7 +455,7 @@ class TransportLayerClient(object):
|
||||||
A dict containg the one-time keys.
|
A dict containg the one-time keys.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
path = PREFIX + "/user/keys/claim"
|
path = _create_v1_path("/user/keys/claim")
|
||||||
|
|
||||||
content = yield self.client.post_json(
|
content = yield self.client.post_json(
|
||||||
destination=destination,
|
destination=destination,
|
||||||
|
@ -469,7 +469,7 @@ class TransportLayerClient(object):
|
||||||
@log_function
|
@log_function
|
||||||
def get_missing_events(self, destination, room_id, earliest_events,
|
def get_missing_events(self, destination, room_id, earliest_events,
|
||||||
latest_events, limit, min_depth, timeout):
|
latest_events, limit, min_depth, timeout):
|
||||||
path = _create_path(PREFIX, "/get_missing_events/%s", room_id,)
|
path = _create_v1_path("/get_missing_events/%s", room_id,)
|
||||||
|
|
||||||
content = yield self.client.post_json(
|
content = yield self.client.post_json(
|
||||||
destination=destination,
|
destination=destination,
|
||||||
|
@ -489,7 +489,7 @@ class TransportLayerClient(object):
|
||||||
def get_group_profile(self, destination, group_id, requester_user_id):
|
def get_group_profile(self, destination, group_id, requester_user_id):
|
||||||
"""Get a group profile
|
"""Get a group profile
|
||||||
"""
|
"""
|
||||||
path = _create_path(PREFIX, "/groups/%s/profile", group_id,)
|
path = _create_v1_path("/groups/%s/profile", group_id,)
|
||||||
|
|
||||||
return self.client.get_json(
|
return self.client.get_json(
|
||||||
destination=destination,
|
destination=destination,
|
||||||
|
@ -508,7 +508,7 @@ class TransportLayerClient(object):
|
||||||
requester_user_id (str)
|
requester_user_id (str)
|
||||||
content (dict): The new profile of the group
|
content (dict): The new profile of the group
|
||||||
"""
|
"""
|
||||||
path = _create_path(PREFIX, "/groups/%s/profile", group_id,)
|
path = _create_v1_path("/groups/%s/profile", group_id,)
|
||||||
|
|
||||||
return self.client.post_json(
|
return self.client.post_json(
|
||||||
destination=destination,
|
destination=destination,
|
||||||
|
@ -522,7 +522,7 @@ class TransportLayerClient(object):
|
||||||
def get_group_summary(self, destination, group_id, requester_user_id):
|
def get_group_summary(self, destination, group_id, requester_user_id):
|
||||||
"""Get a group summary
|
"""Get a group summary
|
||||||
"""
|
"""
|
||||||
path = _create_path(PREFIX, "/groups/%s/summary", group_id,)
|
path = _create_v1_path("/groups/%s/summary", group_id,)
|
||||||
|
|
||||||
return self.client.get_json(
|
return self.client.get_json(
|
||||||
destination=destination,
|
destination=destination,
|
||||||
|
@ -535,7 +535,7 @@ class TransportLayerClient(object):
|
||||||
def get_rooms_in_group(self, destination, group_id, requester_user_id):
|
def get_rooms_in_group(self, destination, group_id, requester_user_id):
|
||||||
"""Get all rooms in a group
|
"""Get all rooms in a group
|
||||||
"""
|
"""
|
||||||
path = _create_path(PREFIX, "/groups/%s/rooms", group_id,)
|
path = _create_v1_path("/groups/%s/rooms", group_id,)
|
||||||
|
|
||||||
return self.client.get_json(
|
return self.client.get_json(
|
||||||
destination=destination,
|
destination=destination,
|
||||||
|
@ -548,7 +548,7 @@ class TransportLayerClient(object):
|
||||||
content):
|
content):
|
||||||
"""Add a room to a group
|
"""Add a room to a group
|
||||||
"""
|
"""
|
||||||
path = _create_path(PREFIX, "/groups/%s/room/%s", group_id, room_id,)
|
path = _create_v1_path("/groups/%s/room/%s", group_id, room_id,)
|
||||||
|
|
||||||
return self.client.post_json(
|
return self.client.post_json(
|
||||||
destination=destination,
|
destination=destination,
|
||||||
|
@ -562,8 +562,8 @@ class TransportLayerClient(object):
|
||||||
config_key, content):
|
config_key, content):
|
||||||
"""Update room in group
|
"""Update room in group
|
||||||
"""
|
"""
|
||||||
path = _create_path(
|
path = _create_v1_path(
|
||||||
PREFIX, "/groups/%s/room/%s/config/%s",
|
"/groups/%s/room/%s/config/%s",
|
||||||
group_id, room_id, config_key,
|
group_id, room_id, config_key,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -578,7 +578,7 @@ class TransportLayerClient(object):
|
||||||
def remove_room_from_group(self, destination, group_id, requester_user_id, room_id):
|
def remove_room_from_group(self, destination, group_id, requester_user_id, room_id):
|
||||||
"""Remove a room from a group
|
"""Remove a room from a group
|
||||||
"""
|
"""
|
||||||
path = _create_path(PREFIX, "/groups/%s/room/%s", group_id, room_id,)
|
path = _create_v1_path("/groups/%s/room/%s", group_id, room_id,)
|
||||||
|
|
||||||
return self.client.delete_json(
|
return self.client.delete_json(
|
||||||
destination=destination,
|
destination=destination,
|
||||||
|
@ -591,7 +591,7 @@ class TransportLayerClient(object):
|
||||||
def get_users_in_group(self, destination, group_id, requester_user_id):
|
def get_users_in_group(self, destination, group_id, requester_user_id):
|
||||||
"""Get users in a group
|
"""Get users in a group
|
||||||
"""
|
"""
|
||||||
path = _create_path(PREFIX, "/groups/%s/users", group_id,)
|
path = _create_v1_path("/groups/%s/users", group_id,)
|
||||||
|
|
||||||
return self.client.get_json(
|
return self.client.get_json(
|
||||||
destination=destination,
|
destination=destination,
|
||||||
|
@ -604,7 +604,7 @@ class TransportLayerClient(object):
|
||||||
def get_invited_users_in_group(self, destination, group_id, requester_user_id):
|
def get_invited_users_in_group(self, destination, group_id, requester_user_id):
|
||||||
"""Get users that have been invited to a group
|
"""Get users that have been invited to a group
|
||||||
"""
|
"""
|
||||||
path = _create_path(PREFIX, "/groups/%s/invited_users", group_id,)
|
path = _create_v1_path("/groups/%s/invited_users", group_id,)
|
||||||
|
|
||||||
return self.client.get_json(
|
return self.client.get_json(
|
||||||
destination=destination,
|
destination=destination,
|
||||||
|
@ -617,8 +617,8 @@ class TransportLayerClient(object):
|
||||||
def accept_group_invite(self, destination, group_id, user_id, content):
|
def accept_group_invite(self, destination, group_id, user_id, content):
|
||||||
"""Accept a group invite
|
"""Accept a group invite
|
||||||
"""
|
"""
|
||||||
path = _create_path(
|
path = _create_v1_path(
|
||||||
PREFIX, "/groups/%s/users/%s/accept_invite",
|
"/groups/%s/users/%s/accept_invite",
|
||||||
group_id, user_id,
|
group_id, user_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -633,7 +633,7 @@ class TransportLayerClient(object):
|
||||||
def join_group(self, destination, group_id, user_id, content):
|
def join_group(self, destination, group_id, user_id, content):
|
||||||
"""Attempts to join a group
|
"""Attempts to join a group
|
||||||
"""
|
"""
|
||||||
path = _create_path(PREFIX, "/groups/%s/users/%s/join", group_id, user_id)
|
path = _create_v1_path("/groups/%s/users/%s/join", group_id, user_id)
|
||||||
|
|
||||||
return self.client.post_json(
|
return self.client.post_json(
|
||||||
destination=destination,
|
destination=destination,
|
||||||
|
@ -646,7 +646,7 @@ class TransportLayerClient(object):
|
||||||
def invite_to_group(self, destination, group_id, user_id, requester_user_id, content):
|
def invite_to_group(self, destination, group_id, user_id, requester_user_id, content):
|
||||||
"""Invite a user to a group
|
"""Invite a user to a group
|
||||||
"""
|
"""
|
||||||
path = _create_path(PREFIX, "/groups/%s/users/%s/invite", group_id, user_id)
|
path = _create_v1_path("/groups/%s/users/%s/invite", group_id, user_id)
|
||||||
|
|
||||||
return self.client.post_json(
|
return self.client.post_json(
|
||||||
destination=destination,
|
destination=destination,
|
||||||
|
@ -662,7 +662,7 @@ class TransportLayerClient(object):
|
||||||
invited.
|
invited.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
path = _create_path(PREFIX, "/groups/local/%s/users/%s/invite", group_id, user_id)
|
path = _create_v1_path("/groups/local/%s/users/%s/invite", group_id, user_id)
|
||||||
|
|
||||||
return self.client.post_json(
|
return self.client.post_json(
|
||||||
destination=destination,
|
destination=destination,
|
||||||
|
@ -676,7 +676,7 @@ class TransportLayerClient(object):
|
||||||
user_id, content):
|
user_id, content):
|
||||||
"""Remove a user fron a group
|
"""Remove a user fron a group
|
||||||
"""
|
"""
|
||||||
path = _create_path(PREFIX, "/groups/%s/users/%s/remove", group_id, user_id)
|
path = _create_v1_path("/groups/%s/users/%s/remove", group_id, user_id)
|
||||||
|
|
||||||
return self.client.post_json(
|
return self.client.post_json(
|
||||||
destination=destination,
|
destination=destination,
|
||||||
|
@ -693,7 +693,7 @@ class TransportLayerClient(object):
|
||||||
kicked from the group.
|
kicked from the group.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
path = _create_path(PREFIX, "/groups/local/%s/users/%s/remove", group_id, user_id)
|
path = _create_v1_path("/groups/local/%s/users/%s/remove", group_id, user_id)
|
||||||
|
|
||||||
return self.client.post_json(
|
return self.client.post_json(
|
||||||
destination=destination,
|
destination=destination,
|
||||||
|
@ -708,7 +708,7 @@ class TransportLayerClient(object):
|
||||||
the attestations
|
the attestations
|
||||||
"""
|
"""
|
||||||
|
|
||||||
path = _create_path(PREFIX, "/groups/%s/renew_attestation/%s", group_id, user_id)
|
path = _create_v1_path("/groups/%s/renew_attestation/%s", group_id, user_id)
|
||||||
|
|
||||||
return self.client.post_json(
|
return self.client.post_json(
|
||||||
destination=destination,
|
destination=destination,
|
||||||
|
@ -723,12 +723,12 @@ class TransportLayerClient(object):
|
||||||
"""Update a room entry in a group summary
|
"""Update a room entry in a group summary
|
||||||
"""
|
"""
|
||||||
if category_id:
|
if category_id:
|
||||||
path = _create_path(
|
path = _create_v1_path(
|
||||||
PREFIX, "/groups/%s/summary/categories/%s/rooms/%s",
|
"/groups/%s/summary/categories/%s/rooms/%s",
|
||||||
group_id, category_id, room_id,
|
group_id, category_id, room_id,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
path = _create_path(PREFIX, "/groups/%s/summary/rooms/%s", group_id, room_id,)
|
path = _create_v1_path("/groups/%s/summary/rooms/%s", group_id, room_id,)
|
||||||
|
|
||||||
return self.client.post_json(
|
return self.client.post_json(
|
||||||
destination=destination,
|
destination=destination,
|
||||||
|
@ -744,12 +744,12 @@ class TransportLayerClient(object):
|
||||||
"""Delete a room entry in a group summary
|
"""Delete a room entry in a group summary
|
||||||
"""
|
"""
|
||||||
if category_id:
|
if category_id:
|
||||||
path = _create_path(
|
path = _create_v1_path(
|
||||||
PREFIX + "/groups/%s/summary/categories/%s/rooms/%s",
|
"/groups/%s/summary/categories/%s/rooms/%s",
|
||||||
group_id, category_id, room_id,
|
group_id, category_id, room_id,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
path = _create_path(PREFIX, "/groups/%s/summary/rooms/%s", group_id, room_id,)
|
path = _create_v1_path("/groups/%s/summary/rooms/%s", group_id, room_id,)
|
||||||
|
|
||||||
return self.client.delete_json(
|
return self.client.delete_json(
|
||||||
destination=destination,
|
destination=destination,
|
||||||
|
@ -762,7 +762,7 @@ class TransportLayerClient(object):
|
||||||
def get_group_categories(self, destination, group_id, requester_user_id):
|
def get_group_categories(self, destination, group_id, requester_user_id):
|
||||||
"""Get all categories in a group
|
"""Get all categories in a group
|
||||||
"""
|
"""
|
||||||
path = _create_path(PREFIX, "/groups/%s/categories", group_id,)
|
path = _create_v1_path("/groups/%s/categories", group_id,)
|
||||||
|
|
||||||
return self.client.get_json(
|
return self.client.get_json(
|
||||||
destination=destination,
|
destination=destination,
|
||||||
|
@ -775,7 +775,7 @@ class TransportLayerClient(object):
|
||||||
def get_group_category(self, destination, group_id, requester_user_id, category_id):
|
def get_group_category(self, destination, group_id, requester_user_id, category_id):
|
||||||
"""Get category info in a group
|
"""Get category info in a group
|
||||||
"""
|
"""
|
||||||
path = _create_path(PREFIX, "/groups/%s/categories/%s", group_id, category_id,)
|
path = _create_v1_path("/groups/%s/categories/%s", group_id, category_id,)
|
||||||
|
|
||||||
return self.client.get_json(
|
return self.client.get_json(
|
||||||
destination=destination,
|
destination=destination,
|
||||||
|
@ -789,7 +789,7 @@ class TransportLayerClient(object):
|
||||||
content):
|
content):
|
||||||
"""Update a category in a group
|
"""Update a category in a group
|
||||||
"""
|
"""
|
||||||
path = _create_path(PREFIX, "/groups/%s/categories/%s", group_id, category_id,)
|
path = _create_v1_path("/groups/%s/categories/%s", group_id, category_id,)
|
||||||
|
|
||||||
return self.client.post_json(
|
return self.client.post_json(
|
||||||
destination=destination,
|
destination=destination,
|
||||||
|
@ -804,7 +804,7 @@ class TransportLayerClient(object):
|
||||||
category_id):
|
category_id):
|
||||||
"""Delete a category in a group
|
"""Delete a category in a group
|
||||||
"""
|
"""
|
||||||
path = _create_path(PREFIX, "/groups/%s/categories/%s", group_id, category_id,)
|
path = _create_v1_path("/groups/%s/categories/%s", group_id, category_id,)
|
||||||
|
|
||||||
return self.client.delete_json(
|
return self.client.delete_json(
|
||||||
destination=destination,
|
destination=destination,
|
||||||
|
@ -817,7 +817,7 @@ class TransportLayerClient(object):
|
||||||
def get_group_roles(self, destination, group_id, requester_user_id):
|
def get_group_roles(self, destination, group_id, requester_user_id):
|
||||||
"""Get all roles in a group
|
"""Get all roles in a group
|
||||||
"""
|
"""
|
||||||
path = _create_path(PREFIX, "/groups/%s/roles", group_id,)
|
path = _create_v1_path("/groups/%s/roles", group_id,)
|
||||||
|
|
||||||
return self.client.get_json(
|
return self.client.get_json(
|
||||||
destination=destination,
|
destination=destination,
|
||||||
|
@ -830,7 +830,7 @@ class TransportLayerClient(object):
|
||||||
def get_group_role(self, destination, group_id, requester_user_id, role_id):
|
def get_group_role(self, destination, group_id, requester_user_id, role_id):
|
||||||
"""Get a roles info
|
"""Get a roles info
|
||||||
"""
|
"""
|
||||||
path = _create_path(PREFIX, "/groups/%s/roles/%s", group_id, role_id,)
|
path = _create_v1_path("/groups/%s/roles/%s", group_id, role_id,)
|
||||||
|
|
||||||
return self.client.get_json(
|
return self.client.get_json(
|
||||||
destination=destination,
|
destination=destination,
|
||||||
|
@ -844,7 +844,7 @@ class TransportLayerClient(object):
|
||||||
content):
|
content):
|
||||||
"""Update a role in a group
|
"""Update a role in a group
|
||||||
"""
|
"""
|
||||||
path = _create_path(PREFIX, "/groups/%s/roles/%s", group_id, role_id,)
|
path = _create_v1_path("/groups/%s/roles/%s", group_id, role_id,)
|
||||||
|
|
||||||
return self.client.post_json(
|
return self.client.post_json(
|
||||||
destination=destination,
|
destination=destination,
|
||||||
|
@ -858,7 +858,7 @@ class TransportLayerClient(object):
|
||||||
def delete_group_role(self, destination, group_id, requester_user_id, role_id):
|
def delete_group_role(self, destination, group_id, requester_user_id, role_id):
|
||||||
"""Delete a role in a group
|
"""Delete a role in a group
|
||||||
"""
|
"""
|
||||||
path = _create_path(PREFIX, "/groups/%s/roles/%s", group_id, role_id,)
|
path = _create_v1_path("/groups/%s/roles/%s", group_id, role_id,)
|
||||||
|
|
||||||
return self.client.delete_json(
|
return self.client.delete_json(
|
||||||
destination=destination,
|
destination=destination,
|
||||||
|
@ -873,12 +873,12 @@ class TransportLayerClient(object):
|
||||||
"""Update a users entry in a group
|
"""Update a users entry in a group
|
||||||
"""
|
"""
|
||||||
if role_id:
|
if role_id:
|
||||||
path = _create_path(
|
path = _create_v1_path(
|
||||||
PREFIX, "/groups/%s/summary/roles/%s/users/%s",
|
"/groups/%s/summary/roles/%s/users/%s",
|
||||||
group_id, role_id, user_id,
|
group_id, role_id, user_id,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
path = _create_path(PREFIX, "/groups/%s/summary/users/%s", group_id, user_id,)
|
path = _create_v1_path("/groups/%s/summary/users/%s", group_id, user_id,)
|
||||||
|
|
||||||
return self.client.post_json(
|
return self.client.post_json(
|
||||||
destination=destination,
|
destination=destination,
|
||||||
|
@ -893,7 +893,7 @@ class TransportLayerClient(object):
|
||||||
content):
|
content):
|
||||||
"""Sets the join policy for a group
|
"""Sets the join policy for a group
|
||||||
"""
|
"""
|
||||||
path = _create_path(PREFIX, "/groups/%s/settings/m.join_policy", group_id,)
|
path = _create_v1_path("/groups/%s/settings/m.join_policy", group_id,)
|
||||||
|
|
||||||
return self.client.put_json(
|
return self.client.put_json(
|
||||||
destination=destination,
|
destination=destination,
|
||||||
|
@ -909,12 +909,12 @@ class TransportLayerClient(object):
|
||||||
"""Delete a users entry in a group
|
"""Delete a users entry in a group
|
||||||
"""
|
"""
|
||||||
if role_id:
|
if role_id:
|
||||||
path = _create_path(
|
path = _create_v1_path(
|
||||||
PREFIX, "/groups/%s/summary/roles/%s/users/%s",
|
"/groups/%s/summary/roles/%s/users/%s",
|
||||||
group_id, role_id, user_id,
|
group_id, role_id, user_id,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
path = _create_path(PREFIX, "/groups/%s/summary/users/%s", group_id, user_id,)
|
path = _create_v1_path("/groups/%s/summary/users/%s", group_id, user_id,)
|
||||||
|
|
||||||
return self.client.delete_json(
|
return self.client.delete_json(
|
||||||
destination=destination,
|
destination=destination,
|
||||||
|
@ -927,7 +927,7 @@ class TransportLayerClient(object):
|
||||||
"""Get the groups a list of users are publicising
|
"""Get the groups a list of users are publicising
|
||||||
"""
|
"""
|
||||||
|
|
||||||
path = PREFIX + "/get_groups_publicised"
|
path = _create_v1_path("/get_groups_publicised")
|
||||||
|
|
||||||
content = {"user_ids": user_ids}
|
content = {"user_ids": user_ids}
|
||||||
|
|
||||||
|
@ -939,20 +939,22 @@ class TransportLayerClient(object):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def _create_path(prefix, path, *args):
|
def _create_v1_path(path, *args):
|
||||||
"""Creates a path from the prefix, path template and args. Ensures that
|
"""Creates a path against V1 federation API from the path template and
|
||||||
all args are url encoded.
|
args. Ensures that all args are url encoded.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
_create_path(PREFIX, "/event/%s/", event_id)
|
_create_v1_path("/event/%s/", event_id)
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
prefix (str)
|
|
||||||
path (str): String template for the path
|
path (str): String template for the path
|
||||||
args: ([str]): Args to insert into path. Each arg will be url encoded
|
args: ([str]): Args to insert into path. Each arg will be url encoded
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
str
|
str
|
||||||
"""
|
"""
|
||||||
return prefix + path % tuple(urllib.parse.quote(arg, "") for arg in args)
|
return (
|
||||||
|
FEDERATION_V1_PREFIX
|
||||||
|
+ path % tuple(urllib.parse.quote(arg, "") for arg in args)
|
||||||
|
)
|
||||||
|
|
|
@ -22,7 +22,7 @@ from twisted.internet import defer
|
||||||
|
|
||||||
import synapse
|
import synapse
|
||||||
from synapse.api.errors import Codes, FederationDeniedError, SynapseError
|
from synapse.api.errors import Codes, FederationDeniedError, SynapseError
|
||||||
from synapse.api.urls import FEDERATION_PREFIX as PREFIX
|
from synapse.api.urls import FEDERATION_V1_PREFIX
|
||||||
from synapse.http.endpoint import parse_and_validate_server_name
|
from synapse.http.endpoint import parse_and_validate_server_name
|
||||||
from synapse.http.server import JsonResource
|
from synapse.http.server import JsonResource
|
||||||
from synapse.http.servlet import (
|
from synapse.http.servlet import (
|
||||||
|
@ -227,6 +227,8 @@ class BaseFederationServlet(object):
|
||||||
"""
|
"""
|
||||||
REQUIRE_AUTH = True
|
REQUIRE_AUTH = True
|
||||||
|
|
||||||
|
PREFIX = FEDERATION_V1_PREFIX # Allows specifying the API version
|
||||||
|
|
||||||
def __init__(self, handler, authenticator, ratelimiter, server_name):
|
def __init__(self, handler, authenticator, ratelimiter, server_name):
|
||||||
self.handler = handler
|
self.handler = handler
|
||||||
self.authenticator = authenticator
|
self.authenticator = authenticator
|
||||||
|
@ -286,7 +288,7 @@ class BaseFederationServlet(object):
|
||||||
return new_func
|
return new_func
|
||||||
|
|
||||||
def register(self, server):
|
def register(self, server):
|
||||||
pattern = re.compile("^" + PREFIX + self.PATH + "$")
|
pattern = re.compile("^" + self.PREFIX + self.PATH + "$")
|
||||||
|
|
||||||
for method in ("GET", "PUT", "POST"):
|
for method in ("GET", "PUT", "POST"):
|
||||||
code = getattr(self, "on_%s" % (method), None)
|
code = getattr(self, "on_%s" % (method), None)
|
||||||
|
|
Loading…
Reference in a new issue