mirror of
https://mau.dev/maunium/synapse.git
synced 2024-10-01 01:36:05 -04:00
Fix pep8 warnings
This commit is contained in:
parent
b4b492824e
commit
7d709542ca
@ -12,4 +12,3 @@
|
|||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ class SynapseError(CodeMessageException):
|
|||||||
"""Constructs a synapse error.
|
"""Constructs a synapse error.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
code (int): The integer error code (typically an HTTP response code)
|
code (int): The integer error code (an HTTP response code)
|
||||||
msg (str): The human-readable error message.
|
msg (str): The human-readable error message.
|
||||||
err (str): The error code e.g 'M_FORBIDDEN'
|
err (str): The error code e.g 'M_FORBIDDEN'
|
||||||
"""
|
"""
|
||||||
@ -67,6 +67,7 @@ class SynapseError(CodeMessageException):
|
|||||||
self.errcode,
|
self.errcode,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class RoomError(SynapseError):
|
class RoomError(SynapseError):
|
||||||
"""An error raised when a room event fails."""
|
"""An error raised when a room event fails."""
|
||||||
pass
|
pass
|
||||||
@ -117,6 +118,7 @@ class InvalidCaptchaError(SynapseError):
|
|||||||
error_url=self.error_url,
|
error_url=self.error_url,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class LimitExceededError(SynapseError):
|
class LimitExceededError(SynapseError):
|
||||||
"""A client has sent too many requests and is being throttled.
|
"""A client has sent too many requests and is being throttled.
|
||||||
"""
|
"""
|
||||||
|
@ -12,4 +12,3 @@
|
|||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
@ -123,11 +123,18 @@ class Config(object):
|
|||||||
# style mode markers into the file, to hint to people that
|
# style mode markers into the file, to hint to people that
|
||||||
# this is a YAML file.
|
# this is a YAML file.
|
||||||
yaml.dump(config, config_file, default_flow_style=False)
|
yaml.dump(config, config_file, default_flow_style=False)
|
||||||
print "A config file has been generated in %s for server name '%s') with corresponding SSL keys and self-signed certificates. Please review this file and customise it to your needs." % (config_args.config_path, config['server_name'])
|
print (
|
||||||
print "If this server name is incorrect, you will need to regenerate the SSL certificates"
|
"A config file has been generated in %s for server name"
|
||||||
|
" '%s' with corresponding SSL keys and self-signed"
|
||||||
|
" certificates. Please review this file and customise it to"
|
||||||
|
" your needs."
|
||||||
|
) % (
|
||||||
|
config_args.config_path, config['server_name']
|
||||||
|
)
|
||||||
|
print (
|
||||||
|
"If this server name is incorrect, you will need to regenerate"
|
||||||
|
" the SSL certificates"
|
||||||
|
)
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
return cls(args)
|
return cls(args)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
from ._base import Config
|
from ._base import Config
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
|
||||||
class DatabaseConfig(Config):
|
class DatabaseConfig(Config):
|
||||||
def __init__(self, args):
|
def __init__(self, args):
|
||||||
super(DatabaseConfig, self).__init__(args)
|
super(DatabaseConfig, self).__init__(args)
|
||||||
@ -34,4 +35,3 @@ class DatabaseConfig(Config):
|
|||||||
def generate_config(cls, args, config_dir_path):
|
def generate_config(cls, args, config_dir_path):
|
||||||
super(DatabaseConfig, cls).generate_config(args, config_dir_path)
|
super(DatabaseConfig, cls).generate_config(args, config_dir_path)
|
||||||
args.database_path = os.path.abspath(args.database_path)
|
args.database_path = os.path.abspath(args.database_path)
|
||||||
|
|
||||||
|
@ -35,5 +35,8 @@ class EmailConfig(Config):
|
|||||||
email_group.add_argument(
|
email_group.add_argument(
|
||||||
"--email-smtp-server",
|
"--email-smtp-server",
|
||||||
default="",
|
default="",
|
||||||
help="The SMTP server to send emails from (e.g. for password resets)."
|
help=(
|
||||||
|
"The SMTP server to send emails from (e.g. for password"
|
||||||
|
" resets)."
|
||||||
|
)
|
||||||
)
|
)
|
@ -19,6 +19,7 @@ from twisted.python.log import PythonLoggingObserver
|
|||||||
import logging
|
import logging
|
||||||
import logging.config
|
import logging.config
|
||||||
|
|
||||||
|
|
||||||
class LoggingConfig(Config):
|
class LoggingConfig(Config):
|
||||||
def __init__(self, args):
|
def __init__(self, args):
|
||||||
super(LoggingConfig, self).__init__(args)
|
super(LoggingConfig, self).__init__(args)
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
from ._base import Config
|
from ._base import Config
|
||||||
|
|
||||||
|
|
||||||
class RatelimitConfig(Config):
|
class RatelimitConfig(Config):
|
||||||
|
|
||||||
def __init__(self, args):
|
def __init__(self, args):
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
|
|
||||||
from ._base import Config
|
from ._base import Config
|
||||||
|
|
||||||
|
|
||||||
class ContentRepositoryConfig(Config):
|
class ContentRepositoryConfig(Config):
|
||||||
def __init__(self, args):
|
def __init__(self, args):
|
||||||
super(ContentRepositoryConfig, self).__init__(args)
|
super(ContentRepositoryConfig, self).__init__(args)
|
||||||
|
@ -33,7 +33,10 @@ class VoipConfig(Config):
|
|||||||
)
|
)
|
||||||
group.add_argument(
|
group.add_argument(
|
||||||
"--turn-shared-secret", type=str, default=None,
|
"--turn-shared-secret", type=str, default=None,
|
||||||
help="The shared secret used to compute passwords for the TURN server"
|
help=(
|
||||||
|
"The shared secret used to compute passwords for the TURN"
|
||||||
|
" server"
|
||||||
|
)
|
||||||
)
|
)
|
||||||
group.add_argument(
|
group.add_argument(
|
||||||
"--turn-user-lifetime", type=int, default=(1000 * 60 * 60),
|
"--turn-user-lifetime", type=int, default=(1000 * 60 * 60),
|
||||||
|
@ -12,4 +12,3 @@
|
|||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@ import logging
|
|||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class ServerContextFactory(ssl.ContextFactory):
|
class ServerContextFactory(ssl.ContextFactory):
|
||||||
"""Factory for PyOpenSSL SSL contexts that are used to handle incoming
|
"""Factory for PyOpenSSL SSL contexts that are used to handle incoming
|
||||||
connections and to make connections to remote servers."""
|
connections and to make connections to remote servers."""
|
||||||
@ -43,4 +44,3 @@ class ServerContextFactory(ssl.ContextFactory):
|
|||||||
|
|
||||||
def getContext(self):
|
def getContext(self):
|
||||||
return self._context
|
return self._context
|
||||||
|
|
||||||
|
@ -98,4 +98,3 @@ class SynapseKeyClientProtocol(HTTPClient):
|
|||||||
|
|
||||||
class SynapseKeyClientFactory(Factory):
|
class SynapseKeyClientFactory(Factory):
|
||||||
protocol = SynapseKeyClientProtocol
|
protocol = SynapseKeyClientProtocol
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ class LoginHandler(BaseHandler):
|
|||||||
# pull out the hash for this user if they exist
|
# pull out the hash for this user if they exist
|
||||||
user_info = yield self.store.get_user_by_id(user_id=user)
|
user_info = yield self.store.get_user_by_id(user_id=user)
|
||||||
if not user_info:
|
if not user_info:
|
||||||
logger.warn("Attempted to login as %s but they do not exist.", user)
|
logger.warn("Attempted to login as %s but they do not exist", user)
|
||||||
raise LoginError(403, "", errcode=Codes.FORBIDDEN)
|
raise LoginError(403, "", errcode=Codes.FORBIDDEN)
|
||||||
|
|
||||||
stored_hash = user_info[0]["password_hash"]
|
stored_hash = user_info[0]["password_hash"]
|
||||||
|
@ -76,9 +76,7 @@ class PresenceHandler(BaseHandler):
|
|||||||
"stopped_user_eventstream", self.stopped_user_eventstream
|
"stopped_user_eventstream", self.stopped_user_eventstream
|
||||||
)
|
)
|
||||||
|
|
||||||
distributor.observe("user_joined_room",
|
distributor.observe("user_joined_room", self.user_joined_room)
|
||||||
self.user_joined_room
|
|
||||||
)
|
|
||||||
|
|
||||||
distributor.declare("collect_presencelike_data")
|
distributor.declare("collect_presencelike_data")
|
||||||
|
|
||||||
@ -156,14 +154,12 @@ class PresenceHandler(BaseHandler):
|
|||||||
defer.returnValue(True)
|
defer.returnValue(True)
|
||||||
|
|
||||||
if (yield self.store.user_rooms_intersect(
|
if (yield self.store.user_rooms_intersect(
|
||||||
[u.to_string() for u in observer_user, observed_user]
|
[u.to_string() for u in observer_user, observed_user])):
|
||||||
)):
|
|
||||||
defer.returnValue(True)
|
defer.returnValue(True)
|
||||||
|
|
||||||
if (yield self.store.is_presence_visible(
|
if (yield self.store.is_presence_visible(
|
||||||
observed_localpart=observed_user.localpart,
|
observed_localpart=observed_user.localpart,
|
||||||
observer_userid=observer_user.to_string(),
|
observer_userid=observer_user.to_string())):
|
||||||
)):
|
|
||||||
defer.returnValue(True)
|
defer.returnValue(True)
|
||||||
|
|
||||||
defer.returnValue(False)
|
defer.returnValue(False)
|
||||||
@ -171,7 +167,8 @@ class PresenceHandler(BaseHandler):
|
|||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def get_state(self, target_user, auth_user):
|
def get_state(self, target_user, auth_user):
|
||||||
if target_user.is_mine:
|
if target_user.is_mine:
|
||||||
visible = yield self.is_presence_visible(observer_user=auth_user,
|
visible = yield self.is_presence_visible(
|
||||||
|
observer_user=auth_user,
|
||||||
observed_user=target_user
|
observed_user=target_user
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -219,9 +216,9 @@ class PresenceHandler(BaseHandler):
|
|||||||
)
|
)
|
||||||
|
|
||||||
if state["presence"] not in self.STATE_LEVELS:
|
if state["presence"] not in self.STATE_LEVELS:
|
||||||
raise SynapseError(400, "'%s' is not a valid presence state" %
|
raise SynapseError(400, "'%s' is not a valid presence state" % (
|
||||||
state["presence"]
|
state["presence"],
|
||||||
)
|
))
|
||||||
|
|
||||||
logger.debug("Updating presence state of %s to %s",
|
logger.debug("Updating presence state of %s to %s",
|
||||||
target_user.localpart, state["presence"])
|
target_user.localpart, state["presence"])
|
||||||
@ -649,8 +646,9 @@ class PresenceHandler(BaseHandler):
|
|||||||
del state["user_id"]
|
del state["user_id"]
|
||||||
|
|
||||||
if "presence" not in state:
|
if "presence" not in state:
|
||||||
logger.warning("Received a presence 'push' EDU from %s without"
|
logger.warning(
|
||||||
+ " a 'presence' key", origin
|
"Received a presence 'push' EDU from %s without a"
|
||||||
|
" 'presence' key", origin
|
||||||
)
|
)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@ -765,8 +763,7 @@ class PresenceEventSource(object):
|
|||||||
presence = self.hs.get_handlers().presence_handler
|
presence = self.hs.get_handlers().presence_handler
|
||||||
|
|
||||||
if (yield presence.store.user_rooms_intersect(
|
if (yield presence.store.user_rooms_intersect(
|
||||||
[u.to_string() for u in observer_user, observed_user]
|
[u.to_string() for u in observer_user, observed_user])):
|
||||||
)):
|
|
||||||
defer.returnValue(True)
|
defer.returnValue(True)
|
||||||
|
|
||||||
if observed_user.is_mine:
|
if observed_user.is_mine:
|
||||||
|
@ -64,9 +64,11 @@ class RegistrationHandler(BaseHandler):
|
|||||||
user_id = user.to_string()
|
user_id = user.to_string()
|
||||||
|
|
||||||
token = self._generate_token(user_id)
|
token = self._generate_token(user_id)
|
||||||
yield self.store.register(user_id=user_id,
|
yield self.store.register(
|
||||||
|
user_id=user_id,
|
||||||
token=token,
|
token=token,
|
||||||
password_hash=password_hash)
|
password_hash=password_hash
|
||||||
|
)
|
||||||
|
|
||||||
self.distributor.fire("registered_user", user)
|
self.distributor.fire("registered_user", user)
|
||||||
else:
|
else:
|
||||||
@ -181,8 +183,11 @@ class RegistrationHandler(BaseHandler):
|
|||||||
data = yield httpCli.post_urlencoded_get_json(
|
data = yield httpCli.post_urlencoded_get_json(
|
||||||
creds['idServer'],
|
creds['idServer'],
|
||||||
"/_matrix/identity/api/v1/3pid/bind",
|
"/_matrix/identity/api/v1/3pid/bind",
|
||||||
{'sid': creds['sid'], 'clientSecret': creds['clientSecret'],
|
{
|
||||||
'mxid': mxid}
|
'sid': creds['sid'],
|
||||||
|
'clientSecret': creds['clientSecret'],
|
||||||
|
'mxid': mxid,
|
||||||
|
}
|
||||||
)
|
)
|
||||||
defer.returnValue(data)
|
defer.returnValue(data)
|
||||||
|
|
||||||
@ -223,5 +228,3 @@ class RegistrationHandler(BaseHandler):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
defer.returnValue(data)
|
defer.returnValue(data)
|
||||||
|
|
||||||
|
|
||||||
|
@ -96,9 +96,10 @@ class TypingNotificationHandler(BaseHandler):
|
|||||||
remotedomains = set()
|
remotedomains = set()
|
||||||
|
|
||||||
rm_handler = self.homeserver.get_handlers().room_member_handler
|
rm_handler = self.homeserver.get_handlers().room_member_handler
|
||||||
yield rm_handler.fetch_room_distributions_into(room_id,
|
yield rm_handler.fetch_room_distributions_into(
|
||||||
localusers=localusers, remotedomains=remotedomains,
|
room_id, localusers=localusers, remotedomains=remotedomains,
|
||||||
ignore_user=user)
|
ignore_user=user
|
||||||
|
)
|
||||||
|
|
||||||
for u in localusers:
|
for u in localusers:
|
||||||
self.push_update_to_clients(
|
self.push_update_to_clients(
|
||||||
@ -130,8 +131,9 @@ class TypingNotificationHandler(BaseHandler):
|
|||||||
localusers = set()
|
localusers = set()
|
||||||
|
|
||||||
rm_handler = self.homeserver.get_handlers().room_member_handler
|
rm_handler = self.homeserver.get_handlers().room_member_handler
|
||||||
yield rm_handler.fetch_room_distributions_into(room_id,
|
yield rm_handler.fetch_room_distributions_into(
|
||||||
localusers=localusers)
|
room_id, localusers=localusers
|
||||||
|
)
|
||||||
|
|
||||||
for u in localusers:
|
for u in localusers:
|
||||||
self.push_update_to_clients(
|
self.push_update_to_clients(
|
||||||
|
@ -12,4 +12,3 @@
|
|||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
@ -16,7 +16,9 @@
|
|||||||
|
|
||||||
from twisted.internet import defer, reactor
|
from twisted.internet import defer, reactor
|
||||||
from twisted.internet.error import DNSLookupError
|
from twisted.internet.error import DNSLookupError
|
||||||
from twisted.web.client import _AgentBase, _URI, readBody, FileBodyProducer, PartialDownloadError
|
from twisted.web.client import (
|
||||||
|
_AgentBase, _URI, readBody, FileBodyProducer, PartialDownloadError
|
||||||
|
)
|
||||||
from twisted.web.http_headers import Headers
|
from twisted.web.http_headers import Headers
|
||||||
|
|
||||||
from synapse.http.endpoint import matrix_endpoint
|
from synapse.http.endpoint import matrix_endpoint
|
||||||
@ -97,7 +99,7 @@ class BaseHttpClient(object):
|
|||||||
|
|
||||||
retries_left = 5
|
retries_left = 5
|
||||||
|
|
||||||
endpoint = self._getEndpoint(reactor, destination);
|
endpoint = self._getEndpoint(reactor, destination)
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
|
||||||
@ -276,7 +278,6 @@ class MatrixHttpClient(BaseHttpClient):
|
|||||||
|
|
||||||
defer.returnValue(json.loads(body))
|
defer.returnValue(json.loads(body))
|
||||||
|
|
||||||
|
|
||||||
def _getEndpoint(self, reactor, destination):
|
def _getEndpoint(self, reactor, destination):
|
||||||
return matrix_endpoint(
|
return matrix_endpoint(
|
||||||
reactor, destination, timeout=10,
|
reactor, destination, timeout=10,
|
||||||
@ -351,6 +352,7 @@ class IdentityServerHttpClient(BaseHttpClient):
|
|||||||
|
|
||||||
defer.returnValue(json.loads(body))
|
defer.returnValue(json.loads(body))
|
||||||
|
|
||||||
|
|
||||||
class CaptchaServerHttpClient(MatrixHttpClient):
|
class CaptchaServerHttpClient(MatrixHttpClient):
|
||||||
"""Separate HTTP client for talking to google's captcha servers"""
|
"""Separate HTTP client for talking to google's captcha servers"""
|
||||||
|
|
||||||
@ -384,6 +386,7 @@ class CaptchaServerHttpClient(MatrixHttpClient):
|
|||||||
else:
|
else:
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
|
|
||||||
def _print_ex(e):
|
def _print_ex(e):
|
||||||
if hasattr(e, "reasons") and e.reasons:
|
if hasattr(e, "reasons") and e.reasons:
|
||||||
for ex in e.reasons:
|
for ex in e.reasons:
|
||||||
|
@ -38,8 +38,8 @@ class ContentRepoResource(resource.Resource):
|
|||||||
|
|
||||||
Uploads are POSTed to wherever this Resource is linked to. This resource
|
Uploads are POSTed to wherever this Resource is linked to. This resource
|
||||||
returns a "content token" which can be used to GET this content again. The
|
returns a "content token" which can be used to GET this content again. The
|
||||||
token is typically a path, but it may not be. Tokens can expire, be one-time
|
token is typically a path, but it may not be. Tokens can expire, be
|
||||||
uses, etc.
|
one-time uses, etc.
|
||||||
|
|
||||||
In this case, the token is a path to the file and contains 3 interesting
|
In this case, the token is a path to the file and contains 3 interesting
|
||||||
sections:
|
sections:
|
||||||
@ -175,10 +175,9 @@ class ContentRepoResource(resource.Resource):
|
|||||||
with open(fname, "wb") as f:
|
with open(fname, "wb") as f:
|
||||||
f.write(request.content.read())
|
f.write(request.content.read())
|
||||||
|
|
||||||
|
|
||||||
# FIXME (erikj): These should use constants.
|
# FIXME (erikj): These should use constants.
|
||||||
file_name = os.path.basename(fname)
|
file_name = os.path.basename(fname)
|
||||||
# FIXME: we can't assume what the public mounted path of the repo is
|
# FIXME: we can't assume what the repo's public mounted path is
|
||||||
# ...plus self-signed SSL won't work to remote clients anyway
|
# ...plus self-signed SSL won't work to remote clients anyway
|
||||||
# ...and we can't assume that it's SSL anyway, as we might want to
|
# ...and we can't assume that it's SSL anyway, as we might want to
|
||||||
# server it via the non-SSL listener...
|
# server it via the non-SSL listener...
|
||||||
@ -201,6 +200,3 @@ class ContentRepoResource(resource.Resource):
|
|||||||
500,
|
500,
|
||||||
json.dumps({"error": "Internal server error"}),
|
json.dumps({"error": "Internal server error"}),
|
||||||
send_cors=True)
|
send_cors=True)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -167,7 +167,8 @@ class Notifier(object):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def eb(failure):
|
def eb(failure):
|
||||||
logger.error("Failed to notify listener",
|
logger.error(
|
||||||
|
"Failed to notify listener",
|
||||||
exc_info=(
|
exc_info=(
|
||||||
failure.type,
|
failure.type,
|
||||||
failure.value,
|
failure.value,
|
||||||
|
@ -60,40 +60,45 @@ class RegisterRestServlet(RestServlet):
|
|||||||
|
|
||||||
def on_GET(self, request):
|
def on_GET(self, request):
|
||||||
if self.hs.config.enable_registration_captcha:
|
if self.hs.config.enable_registration_captcha:
|
||||||
return (200, {
|
return (
|
||||||
"flows": [
|
200,
|
||||||
|
{"flows": [
|
||||||
{
|
{
|
||||||
"type": LoginType.RECAPTCHA,
|
"type": LoginType.RECAPTCHA,
|
||||||
"stages": ([LoginType.RECAPTCHA,
|
"stages": [
|
||||||
|
LoginType.RECAPTCHA,
|
||||||
LoginType.EMAIL_IDENTITY,
|
LoginType.EMAIL_IDENTITY,
|
||||||
LoginType.PASSWORD])
|
LoginType.PASSWORD
|
||||||
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": LoginType.RECAPTCHA,
|
"type": LoginType.RECAPTCHA,
|
||||||
"stages": [LoginType.RECAPTCHA, LoginType.PASSWORD]
|
"stages": [LoginType.RECAPTCHA, LoginType.PASSWORD]
|
||||||
}
|
}
|
||||||
]
|
]}
|
||||||
})
|
)
|
||||||
else:
|
else:
|
||||||
return (200, {
|
return (
|
||||||
"flows": [
|
200,
|
||||||
|
{"flows": [
|
||||||
{
|
{
|
||||||
"type": LoginType.EMAIL_IDENTITY,
|
"type": LoginType.EMAIL_IDENTITY,
|
||||||
"stages": ([LoginType.EMAIL_IDENTITY,
|
"stages": [
|
||||||
LoginType.PASSWORD])
|
LoginType.EMAIL_IDENTITY, LoginType.PASSWORD
|
||||||
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": LoginType.PASSWORD
|
"type": LoginType.PASSWORD
|
||||||
}
|
}
|
||||||
]
|
]}
|
||||||
})
|
)
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def on_POST(self, request):
|
def on_POST(self, request):
|
||||||
register_json = _parse_json(request)
|
register_json = _parse_json(request)
|
||||||
|
|
||||||
session = (register_json["session"] if "session" in register_json
|
session = (register_json["session"]
|
||||||
else None)
|
if "session" in register_json else None)
|
||||||
login_type = None
|
login_type = None
|
||||||
if "type" not in register_json:
|
if "type" not in register_json:
|
||||||
raise SynapseError(400, "Missing 'type' key.")
|
raise SynapseError(400, "Missing 'type' key.")
|
||||||
@ -122,7 +127,9 @@ class RegisterRestServlet(RestServlet):
|
|||||||
defer.returnValue((200, response))
|
defer.returnValue((200, response))
|
||||||
except KeyError as e:
|
except KeyError as e:
|
||||||
logger.exception(e)
|
logger.exception(e)
|
||||||
raise SynapseError(400, "Missing JSON keys for login type %s." % login_type)
|
raise SynapseError(400, "Missing JSON keys for login type %s." % (
|
||||||
|
login_type,
|
||||||
|
))
|
||||||
|
|
||||||
def on_OPTIONS(self, request):
|
def on_OPTIONS(self, request):
|
||||||
return (200, {})
|
return (200, {})
|
||||||
@ -183,8 +190,10 @@ class RegisterRestServlet(RestServlet):
|
|||||||
session["user"] = register_json["user"]
|
session["user"] = register_json["user"]
|
||||||
defer.returnValue(None)
|
defer.returnValue(None)
|
||||||
else:
|
else:
|
||||||
raise SynapseError(400, "Captcha bypass HMAC incorrect",
|
raise SynapseError(
|
||||||
errcode=Codes.CAPTCHA_NEEDED)
|
400, "Captcha bypass HMAC incorrect",
|
||||||
|
errcode=Codes.CAPTCHA_NEEDED
|
||||||
|
)
|
||||||
|
|
||||||
challenge = None
|
challenge = None
|
||||||
user_response = None
|
user_response = None
|
||||||
@ -230,12 +239,15 @@ class RegisterRestServlet(RestServlet):
|
|||||||
|
|
||||||
if ("user" in session and "user" in register_json and
|
if ("user" in session and "user" in register_json and
|
||||||
session["user"] != register_json["user"]):
|
session["user"] != register_json["user"]):
|
||||||
raise SynapseError(400, "Cannot change user ID during registration")
|
raise SynapseError(
|
||||||
|
400, "Cannot change user ID during registration"
|
||||||
|
)
|
||||||
|
|
||||||
password = register_json["password"].encode("utf-8")
|
password = register_json["password"].encode("utf-8")
|
||||||
desired_user_id = (register_json["user"].encode("utf-8") if "user"
|
desired_user_id = (register_json["user"].encode("utf-8")
|
||||||
in register_json else None)
|
if "user" in register_json else None)
|
||||||
if desired_user_id and urllib.quote(desired_user_id) != desired_user_id:
|
if (desired_user_id
|
||||||
|
and urllib.quote(desired_user_id) != desired_user_id):
|
||||||
raise SynapseError(
|
raise SynapseError(
|
||||||
400,
|
400,
|
||||||
"User ID must only contain characters which do not " +
|
"User ID must only contain characters which do not " +
|
||||||
|
@ -48,7 +48,9 @@ class RoomCreateRestServlet(RestServlet):
|
|||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def on_PUT(self, request, txn_id):
|
def on_PUT(self, request, txn_id):
|
||||||
try:
|
try:
|
||||||
defer.returnValue(self.txns.get_client_transaction(request, txn_id))
|
defer.returnValue(
|
||||||
|
self.txns.get_client_transaction(request, txn_id)
|
||||||
|
)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -98,7 +100,7 @@ class RoomStateEventRestServlet(RestServlet):
|
|||||||
no_state_key = "/rooms/(?P<room_id>[^/]*)/state/(?P<event_type>[^/]*)$"
|
no_state_key = "/rooms/(?P<room_id>[^/]*)/state/(?P<event_type>[^/]*)$"
|
||||||
|
|
||||||
# /room/$roomid/state/$eventtype/$statekey
|
# /room/$roomid/state/$eventtype/$statekey
|
||||||
state_key = ("/rooms/(?P<room_id>[^/]*)/state/" +
|
state_key = ("/rooms/(?P<room_id>[^/]*)/state/"
|
||||||
"(?P<event_type>[^/]*)/(?P<state_key>[^/]*)$")
|
"(?P<event_type>[^/]*)/(?P<state_key>[^/]*)$")
|
||||||
|
|
||||||
http_server.register_path("GET",
|
http_server.register_path("GET",
|
||||||
@ -133,7 +135,9 @@ class RoomStateEventRestServlet(RestServlet):
|
|||||||
)
|
)
|
||||||
|
|
||||||
if not data:
|
if not data:
|
||||||
raise SynapseError(404, "Event not found.", errcode=Codes.NOT_FOUND)
|
raise SynapseError(
|
||||||
|
404, "Event not found.", errcode=Codes.NOT_FOUND
|
||||||
|
)
|
||||||
defer.returnValue((200, data[0].get_dict()["content"]))
|
defer.returnValue((200, data[0].get_dict()["content"]))
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
@ -195,7 +199,9 @@ class RoomSendEventRestServlet(RestServlet):
|
|||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def on_PUT(self, request, room_id, event_type, txn_id):
|
def on_PUT(self, request, room_id, event_type, txn_id):
|
||||||
try:
|
try:
|
||||||
defer.returnValue(self.txns.get_client_transaction(request, txn_id))
|
defer.returnValue(
|
||||||
|
self.txns.get_client_transaction(request, txn_id)
|
||||||
|
)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -254,7 +260,9 @@ class JoinRoomAliasServlet(RestServlet):
|
|||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def on_PUT(self, request, room_identifier, txn_id):
|
def on_PUT(self, request, room_identifier, txn_id):
|
||||||
try:
|
try:
|
||||||
defer.returnValue(self.txns.get_client_transaction(request, txn_id))
|
defer.returnValue(
|
||||||
|
self.txns.get_client_transaction(request, txn_id)
|
||||||
|
)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -293,7 +301,8 @@ class RoomMemberListRestServlet(RestServlet):
|
|||||||
target_user = self.hs.parse_userid(event["user_id"])
|
target_user = self.hs.parse_userid(event["user_id"])
|
||||||
# Presence is an optional cache; don't fail if we can't fetch it
|
# Presence is an optional cache; don't fail if we can't fetch it
|
||||||
try:
|
try:
|
||||||
presence_state = yield self.handlers.presence_handler.get_state(
|
presence_handler = self.handlers.presence_handler
|
||||||
|
presence_state = yield presence_handler.get_state(
|
||||||
target_user=target_user, auth_user=user
|
target_user=target_user, auth_user=user
|
||||||
)
|
)
|
||||||
event["content"].update(presence_state)
|
event["content"].update(presence_state)
|
||||||
@ -359,11 +368,11 @@ class RoomInitialSyncRestServlet(RestServlet):
|
|||||||
# { state event } , { state event }
|
# { state event } , { state event }
|
||||||
# ]
|
# ]
|
||||||
# }
|
# }
|
||||||
# Probably worth keeping the keys room_id and membership for parity with
|
# Probably worth keeping the keys room_id and membership for parity
|
||||||
# /initialSync even though they must be joined to sync this and know the
|
# with /initialSync even though they must be joined to sync this and
|
||||||
# room ID, so clients can reuse the same code (room_id and membership
|
# know the room ID, so clients can reuse the same code (room_id and
|
||||||
# are MANDATORY for /initialSync, so the code will expect it to be
|
# membership are MANDATORY for /initialSync, so the code will expect
|
||||||
# there)
|
# it to be there)
|
||||||
defer.returnValue((200, {}))
|
defer.returnValue((200, {}))
|
||||||
|
|
||||||
|
|
||||||
@ -388,7 +397,7 @@ class RoomMembershipRestServlet(RestServlet):
|
|||||||
|
|
||||||
def register(self, http_server):
|
def register(self, http_server):
|
||||||
# /rooms/$roomid/[invite|join|leave]
|
# /rooms/$roomid/[invite|join|leave]
|
||||||
PATTERN = ("/rooms/(?P<room_id>[^/]*)/" +
|
PATTERN = ("/rooms/(?P<room_id>[^/]*)/"
|
||||||
"(?P<membership_action>join|invite|leave|ban|kick)")
|
"(?P<membership_action>join|invite|leave|ban|kick)")
|
||||||
register_txn_path(self, PATTERN, http_server)
|
register_txn_path(self, PATTERN, http_server)
|
||||||
|
|
||||||
@ -422,7 +431,9 @@ class RoomMembershipRestServlet(RestServlet):
|
|||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def on_PUT(self, request, room_id, membership_action, txn_id):
|
def on_PUT(self, request, room_id, membership_action, txn_id):
|
||||||
try:
|
try:
|
||||||
defer.returnValue(self.txns.get_client_transaction(request, txn_id))
|
defer.returnValue(
|
||||||
|
self.txns.get_client_transaction(request, txn_id)
|
||||||
|
)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -431,6 +442,7 @@ class RoomMembershipRestServlet(RestServlet):
|
|||||||
self.txns.store_client_transaction(request, txn_id, response)
|
self.txns.store_client_transaction(request, txn_id, response)
|
||||||
defer.returnValue(response)
|
defer.returnValue(response)
|
||||||
|
|
||||||
|
|
||||||
class RoomRedactEventRestServlet(RestServlet):
|
class RoomRedactEventRestServlet(RestServlet):
|
||||||
def register(self, http_server):
|
def register(self, http_server):
|
||||||
PATTERN = ("/rooms/(?P<room_id>[^/]*)/redact/(?P<event_id>[^/]*)")
|
PATTERN = ("/rooms/(?P<room_id>[^/]*)/redact/(?P<event_id>[^/]*)")
|
||||||
@ -457,7 +469,9 @@ class RoomRedactEventRestServlet(RestServlet):
|
|||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def on_PUT(self, request, room_id, event_id, txn_id):
|
def on_PUT(self, request, room_id, event_id, txn_id):
|
||||||
try:
|
try:
|
||||||
defer.returnValue(self.txns.get_client_transaction(request, txn_id))
|
defer.returnValue(
|
||||||
|
self.txns.get_client_transaction(request, txn_id)
|
||||||
|
)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -30,9 +30,9 @@ class HttpTransactionStore(object):
|
|||||||
"""Retrieve a response for this request.
|
"""Retrieve a response for this request.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
key (str): A transaction-independent key for this request. Typically
|
key (str): A transaction-independent key for this request. Usually
|
||||||
this is a combination of the path (without the transaction id) and
|
this is a combination of the path (without the transaction id)
|
||||||
the user's access token.
|
and the user's access token.
|
||||||
txn_id (str): The transaction ID for this request
|
txn_id (str): The transaction ID for this request
|
||||||
Returns:
|
Returns:
|
||||||
A tuple of (HTTP response code, response content) or None.
|
A tuple of (HTTP response code, response content) or None.
|
||||||
@ -51,9 +51,9 @@ class HttpTransactionStore(object):
|
|||||||
"""Stores an HTTP response tuple.
|
"""Stores an HTTP response tuple.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
key (str): A transaction-independent key for this request. Typically
|
key (str): A transaction-independent key for this request. Usually
|
||||||
this is a combination of the path (without the transaction id) and
|
this is a combination of the path (without the transaction id)
|
||||||
the user's access token.
|
and the user's access token.
|
||||||
txn_id (str): The transaction ID for this request.
|
txn_id (str): The transaction ID for this request.
|
||||||
response (tuple): A tuple of (HTTP response code, response content)
|
response (tuple): A tuple of (HTTP response code, response content)
|
||||||
"""
|
"""
|
||||||
@ -92,5 +92,3 @@ class HttpTransactionStore(object):
|
|||||||
token = request.args["access_token"][0]
|
token = request.args["access_token"][0]
|
||||||
path_without_txn_id = request.path.rsplit("/", 1)[0]
|
path_without_txn_id = request.path.rsplit("/", 1)[0]
|
||||||
return path_without_txn_id + "/" + token
|
return path_without_txn_id + "/" + token
|
||||||
|
|
||||||
|
|
||||||
|
@ -40,9 +40,9 @@ class VoipRestServlet(RestServlet):
|
|||||||
username = "%d:%s" % (expiry, auth_user.to_string())
|
username = "%d:%s" % (expiry, auth_user.to_string())
|
||||||
|
|
||||||
mac = hmac.new(turnSecret, msg=username, digestmod=hashlib.sha1)
|
mac = hmac.new(turnSecret, msg=username, digestmod=hashlib.sha1)
|
||||||
# We need to use standard base64 encoding here, *not* syutil's encode_base64
|
# We need to use standard base64 encoding here, *not* syutil's
|
||||||
# because we need to add the standard padding to get the same result as the
|
# encode_base64 because we need to add the standard padding to get the
|
||||||
# TURN server.
|
# same result as the TURN server.
|
||||||
password = base64.b64encode(mac.digest())
|
password = base64.b64encode(mac.digest())
|
||||||
|
|
||||||
defer.returnValue((200, {
|
defer.returnValue((200, {
|
||||||
|
@ -21,6 +21,7 @@ import OpenSSL
|
|||||||
from syutil.crypto.signing_key import decode_verify_key_bytes
|
from syutil.crypto.signing_key import decode_verify_key_bytes
|
||||||
import hashlib
|
import hashlib
|
||||||
|
|
||||||
|
|
||||||
class KeyStore(SQLBaseStore):
|
class KeyStore(SQLBaseStore):
|
||||||
"""Persistence for signature verification keys and tls X.509 certificates
|
"""Persistence for signature verification keys and tls X.509 certificates
|
||||||
"""
|
"""
|
||||||
|
@ -33,7 +33,9 @@ class RoomMemberStore(SQLBaseStore):
|
|||||||
target_user_id = event.state_key
|
target_user_id = event.state_key
|
||||||
domain = self.hs.parse_userid(target_user_id).domain
|
domain = self.hs.parse_userid(target_user_id).domain
|
||||||
except:
|
except:
|
||||||
logger.exception("Failed to parse target_user_id=%s", target_user_id)
|
logger.exception(
|
||||||
|
"Failed to parse target_user_id=%s", target_user_id
|
||||||
|
)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
logger.debug(
|
logger.debug(
|
||||||
@ -65,7 +67,8 @@ class RoomMemberStore(SQLBaseStore):
|
|||||||
# Check if this was the last person to have left.
|
# Check if this was the last person to have left.
|
||||||
member_events = self._get_members_query_txn(
|
member_events = self._get_members_query_txn(
|
||||||
txn,
|
txn,
|
||||||
where_clause="c.room_id = ? AND m.membership = ? AND m.user_id != ?",
|
where_clause=("c.room_id = ? AND m.membership = ?"
|
||||||
|
" AND m.user_id != ?"),
|
||||||
where_values=(event.room_id, Membership.JOIN, target_user_id,)
|
where_values=(event.room_id, Membership.JOIN, target_user_id,)
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -120,7 +123,6 @@ class RoomMemberStore(SQLBaseStore):
|
|||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def get_room_members(self, room_id, membership=None):
|
def get_room_members(self, room_id, membership=None):
|
||||||
"""Retrieve the current room member list for a room.
|
"""Retrieve the current room member list for a room.
|
||||||
|
|
||||||
|
@ -42,7 +42,8 @@ class Distributor(object):
|
|||||||
if name in self.signals:
|
if name in self.signals:
|
||||||
raise KeyError("%r already has a signal named %s" % (self, name))
|
raise KeyError("%r already has a signal named %s" % (self, name))
|
||||||
|
|
||||||
self.signals[name] = Signal(name,
|
self.signals[name] = Signal(
|
||||||
|
name,
|
||||||
suppress_failures=self.suppress_failures,
|
suppress_failures=self.suppress_failures,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ def send_email(smtp_server, from_addr, to_addr, subject, body):
|
|||||||
EmailException if there was a problem sending the mail.
|
EmailException if there was a problem sending the mail.
|
||||||
"""
|
"""
|
||||||
if not smtp_server or not from_addr or not to_addr:
|
if not smtp_server or not from_addr or not to_addr:
|
||||||
raise EmailException("Need SMTP server, from and to addresses. Check " +
|
raise EmailException("Need SMTP server, from and to addresses. Check"
|
||||||
" the config to set these.")
|
" the config to set these.")
|
||||||
|
|
||||||
msg = MIMEMultipart('alternative')
|
msg = MIMEMultipart('alternative')
|
||||||
|
@ -13,9 +13,9 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
|
||||||
import copy
|
import copy
|
||||||
|
|
||||||
|
|
||||||
class JsonEncodedObject(object):
|
class JsonEncodedObject(object):
|
||||||
""" A common base class for defining protocol units that are represented
|
""" A common base class for defining protocol units that are represented
|
||||||
as JSON.
|
as JSON.
|
||||||
@ -89,6 +89,7 @@ class JsonEncodedObject(object):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "(%s, %s)" % (self.__class__.__name__, repr(self.__dict__))
|
return "(%s, %s)" % (self.__class__.__name__, repr(self.__dict__))
|
||||||
|
|
||||||
|
|
||||||
def _encode(obj):
|
def _encode(obj):
|
||||||
if type(obj) is list:
|
if type(obj) is list:
|
||||||
return [_encode(o) for o in obj]
|
return [_encode(o) for o in obj]
|
||||||
|
Loading…
Reference in New Issue
Block a user