|
@@ -22,8 +22,23 @@ class ConnectionClosed(Error):
|
|
class PathNotAllowed(Error):
|
|
class PathNotAllowed(Error):
|
|
"""Repository path not allowed"""
|
|
"""Repository path not allowed"""
|
|
|
|
|
|
|
|
+class InvalidRPCMethod(Error):
|
|
|
|
+ """RPC method is not valid"""
|
|
|
|
|
|
class RepositoryServer(object):
|
|
class RepositoryServer(object):
|
|
|
|
+ rpc_methods = (
|
|
|
|
+ '__len__',
|
|
|
|
+ 'check',
|
|
|
|
+ 'commit',
|
|
|
|
+ 'delete',
|
|
|
|
+ 'get',
|
|
|
|
+ 'list',
|
|
|
|
+ 'negotiate',
|
|
|
|
+ 'open',
|
|
|
|
+ 'put',
|
|
|
|
+ 'repair',
|
|
|
|
+ 'rollback',
|
|
|
|
+ )
|
|
|
|
|
|
def __init__(self, restrict_to_paths):
|
|
def __init__(self, restrict_to_paths):
|
|
self.repository = None
|
|
self.repository = None
|
|
@@ -47,6 +62,8 @@ class RepositoryServer(object):
|
|
for type, msgid, method, args in unpacker:
|
|
for type, msgid, method, args in unpacker:
|
|
method = method.decode('ascii')
|
|
method = method.decode('ascii')
|
|
try:
|
|
try:
|
|
|
|
+ if not method in self.rpc_methods:
|
|
|
|
+ raise InvalidRPCMethod(method)
|
|
try:
|
|
try:
|
|
f = getattr(self, method)
|
|
f = getattr(self, method)
|
|
except AttributeError:
|
|
except AttributeError:
|
|
@@ -155,8 +172,10 @@ class RemoteRepository(object):
|
|
raise IntegrityError(res)
|
|
raise IntegrityError(res)
|
|
elif error == b'PathNotAllowed':
|
|
elif error == b'PathNotAllowed':
|
|
raise PathNotAllowed(*res)
|
|
raise PathNotAllowed(*res)
|
|
- if error == b'ObjectNotFound':
|
|
|
|
|
|
+ elif error == b'ObjectNotFound':
|
|
raise Repository.ObjectNotFound(res[0], self.location.orig)
|
|
raise Repository.ObjectNotFound(res[0], self.location.orig)
|
|
|
|
+ elif error == b'InvalidRPCMethod':
|
|
|
|
+ raise InvalidRPCMethod(*res)
|
|
raise self.RPCError(error)
|
|
raise self.RPCError(error)
|
|
else:
|
|
else:
|
|
yield res
|
|
yield res
|