Exemplo n.º 1
0
 def revoke_key(key):
     if not key:
         raise BadRequestError({'error_msg': 'Ivalid Master-Key'})
     uuid_key = None
     try:
         uuid_key = uuid.UUID(key)
     except ValueError as e:
         raise BadRequestError({'error_msg': 'Ivalid Master-Key'})
     MasterHelper.revoke(uuid_key)
Exemplo n.º 2
0
 def check_key(key):
     if not key:
         raise BadRequestError({'error_msg': 'Ivalid Master-Key'})
     uuid_key = None
     try:
         uuid_key = uuid.UUID(key)
     except ValueError as e:
         raise BadRequestError({'error_msg': 'Ivalid Master-Key'})
     return MasterHelper.check(uuid_key)
Exemplo n.º 3
0
 def check_token(token):
     if not token:
         raise BadRequestError({'error_msg': 'Ivalid Token'})
     uuid_token = None
     try:
         uuid_token = uuid.UUID(token)
     except ValueError as e:
         raise BadRequestError({'error_msg': 'Ivalid Token'})
     return Token.validate(token)
Exemplo n.º 4
0
 def handler_wrapper(*args, **kwargs):
     # No need to check auth
     if not mode:
         return func(*args, **kwargs)
     def master_available():
         return mode & AuthMode.MASTER and MasterControl.is_master_mode()
     auth = get_auth()
     if not auth:
         raise UnauthorizedError({'error_msg': 'No Authorization header is present in request'})
     if not validate_auth_type(auth):
         raise BadRequestError({'error_msg': 'Invalid Authorization header'})
     master_available = master_available()
     if master_available and 'Master-Key' in auth:
         if MasterControl.check_key(auth['Master-Key']):
             return func(*args, **kwargs)
         else:
             raise ForbiddenError({'error_msg': 'Invalid Master-Key'})
     elif master_available:
         raise ForbiddenError({'error_msg': 'Cannot access resource while node is in master mode'})
     elif 'Token' in auth and ((mode & AuthMode.USER) or (mode & AuthMode.ORG)):
         token = auth['Token']
         if not AuthControl.check_token(token):
             raise ForbiddenError({'error_msg': 'Invalid token or token has been expired'})
         if not (mode & AuthMode.USER):
             # TODO: [OOKAMI] Validate organization exists
             pass
     else:
         raise ForbiddenError({'error_msg': 'Permission denied'})
     return func(*args, **kwargs)
Exemplo n.º 5
0
 def POST():
     if not len(args):
         try:
             with BodyReader() as body:
                 name = body['name']
                 own_name = body['own_name']
         except MultiKeyError as ex:
             paths = ex.get_error_paths()
             keys = {'paths': paths, 'count': len(paths)}
             raise BadRequestError({
                 'error_msg': 'Request body is not full',
                 'keys': keys
             })
         if not len(name) or not len(own_name):
             raise BadRequestError({
                 'error_msg': 'Cannot create language with empty name',
                 'name': name,
                 'own_name': own_name
             })
         return LanguageControl.create(name, own_name)
     raise NotFoundError({'error_msg': 'Resource not found'})
Exemplo n.º 6
0
 def POST():
     try:
         with BodyReader() as body:
             local_name = body['local_name']
     except MultiKeyError as ex:
         paths = ex.get_error_paths()
         keys = {'paths': paths, 'count': len(paths)}
         raise BadRequestError({
             'error_msg': 'Request body is not full',
             'keys': keys
         })
     return OrganizationControl.create(local_name)
Exemplo n.º 7
0
 def POST():
     try:
         with BodyReader() as body:
             username = body['username']
             password = body['password']
             email = body['email']
     except MultiKeyError as ex:
         paths = ex.get_error_paths()
         keys = {'paths': paths, 'count': len(paths)}
         raise BadRequestError({
             'error_msg': 'Request body is not full',
             'keys': keys
         })
     return UserControl.create_user(username, email, password)
Exemplo n.º 8
0
 def POST():
     if not len(args):
         return UnitsControl.create_unit()
     if len(args) == 2 and args[1] == 'name':
         id = args[0]
         try:
             with BodyReader() as body:
                 lang = body['lang']
                 short_name = body['short_name']
                 full_name = body['full_name']
                 desc = body['description']
         except MultiKeyError as ex:
             paths = ex.get_error_paths()
             keys = {'paths': paths, 'count': len(paths)}
             raise BadRequestError({
                 'error_msg': 'Request body is not full',
                 'keys': keys
             })
         try:
             return UnitsControl.add_name(id, lang, short_name,
                                          full_name, desc)
         except ValueError as ex:
             raise BadRequestError({'error_msg': 'Bad request'})
     raise NotFoundError({'error_msg': 'Resource not found'})
Exemplo n.º 9
0
 def key_error():
     raise BadRequestError({'error_msg': 'Ivalid Master-Key'})