How to use the rucio.common.utils.generate_http_error_flask 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 / flaskapi / v1 / request.py View on Github external
"""

        src_rse = f_request.get('src_rse')
        dst_rse = f_request.get('dst_rse')
        src_site = f_request.get('src_site')
        dst_site = f_request.get('dst_site')
        request_states = f_request.get('request_states')

        if not request_states:
            return generate_http_error_flask(400, 'MissingParameter', 'Request state is missing')
        if src_rse and not dst_rse:
            return generate_http_error_flask(400, 'MissingParameter', 'Destination RSE is missing')
        elif dst_rse and not src_rse:
            return generate_http_error_flask(400, 'MissingParameter', 'Source RSE is missing')
        elif src_site and not dst_site:
            return generate_http_error_flask(400, 'MissingParameter', 'Destination site is missing')
        elif dst_site and not src_site:
            return generate_http_error_flask(400, 'MissingParameter', 'Source site is missing')

        try:
            states = [RequestState.from_string(state) for state in request_states.split(',')]
        except ValueError:
            return generate_http_error_flask(400, 'Invalid', 'Request state value is invalid')

        src_rses = []
        dst_rses = []
        if src_site:
            src_rses = get_rses_with_attribute_value(key='site', value=src_site, lookup_key='site')
            if not src_rses:
                return generate_http_error_flask(404, 'NotFound', 'Could not resolve site name %s to RSE' % src_site)
            src_rses = [get_rse_name(rse['rse_id']) for rse in src_rses]
            dst_rses = get_rses_with_attribute_value(key='site', value=dst_site, lookup_key='site')
github rucio / rucio / lib / rucio / web / rest / flaskapi / v1 / account_limit.py View on Github external
:param account: Account name.
        :param rse: RSE name.
        :status 200: Successfully deleted.
        :status 401: Invalid auth token.
        :status 404: RSE not found.
        :status 404: Account not found
        """
        try:
            delete_local_account_limit(account=account, rse=rse, issuer=request.environ.get('issuer'))
        except AccessDenied as exception:
            return generate_http_error_flask(401, 'AccessDenied', exception.args[0])
        except AccountNotFound as exception:
            return generate_http_error_flask(404, 'AccountNotFound', exception.args[0])
        except RSENotFound as exception:
            return generate_http_error_flask(404, 'RSENotFound', exception.args[0])
        except Exception as exception:
            print(format_exc())
            return exception, 500
        return "OK", 200
github rucio / rucio / lib / rucio / web / rest / flaskapi / v1 / replica.py View on Github external
return generate_http_error_flask(400, 'ValueError', 'Cannot decode json parameter list')

        try:
            add_replicas(rse=parameters['rse'], files=parameters['files'], issuer=request.environ.get('issuer'), ignore_availability=parameters.get('ignore_availability', False))
        except InvalidPath as error:
            return generate_http_error_flask(400, 'InvalidPath', error.args[0])
        except AccessDenied as error:
            return generate_http_error_flask(401, 'AccessDenied', error.args[0])
        except Duplicate as error:
            return generate_http_error_flask(409, 'Duplicate', error.args[0])
        except DataIdentifierAlreadyExists as error:
            return generate_http_error_flask(409, 'DataIdentifierAlreadyExists', error.args[0])
        except RSENotFound as error:
            return generate_http_error_flask(404, 'RSENotFound', error.args[0])
        except ResourceTemporaryUnavailable as error:
            return generate_http_error_flask(503, 'ResourceTemporaryUnavailable', 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 error, 500
        return 'Created', 201
github rucio / rucio / lib / rucio / web / rest / flaskapi / v1 / rule.py View on Github external
except InvalidRSEExpression as error:
            return generate_http_error_flask(409, 'InvalidRSEExpression', error.args[0])
        except DataIdentifierNotFound as error:
            return generate_http_error_flask(404, 'DataIdentifierNotFound', error.args[0])
        except ReplicationRuleCreationTemporaryFailed as error:
            return generate_http_error_flask(409, 'ReplicationRuleCreationTemporaryFailed', error.args[0])
        except InvalidRuleWeight as error:
            return generate_http_error_flask(409, 'InvalidRuleWeight', error.args[0])
        except StagingAreaRuleRequiresLifetime as error:
            return generate_http_error_flask(409, 'StagingAreaRuleRequiresLifetime', error.args[0])
        except ScratchDiskLifetimeConflict as error:
            return generate_http_error_flask(409, 'ScratchDiskLifetimeConflict', error.args[0])
        except ManualRuleApprovalBlocked as error:
            return generate_http_error_flask(409, 'ManualRuleApprovalBlocked', error.args[0])
        except InvalidObject as error:
            return generate_http_error_flask(409, 'InvalidObject', error.args[0])
        except RucioException as error:
            return generate_http_error_flask(500, error.__class__.__name__, error.args[0])
        except Exception as error:
            print(error)
            print(format_exc())
            return error, 500

        return Response(dumps(rule_ids), status=201)
github rucio / rucio / lib / rucio / web / rest / flaskapi / v1 / nongrid_trace.py View on Github external
"""
        try:
            payload = json.loads(request.data)

            # generate entry timestamp
            payload['timeentry'] = int(time.time())

            # guess client IP
            payload['ip'] = request.environ.get('HTTP_X_FORWARDED_FOR')
            if payload['ip'] is None:
                payload['ip'] = request.remote_addr

            trace(payload=payload)

        except ValueError:
            return generate_http_error_flask(400, 'ValueError', 'Cannot decode json data')
        except Exception as error:
            print(traceback.format_exc())
            return error, 500

        return "Created", 201
github rucio / rucio / lib / rucio / web / rest / flaskapi / v1 / account.py View on Github external
:statsu 406: Not Acceptable
        :status 500: Database exception.
        :returns: A list containing all scope names for an account.
        """
        try:
            scopes = get_scopes(account)
        except AccountNotFound as error:
            return generate_http_error_flask(404, 'AccountNotFound', 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 error, 500

        if not len(scopes):
            return generate_http_error_flask(404, 'ScopeNotFound', 'no scopes found for account ID \'%s\'' % account)

        return Response(dumps(scopes), content_type="application/json")
github rucio / rucio / lib / rucio / web / rest / flaskapi / v1 / rse.py View on Github external
:status 200: OK.
        :status 401: Invalid Auth Token.
        :status 404: RSE Not Found.
        :status 406: Not Acceptable.
        :status 500: Internal Error.
        :returns: Line separated list of dict with account usage and limits.

        """
        try:
            usage = get_rse_account_usage(rse=rse, vo=request.environ.get('vo'))
            data = ""
            for row in usage:
                data = dumps(row, cls=APIEncoder) + '\n'
            return Response(data, content_type="application/json")
        except RSENotFound as error:
            return generate_http_error_flask(404, 'RSENotFound', 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 error, 500
github rucio / rucio / lib / rucio / web / rest / flaskapi / v1 / lock.py View on Github external
:status 406: Not Acceptable.
        :status 500: Internal Error.
        :returns: Line separated list of dictionaries with lock information.
        """

        did_type = request.args.get('did_type', None)
        try:
            if did_type == 'dataset':
                data = ""
                for lock in get_dataset_locks_by_rse(rse, vo=request.environ.get('vo')):
                    data += render_json(**lock) + '\n'
                return Response(data, content_type="application/x-json-stream")
            else:
                return 'Wrong did_type specified', 500
        except RSENotFound as error:
            return generate_http_error_flask(404, error.__class__.__name__, error.args[0])
        except RucioException as error:
            return generate_http_error_flask(500, error.__class__.__name__, error.args[0])
        except Exception as error:
            return error, 500
github rucio / rucio / lib / rucio / web / rest / flaskapi / v1 / rse.py View on Github external
:param rse: the RSE name.
        :status 200: OK.
        :status 401: Invalid Auth Token.
        :status 404: RSE not found.
        :status 500: Internal Error.

        """
        try:
            del_rse(rse=rse, issuer=request.environ.get('issuer'), vo=request.environ.get('vo'))
        except RSENotFound as error:
            return generate_http_error_flask(404, 'RSENotFound', error.args[0])
        except AccessDenied as error:
            return generate_http_error_flask(401, 'AccessDenied', error.args[0])
        except RSEOperationNotSupported as error:
            return generate_http_error_flask(404, 'RSEOperationNotsupported', error.args[0])
        except CounterNotFound as error:
            return generate_http_error_flask(404, 'CounterNotFound', error.args[0])

        return "OK", 200
github rucio / rucio / lib / rucio / web / rest / flaskapi / v1 / did.py View on Github external
json_data = request.data
        try:
            params = loads(json_data)
            value = params['value']
            recursive = params.get('recursive', False)
        except ValueError:
            return generate_http_error_flask(400, 'ValueError', 'Cannot decode json parameter list')
        try:
            set_metadata(scope=scope, name=name, key=key, value=value,
                         issuer=request.environ.get('issuer'), recursive=recursive)
        except DataIdentifierNotFound as error:
            return generate_http_error_flask(404, 'DataIdentifierNotFound', error.args[0])
        except Duplicate as error:
            return generate_http_error_flask(409, 'Duplicate', error.args[0])
        except KeyNotFound as error:
            return generate_http_error_flask(400, 'KeyNotFound', error.args[0])
        except InvalidMetadata as error:
            return generate_http_error_flask(400, 'InvalidMetadata', error.args[0])
        except InvalidValueForKey as error:
            return generate_http_error_flask(400, 'InvalidValueForKey', 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 error, 500

        return "Created", 201