Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# ensure complete metalink
if __first and metalink:
yield '\n\n'
if metalink:
yield '\n'
except DataIdentifierNotFound as error:
raise generate_http_error(404, 'DataIdentifierNotFound', 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)
class ReplicasDIDs(RucioController):
@check_accept_header_wrapper(['application/x-json-stream'])
def POST(self):
"""
List the DIDs associated to a list of replicas.
HTTP Success:
200 OK
HTTP Error:
401 Unauthorized
406 Not Acceptable
500 InternalError
:returns: A list of dictionaries containing the mAPPing PFNs to DIDs.
"""
if operation == 'connect':
objectstore.connect(rse, url)
else:
result = objectstore.get_signed_urls([url], rse=rse, operation=operation)
if isinstance(result[url], Exception):
raise result[url]
return result[url]
except RucioException as error:
raise generate_http_error(500, error.__class__.__name__, error.args[0])
except Exception as error:
print(traceback.format_exc())
raise InternalError(error)
raise OK()
class ObjectStore(RucioController):
def POST(self, rse, operation):
"""
Get URLs for files at a given RSE.
HTTP Success:
200 OK
HTTP Error:
401 Unauthorized
500 Internal Error
"""
header('Content-Type', 'application/json')
json_data = data()
try:
parameters = parse_response(json_data)
except RucioException as error:
raise generate_http_error(500, error.__class__.__name__, error.args[0])
except Exception as error:
raise InternalError(error)
def PUT(self):
raise BadRequest()
def DELETE(self):
raise BadRequest()
def POST(self):
raise BadRequest()
class States(RucioController):
@check_accept_header_wrapper(['application/x-json-stream'])
def GET(self, account, name=None):
"""
Return a summary of the states of all rules of a given subscription id.
HTTP Success:
200 OK
HTTP Error:
404 Not Found
406 Not Acceptable
500 Internal Error
"""
header('Content-Type', 'application/x-json-stream')
# PY3K COMPATIBLE
from web import (application, header, loadhook, ctx)
from rucio.common.exception import RucioException
from rucio.common.utils import generate_http_error, render_json
from rucio.api.exporter import export_data
from rucio.web.rest.common import rucio_loadhook, RucioController, check_accept_header_wrapper
URLS = (
'/', 'Export',
'', 'Export'
)
class Export(RucioController):
""" Export data from Rucio. """
@check_accept_header_wrapper(['application/json'])
def GET(self):
""" Export data from Rucio.
HTTP Success:
200 OK
HTTP Error:
400 Bad request
401 Unauthorized
404 Resource not Found
406 Not Acceptable
500 InternalError
"""
"""
header('Content-Type', 'application/json')
try:
usage = get_rse_account_usage(rse=rse)
for row in usage:
yield dumps(row, cls=APIEncoder) + '\n'
except RSENotFound as error:
raise generate_http_error(404, 'RSENotFound', 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)
class Distance(RucioController):
""" Create/Update and read distances between RSEs. """
@check_accept_header_wrapper(['application/json'])
def GET(self, source, destination):
"""
Get RSE distance between source and destination.
:param rse: the RSE name.
"""
header('Content-Type', 'application/json')
try:
distance = get_distance(source=source,
destination=destination,
issuer=ctx.env.get('issuer'))
return dumps(distance, cls=APIEncoder)
except RSENotFound as error:
import json
import time
import traceback
from web import application, ctx, data, header, InternalError, Created
from rucio.common.utils import generate_http_error
from rucio.core.nongrid_trace import trace
from rucio.web.rest.common import RucioController
URLS = (
'/', 'Trace',
)
class Trace(RucioController):
def POST(self):
header('Content-Type', 'application/octet-stream')
header('Access-Control-Allow-Origin', ctx.env.get('HTTP_ORIGIN'))
header('Access-Control-Allow-Headers', ctx.env.get('HTTP_ACCESS_CONTROL_REQUEST_HEADERS'))
header('Access-Control-Allow-Methods', '*')
header('Access-Control-Allow-Credentials', 'true')
try:
payload = json.loads(data())
# generate entry timestamp
payload['timeentry'] = int(time.time())
# guess client IP
:param scope: The scope name.
"""
header('Content-Type', 'application/x-json-stream')
try:
for rule in list_replication_rules({'scope': scope, 'name': name}):
yield dumps(rule, cls=APIEncoder) + '\n'
except RuleNotFound as error:
raise generate_http_error(404, 'RuleNotFound', 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)
class AssociatedRules(RucioController):
@check_accept_header_wrapper(['application/x-json-stream'])
def GET(self, scope, name):
"""
Return all associated rules of a file.
HTTP Success:
200 OK
HTTP Error:
401 Unauthorized
406 Not Acceptable
404 Not Found
:param scope: The scope name.
"""
raise generate_http_error(404, 'RuleNotFound', error.args[0])
except Exception as error:
print(format_exc())
raise InternalError(error)
def PUT(self):
raise BadRequest()
def POST(self):
raise BadRequest()
def DELETE(self):
raise BadRequest()
class UsageHistory(RucioController):
@check_accept_header_wrapper(['application/json'])
def GET(self, account, rse):
"""
Return the account usage of the account.
HTTP Success:
200 OK
HTTP Error:
401 Unauthorized
404 Not Found
406 Not Acceptable
500 Internal Error
:param account: The account name.
if 'source' in params:
source = params['source'][0]
try:
for usage in list_rse_usage_history(rse=rse, issuer=ctx.env.get('issuer'), source=source):
yield render_json(**usage) + '\n'
except RSENotFound as error:
raise generate_http_error(404, 'RSENotFound', 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)
class Limits(RucioController):
""" Create, Update, Read and delete RSE limits. """
@check_accept_header_wrapper(['application/json'])
def GET(self, rse):
"""
Get RSE limits.
:param rse: the RSE name.
"""
header('Content-Type', 'application/json')
try:
limits = get_rse_limits(rse=rse, issuer=ctx.env.get('issuer'))
return render_json(**limits)
except RSENotFound as error:
raise generate_http_error(404, 'RSENotFound', error.args[0])
except RucioException as error:
500 InternalError
:param Rucio-Account: Account identifier.
:param Rucio-Auth-Token: as an 32 character hex string.
:returns: A list containing all account names as dict.
"""
header('Content-Type', 'application/x-json-stream')
filter = {}
if ctx.query:
filter = dict(parse_qsl(ctx.query[1:]))
for account in list_accounts(filter=filter):
yield render_json(**account) + "\n"
class AccountLimits(RucioController):
def GET(self, account, rse=None):
""" get the current limits for an account on a specific RSE
HTTP Success:
200 OK
HTTP Error:
404 Not Found
500 InternalError
:param X-Rucio-Account: Account identifier.
:param X-Rucio-Auth-Token: as an 32 character hex string.
:param account: The account name.
:param rse: The rse name.