예제 #1
0
 def test_recover_root_identity(self):
     """ MULTI VO (CORE): Test adding a new identity for root using super_root """
     identity_key = ''.join(choice(ascii_lowercase) for x in range(10))
     with assert_raises(AccessDenied):
         vo_api.recover_vo_root_identity(root_vo=self.new_vo['vo'], identity_key=identity_key, id_type='userpass', email='*****@*****.**', issuer='root', password='******', **self.vo)
     vo_api.recover_vo_root_identity(root_vo=self.new_vo['vo'], identity_key=identity_key, id_type='userpass', email='*****@*****.**', issuer='super_root', password='******', vo='def')
     assert_in('root', list_accounts_for_identity(identity_key=identity_key, id_type='userpass'))
예제 #2
0
    def POST(self, root_vo):
        """ Recover root identity for a given VO

        HTTP Success:
            201 Created

        HTTP Error:
            401 Unauthorized
            404 Not Found
            409 Conflict
            500 InternalError

        :param root_vo: VO to be updated.
        """
        json_data = data().decode()

        try:
            parameter = loads(json_data)
        except ValueError:
            raise generate_http_error(400, 'ValueError', 'cannot decode json parameter dictionary')

        try:
            identity = parameter['identity']
            authtype = parameter['authtype']
            email = parameter['email']
            password = parameter.get('password', None)
            default = parameter.get('default', False)
        except KeyError as error:
            if error.args[0] == 'authtype' or error.args[0] == 'identity' or error.args[0] == 'email':
                raise generate_http_error(400, 'KeyError', '%s not defined' % str(error))
        except TypeError:
            raise generate_http_error(400, 'TypeError', 'body must be a json dictionary')

        try:
            recover_vo_root_identity(root_vo=root_vo,
                                     identity_key=identity,
                                     id_type=authtype,
                                     email=email,
                                     password=password,
                                     default=default,
                                     issuer=ctx.env.get('issuer'),
                                     vo=ctx.env.get('vo'))
        except AccessDenied as error:
            raise generate_http_error(401, 'AccessDenied', error.args[0])
        except AccountNotFound as error:
            raise generate_http_error(404, 'AccountNotFound', error.args[0])
        except Duplicate as error:
            raise generate_http_error(409, 'Duplicate', error.args[0])
        except RucioException as error:
            raise generate_http_error(500, error.__class__.__name__, error.args[0])
        except Exception as error:
            print(error)
            print(format_exc())
            raise InternalError(error)

        raise Created()
예제 #3
0
    def post(self, vo):
        """ Recover root identity for a given VO

        .. :quickref: RecoverVO; Recover VO root identity.

        :param vo: VO to be recovered.
        :<json string identity: Identity key to use.
        :<json string authtype: Type of identity.
        :<json string email: Admin email for VO.
        :<json string email: Password for identity.
        :<json bool default: Whether to use identity as account default.
        :status 201: VO recovered successfully.
        :status 401: Invalid Auth Token.
        :status 404: Account not found.
        :status 409: Unsupported operation.
        """
        parameters = json_parameters()
        identity = param_get(parameters, 'identity')
        authtype = param_get(parameters, 'authtype')
        email = param_get(parameters, 'email')
        password = param_get(parameters, 'password', default=None)
        default = param_get(parameters, 'default', default=False)

        try:
            recover_vo_root_identity(
                root_vo=vo,
                identity_key=identity,
                id_type=authtype,
                email=email,
                password=password,
                default=default,
                issuer=request.environ.get('issuer'),
                vo=request.environ.get('vo'),
            )
        except AccessDenied as error:
            return generate_http_error_flask(401, error)
        except AccountNotFound as error:
            return generate_http_error_flask(404, error)
        except Duplicate as error:
            return generate_http_error_flask(409, error)

        return 'Created', 201
예제 #4
0
파일: vo.py 프로젝트: stfc/rucio
    def post(self, vo):
        """ Recover root identity for a given VO

        .. :quickref: RecoverVO; Recover VO root identity.

        :param vo: VO to be recovered.
        :<json string identity: Identity key to use.
        :<json string authtype: Type of identity.
        :<json string email: Admin email for VO.
        :<json string email: Password for identity.
        :<json bool default: Whether to use identity as account default.
        :status 201: VO recovered successfully.
        :status 401: Invalid Auth Token.
        :status 404: Account not found.
        :status 409: Unsupported operation.
        :status 500: Internal Error.

        """
        json_data = request.data.decode()

        try:
            parameter = loads(json_data)
        except ValueError:
            return generate_http_error_flask(
                400, 'ValueError', 'cannot decode json parameter dictionary')

        try:
            identity = parameter['identity']
            authtype = parameter['authtype']
            email = parameter['email']
            password = parameter.get('password', None)
            default = parameter.get('default', False)
        except KeyError as error:
            if error.args[0] == 'authtype' or error.args[
                    0] == 'identity' or error.args[0] == 'email':
                return generate_http_error_flask(400, 'KeyError',
                                                 '%s not defined' % str(error))
        except TypeError:
            return generate_http_error_flask(400, 'TypeError',
                                             'body must be a json dictionary')

        try:
            recover_vo_root_identity(root_vo=vo,
                                     identity_key=identity,
                                     id_type=authtype,
                                     email=email,
                                     password=password,
                                     default=default,
                                     issuer=request.environ.get('issuer'),
                                     vo=request.environ.get('vo'))
        except AccessDenied as error:
            return generate_http_error_flask(401, 'AccessDenied',
                                             error.args[0])
        except AccountNotFound as error:
            return generate_http_error_flask(404, 'AccountNotFound',
                                             error.args[0])
        except Duplicate as error:
            return generate_http_error_flask(409, 'Duplicate', error.args[0])
        except RucioException as error:
            return generate_http_error_flask(500, error.__class__.__name__,
                                             error.args[0])
        except Exception as error:
            print(format_exc())
            return str(error), 500

        return 'Created', 201