How to use the rucio.common.utils.generate_http_error function in rucio

To help you get started, we’ve selected a few rucio examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github rucio / rucio / lib / rucio / web / rest / webpy / v1 / authentication.py View on Github external
return render.auth_crash('contact')
            raise generate_http_error(401, 'CannotAuthorize', 'Cannot authorize token request.')
        except RucioException as error:
            render = template.render(join(dirname(__file__), '../auth_templates/'))
            return render.auth_crash('internal_error')
            raise generate_http_error(500, error.__class__.__name__, error.args[0])
        except Exception as error:
            print(format_exc())
            render = template.render(join(dirname(__file__), '../auth_templates/'))
            return render.auth_crash('internal_error')
            raise InternalError(error)

        render = template.render(join(dirname(__file__), '../auth_templates/'))
        if not result:
            return render.auth_crash('no_result')
            raise generate_http_error(401, 'CannotAuthorize', 'Cannot authorize token request.')
        if 'fetchcode' in result:
            authcode = result['fetchcode']
            return render.auth_granted(authcode)
        elif 'polling' in result and result['polling'] is True:
            authcode = "allok"
            return render.auth_granted(authcode)
        else:
            return render.auth_crash('bad_request')
            raise BadRequest()
github rucio / rucio / lib / rucio / web / rest / webpy / v1 / replica.py View on Github external
HTTP Error:
            401 Unauthorized
            409 Conflict
            500 Internal Error
        """
        json_data = data()
        try:
            parameters = parse_response(json_data)
        except ValueError:
            raise generate_http_error(400, 'ValueError', 'Cannot decode json parameter list')

        try:
            delete_replicas(rse=parameters['rse'], files=parameters['files'], issuer=ctx.env.get(
                'issuer'), ignore_availability=parameters.get('ignore_availability', False))
        except AccessDenied as error:
            raise generate_http_error(401, 'AccessDenied', error.args[0])
        except RSENotFound as error:
            raise generate_http_error(404, 'RSENotFound', error.args[0])
        except ResourceTemporaryUnavailable as error:
            raise generate_http_error(503, 'ResourceTemporaryUnavailable', error.args[0])
        except ReplicaNotFound as error:
            raise generate_http_error(404, 'ReplicaNotFound', error.args[0])
        except RucioException as error:
            raise generate_http_error(500, error.__class__.__name__, error.args[0])
        except Exception as error:
            print(format_exc())
            raise InternalError(error)
        raise OK()
github rucio / rucio / lib / rucio / web / rest / webpy / v1 / did.py View on Github external
"""

        select = {}
        scope = ""
        if ctx.query:
            params = parse_qs(ctx.query[1:])
            if 'scope' in params:
                scope = params['scope'][0]
            if 'select' in params:
                select = loads(params['select'][0])

        try:
            dids = list_dids_by_meta(scope=scope, select=select)
            yield dumps(dids, cls=APIEncoder) + '\n'
        except NotImplementedError:
            raise generate_http_error(409, 'NotImplementedError', 'Feature not in current database')
        except Exception as error:
            print(format_exc())
            raise InternalError(error)
github rucio / rucio / lib / rucio / web / rest / webpy / v1 / subscription.py View on Github external
Retrieve a subscription matching the given subscription id

        HTTP Success:
            200 OK

        HTTP Error:
            401 Unauthorized
            404 Not Found
            406 Not Acceptable

        """
        header('Content-Type', 'application/json')
        try:
            subscription = get_subscription_by_id(subscription_id)
        except SubscriptionNotFound as error:
            raise generate_http_error(404, 'SubscriptionNotFound', error.args[0])
        except RucioException as error:
            raise generate_http_error(500, error.__class__.__name__, error.args[0])
        except Exception as error:
            raise InternalError(error)

        return render_json(**subscription)
github rucio / rucio / lib / rucio / web / rest / webpy / v1 / did.py View on Github external
500 InternalError

        :param scope: Detach the data identifier from this scope.
        :param name: Detach the data identifier from this name.
        """
        try:
            json_data = loads(data())
            if 'dids' in json_data:
                dids = json_data['dids']
        except ValueError:
            raise generate_http_error(400, 'ValueError', 'Cannot decode json parameter list')

        try:
            detach_dids(scope=scope, name=name, dids=dids, issuer=ctx.env.get('issuer'))
        except UnsupportedOperation as error:
            raise generate_http_error(409, 'UnsupportedOperation', error.args[0])
        except DataIdentifierNotFound as error:
            raise generate_http_error(404, 'DataIdentifierNotFound', error.args[0])
        except AccessDenied as error:
            raise generate_http_error(401, 'AccessDenied', error.args[0])
        except Exception as error:
            print(format_exc())
            raise InternalError(error)

        raise OK()
github rucio / rucio / lib / rucio / web / rest / dataset.py View on Github external
json_data = data()
        try:
            parameter = loads(json_data)
        except ValueError:
            raise generate_http_error(400, 'ValueError', 'cannot decode json parameter dictionary')

        monotonic = False
        try:
            dsn = parameter['dsn']
            monotonic = parameter['monotonic']
            if (type(monotonic) is not bool and monotonic is not None):
                raise generate_http_error(400, 'InputValidationError', 'Monotonic option needs to be a boolean value')
        except KeyError, e:
            if e.args[0] == 'dsn':
                raise generate_http_error(400, 'KeyError', '%s not defined' % str(e))
        except TypeError:
                raise generate_http_error(400, 'TypeError', 'body must be a json dictionary')

        auth_account = auth['account']

        try:
            add_dataset(scope=scope, dsn=dsn, account=auth_account, monotonic=monotonic)
        except ScopeNotFound, error:
            raise generate_http_error(404, 'ScopeNotFound', error.args[0][0])
        except AccountNotFound, error:
            raise generate_http_error(404, 'AccountNotFound', error.args[0][0])
        except DatasetAlreadyExists, error:
            raise generate_http_error(409, 'DatasetAlreadyExists', error.args[0][0])
        except FileAlreadyExists, error:
            raise generate_http_error(409, 'FileAlreadyExists', error.args[0][0])
        except Exception, error:
github rucio / rucio / lib / rucio / web / rest / webpy / v1 / authentication.py View on Github external
# interaction with web browser - display response in html format
        header('Content-Type', 'text/html')
        header('Cache-Control', 'no-cache, no-store, max-age=0, must-revalidate')
        header('Cache-Control', 'post-check=0, pre-check=0', False)
        header('Pragma', 'no-cache')

        query_string = ctx.env.get('QUERY_STRING')
        try:
            fetchtoken = ctx.env.get('HTTP_X_RUCIO_CLIENT_FETCH_TOKEN')
            fetchtoken = (fetchtoken == 'True')
            result = redirect_auth_oidc(query_string, fetchtoken)

        except AccessDenied:
            render = template.render(join(dirname(__file__), '../auth_templates/'))
            return render.auth_crash('contact')
            raise generate_http_error(401, 'CannotAuthenticate', 'Cannot contact the Rucio Authentication Server.')

        except RucioException as error:
            render = template.render(join(dirname(__file__), '../auth_templates/'))
            return render.auth_crash('internal_error')
            raise generate_http_error(500, error.__class__.__name__, error.args[0])

        except Exception as error:
            print(format_exc())
            render = template.render(join(dirname(__file__), '../auth_templates/'))
            return render.auth_crash('internal_error')
            raise InternalError(error)

        if not result:
            render = template.render(join(dirname(__file__), '../auth_templates/'))
            return render.auth_crash('no_token')
            raise generate_http_error(401, 'CannotAuthenticate', 'Cannot contact the Rucio Authentication Server.')
github rucio / rucio / lib / rucio / web / rest / webpy / v1 / subscription.py View on Github external
state = None
        if ctx.query:
            params = parse_qs(ctx.query[1:])
            if 'state' in params:
                state = params['state'][0]
        try:
            subscriptions = [subscription['id'] for subscription in list_subscriptions(name=name, account=account)]
            if len(subscriptions) > 0:
                if state:
                    for rule in list_replication_rules({'subscription_id': subscriptions[0], 'state': state}):
                        yield dumps(rule, cls=APIEncoder) + '\n'
                else:
                    for rule in list_replication_rules({'subscription_id': subscriptions[0]}):
                        yield dumps(rule, cls=APIEncoder) + '\n'
        except RuleNotFound as error:
            raise generate_http_error(404, 'RuleNotFound', error.args[0])
        except SubscriptionNotFound as error:
            raise generate_http_error(404, 'SubscriptionNotFound', error.args[0])
        except RucioException as error:
            raise generate_http_error(500, error.__class__.__name__, error.args[0])
        except Exception as error:
            raise InternalError(error)
github rucio / rucio / lib / rucio / web / rest / webpy / v1 / did.py View on Github external
meta = loads(json_data)
        except ValueError:
            raise generate_http_error(400, 'ValueError', 'Cannot decode json parameter list')

        try:
            add_did_meta(scope=scope, name=name, meta=meta)
        except DataIdentifierNotFound as error:
            raise generate_http_error(404, 'DataIdentifierNotFound', error.args[0])
        except DataIdentifierAlreadyExists as error:
            raise generate_http_error(409, 'DataIdentifierAlreadyExists', error.args[0])
        except AccessDenied as error:
            raise generate_http_error(401, 'AccessDenied', error.args[0])
        except UnsupportedOperation as error:
            raise generate_http_error(409, 'UnsupportedOperation', error.args[0])
        except NotImplementedError:
            raise generate_http_error(409, 'NotImplementedError', 'Feature not in current database')
        except DatabaseException as error:
            raise generate_http_error(500, 'DatabaseException', error.args[0])
        except RucioException as error:
            raise generate_http_error(500, error.__class__.__name__, error.args[0])
        except Exception as error:
            print(format_exc())
            raise InternalError(error)
        raise Created()
github rucio / rucio / lib / rucio / web / rest / webpy / v1 / account.py View on Github external
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:
            add_account_identity(identity_key=identity, id_type=authtype, account=account, email=email,
                                 password=password, issuer=ctx.env.get('issuer'), default=default)
        except AccessDenied as error:
            raise generate_http_error(401, 'AccessDenied', error.args[0])
        except Duplicate as error:
            raise generate_http_error(409, 'Duplicate', error.args[0])
        except AccountNotFound as error:
            raise generate_http_error(404, 'AccountNotFound', error.args[0])
        except IdentityError as error:
            raise generate_http_error(400, 'IdentityError', error.args[0])
        except Exception as error:
            print(str(format_exc()))
            raise InternalError(error)

        raise Created()