Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1056 from matrix-org/kegan/appservice-url-is-opti…
Browse files Browse the repository at this point in the history
…onal

Allow application services to have an optional 'url'
  • Loading branch information
kegsay authored Aug 30, 2016
2 parents c7f665d + c882783 commit 998666b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
12 changes: 12 additions & 0 deletions synapse/appservice/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ def __init__(self, hs):

@defer.inlineCallbacks
def query_user(self, service, user_id):
if service.url is None:
defer.returnValue(False)
uri = service.url + ("/users/%s" % urllib.quote(user_id))
response = None
try:
Expand All @@ -86,6 +88,8 @@ def query_user(self, service, user_id):

@defer.inlineCallbacks
def query_alias(self, service, alias):
if service.url is None:
defer.returnValue(False)
uri = service.url + ("/rooms/%s" % urllib.quote(alias))
response = None
try:
Expand Down Expand Up @@ -113,6 +117,8 @@ def query_3pe(self, service, kind, protocol, fields):
raise ValueError(
"Unrecognised 'kind' argument %r to query_3pe()", kind
)
if service.url is None:
defer.returnValue([])

uri = "%s%s/thirdparty/%s/%s" % (
service.url,
Expand Down Expand Up @@ -145,6 +151,9 @@ def query_3pe(self, service, kind, protocol, fields):
defer.returnValue([])

def get_3pe_protocol(self, service, protocol):
if service.url is None:
defer.returnValue({})

@defer.inlineCallbacks
def _get():
uri = "%s%s/thirdparty/protocol/%s" % (
Expand All @@ -166,6 +175,9 @@ def _get():

@defer.inlineCallbacks
def push_bulk(self, service, events, txn_id=None):
if service.url is None:
defer.returnValue(True)

events = self._serialize(events)

if txn_id is None:
Expand Down
17 changes: 16 additions & 1 deletion synapse/config/appservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,22 @@ def load_appservices(hostname, config_files):

def _load_appservice(hostname, as_info, config_filename):
required_string_fields = [
"id", "url", "as_token", "hs_token", "sender_localpart"
"id", "as_token", "hs_token", "sender_localpart"
]
for field in required_string_fields:
if not isinstance(as_info.get(field), basestring):
raise KeyError("Required string field: '%s' (%s)" % (
field, config_filename,
))

# 'url' must either be a string or explicitly null, not missing
# to avoid accidentally turning off push for ASes.
if (not isinstance(as_info.get("url"), basestring) and
as_info.get("url", "") is not None):
raise KeyError(
"Required string field or explicit null: 'url' (%s)" % (config_filename,)
)

localpart = as_info["sender_localpart"]
if urllib.quote(localpart) != localpart:
raise ValueError(
Expand Down Expand Up @@ -132,6 +140,13 @@ def _load_appservice(hostname, as_info, config_filename):
for p in protocols:
if not isinstance(p, str):
raise KeyError("Bad value for 'protocols' item")

if as_info["url"] is None:
logger.info(
"(%s) Explicitly empty 'url' provided. This application service"
" will not receive events or queries.",
config_filename,
)
return ApplicationService(
token=as_info["as_token"],
url=as_info["url"],
Expand Down

0 comments on commit 998666b

Please sign in to comment.