def PUT(self, section, option, value): """ Set the value of an option. If the option does not exist, create it. HTTP Success: 200 OK HTTP Error: 401 Unauthorized 500 ConfigurationError :param Rucio-Auth-Account: Account identifier. :param Rucio-Auth-Token: 32 character hex string. """ try: config.set(section=section, option=option, value=value, issuer=ctx.env.get('issuer')) except: raise generate_http_error( 500, 'ConfigurationError', 'Could not set value \'%s\' for section \'%s\' option \'%s\'' % (value, section, option)) raise Created()
def PUT(self, section, option, value): """ Set the value of an option. If the option does not exist, create it. TODO: remove this endpoint after migrating all clients to pass input data via a json body HTTP Success: 200 OK HTTP Error: 401 Unauthorized 500 ConfigurationError :param Rucio-Auth-Account: Account identifier. :param Rucio-Auth-Token: 32 character hex string. """ try: config.set(section=section, option=option, value=value, issuer=ctx.env.get('issuer'), vo=ctx.env.get('vo')) except ConfigurationError: raise generate_http_error(500, 'ConfigurationError', 'Could not set value \'%s\' for section \'%s\' option \'%s\'' % (value, section, option)) except Exception as error: print(format_exc()) raise InternalError(error) raise Created()
def POST(self, rse): """ Create RSE with given name. HTTP Success: 201 Created HTTP Error: 400 Bad request 401 Unauthorized 404 Resource not Found 409 Conflict 500 Internal Error """ json_data = data() kwargs = { 'deterministic': True, 'volatile': False, 'city': None, 'staging_area': False, 'region_code': None, 'country_name': None, 'continent': None, 'time_zone': None, 'ISP': None, 'rse_type': None, 'latitude': None, 'longitude': None, 'ASN': None, 'availability': None } try: parameters = json_data and loads(json_data) if parameters: for param in kwargs: if param in parameters: kwargs[param] = parameters[param] except ValueError: raise generate_http_error( 400, 'ValueError', 'Cannot decode json parameter dictionary') kwargs['issuer'] = ctx.env.get('issuer') try: add_rse(rse, **kwargs) except InvalidObject as error: raise generate_http_error(400, 'InvalidObject', error.args[0]) 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 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()
def POST(self): """ Set the value of an option. If the option does not exist, create it. HTTP Success: 200 OK HTTP Error: 401 Unauthorized 400 The input data is invalid or incomplete 500 ConfigurationError :param Rucio-Auth-Account: Account identifier. :param Rucio-Auth-Token: 32 character hex string. """ json_data = data().decode() try: input_data = json.loads(json_data) except ValueError: raise generate_http_error(400, 'ValueError', 'Cannot decode json parameter dictionary') section, option, value = _config_items_from_input(input_data) if section is None or option is None or value is None: raise generate_http_error(400, 'ValueError', 'Invalid input data') try: config.set(section=section, option=option, value=value, issuer=ctx.env.get('issuer'), vo=ctx.env.get('vo')) except ConfigurationError: raise generate_http_error(500, 'ConfigurationError', 'Could not set value \'%s\' for section \'%s\' option \'%s\'' % (value, section, option)) except Exception as error: print(format_exc()) raise InternalError(error) raise Created()
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 payload['ip'] = ctx.env.get('HTTP_X_FORWARDED_FOR') if payload['ip'] is None: payload['ip'] = ctx.ip # quand meme, cela peut etre None aussi trace(payload=payload) except ValueError: raise generate_http_error(400, 'ValueError', 'Cannot decode json parameter list') except Exception as error: print traceback.format_exc() raise InternalError(error) raise Created()
def PUT(self, account): """ Create a new identity and map it to an account. HTTP Success: 201 Created HTTP Error: 400 Bad Request 401 Unauthorized 500 Internal Error :param Rucio-Auth-Token: as an 32 character hex string. :param SavedCredentials: Apache mod_auth_kerb SavedCredentials. :param Rucio-Email: the desired email. :param account: the affected account via URL. """ gsscred = ctx.env.get('REMOTE_USER') email = ctx.env.get('HTTP_X_RUCIO_EMAIL') try: add_identity(gsscred, 'gss', email=email) except Exception as error: raise InternalError(error) try: add_account_identity(gsscred, 'gss', account, email=email, issuer=ctx.env.get('issuer')) except Exception as error: raise InternalError(error) raise Created()
def POST(self): """ Import data into Rucio. HTTP Success: 200 OK HTTP Error: 400 Bad request 401 Unauthorized 404 Resource not Found 500 InternalError """ header('Content-Type', 'application/x-json-stream') json_data = data() try: data_to_import = json_data and parse_response(json_data) except ValueError: raise generate_http_error( 400, 'ValueError', 'Cannot decode json parameter dictionary') try: import_data(data=data_to_import, issuer=ctx.env.get('issuer'), vo=ctx.env.get('vo')) except RucioException as error: raise generate_http_error(500, error.__class__.__name__, error.args[0]) raise Created()
def POST(self, new_vo): ''' Add a VO with a given name. ''' json_data = data() kwargs = {'description': None, 'email': None} try: parameters = json_data and loads(json_data) if parameters: for param in kwargs: if param in parameters: kwargs[param] = parameters[param] except ValueError: raise generate_http_error(400, 'ValueError', 'Cannot decode json parameter dictionary') kwargs['issuer'] = ctx.env.get('issuer') kwargs['vo'] = ctx.env.get('vo') try: add_vo(new_vo=new_vo, **kwargs) 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()
def PUT(self, account): """ Create a new identity and map it to an account. HTTP Success: 201 Created HTTP Error: 400 Bad Request 401 Unauthorized 500 Internal Error :param Rucio-Auth-Token: as an 32 character hex string. :param SSLStdEnv: Apache mod_ssl SSL Standard Env Variables. :param Rucio-Email: the desired email. :param account: the affected account via URL. """ dn = ctx.env.get('SSL_CLIENT_S_DN') email = ctx.env.get('HTTP_X_RUCIO_EMAIL') try: add_identity(dn, 'x509', email=email) except Exception as error: raise InternalError(error) try: add_account_identity(dn, 'x509', account, email=email, issuer=ctx.env.get('issuer')) except Exception as error: raise InternalError(error) raise Created()
def POST(self): try: json_data = loads(data()) except ValueError: raise generate_http_error(400, 'ValueError', 'Cannot decode json parameter list') try: add_dids(json_data, issuer=ctx.env.get('issuer')) except DataIdentifierNotFound as error: raise generate_http_error(404, 'DataIdentifierNotFound', error.args[0]) except DuplicateContent as error: raise generate_http_error(409, 'DuplicateContent', 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 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()
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['traceTimeentry'] = datetime.datetime.utcnow() payload['traceTimeentryUnix'] = calendar.timegm(payload['traceTimeentry'].timetuple()) + payload['traceTimeentry'].microsecond / 1e6 # guess client IP payload['traceIp'] = ctx.env.get('HTTP_X_FORWARDED_FOR') if payload['traceIp'] is None: payload['traceIp'] = ctx.ip # quand meme, cela peut etre None aussi # generate unique ID payload['traceId'] = str(uuid.uuid4()).replace('-', '').lower() trace(payload=payload) except ValueError: raise generate_http_error(400, 'ValueError', 'Cannot decode json parameter list') except Exception as error: print(traceback.format_exc()) raise InternalError(error) raise Created()
def POST(self): # To be moved in a common processor attachments, ignore_duplicate = [], False try: json_data = loads(data()) if type(json_data) is dict: attachments = json_data.get('attachments') ignore_duplicate = json_data.get('ignore_duplicate') elif type(json_data) is list: attachments = json_data except ValueError: raise generate_http_error(400, 'ValueError', 'Cannot decode json parameter list') try: attach_dids_to_dids(attachments=attachments, ignore_duplicate=ignore_duplicate, issuer=ctx.env.get('issuer')) except DataIdentifierNotFound as error: raise generate_http_error(404, 'DataIdentifierNotFound', error.args[0]) except DuplicateContent as error: raise generate_http_error(409, 'DuplicateContent', 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 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()
def POST(self): """ Set a tombstone on a list of replicas. HTTP Success: 201 OK HTTP Error: 401 Unauthorized 404 ReplicaNotFound 500 InternalError """ json_data = data() replicas = [] try: params = parse_response(json_data) if 'replicas' in params: replicas = params['replicas'] except ValueError: raise generate_http_error(400, 'ValueError', 'Cannot decode json parameter list') try: for replica in replicas: set_tombstone(replica['rse'], replica['scope'], replica['name'], issuer=ctx.env.get('issuer'), vo=ctx.env.get('vo')) 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 Created()
def POST(self, account, scope): """ Creates scope with given scope name. HTTP Success: 201 Created HTTP Error: 401 Unauthorized 404 Not Found 409 Conflict 500 Internal Error :param Rucio-Auth-Account: Account identifier. :param Rucio-Auth-Token: as an 32 character hex string. :params Rucio-Account: account belonging to the new scope. """ try: add_scope(scope, account, issuer=ctx.env.get('issuer')) 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 RucioException as error: raise generate_http_error(500, error.__class__.__name__, error.args[0]) except Exception as error: raise InternalError(error) raise Created()
def PUT(self, exception_id): """ Approve/Reject an execption. HTTP Success: 201 Created HTTP Error: 400 Bad Request 401 Unauthorized 404 Not Found 500 Internal Error """ json_data = data() try: params = loads(json_data) except ValueError: raise generate_http_error(400, 'ValueError', 'Cannot decode json parameter list') try: state = params['state'] except KeyError: state = None try: update_exception(exception_id=exception_id, state=state, issuer=ctx.env.get('issuer')) except UnsupportedOperation as error: raise generate_http_error(400, 'UnsupportedOperation', error[0][0]) except AccessDenied as error: raise generate_http_error(401, 'AccessDenied', error.args[0][0]) except LifetimeExceptionNotFound as error: raise generate_http_error(404, 'LifetimeExceptionNotFound', error[0][0]) except RucioException as error: raise generate_http_error(500, error.__class__.__name__, error.args[0]) except Exception as error: raise InternalError(error) raise Created()
def POST(self, account): """ Grant an identity access to an account. HTTP Success: 201 Created HTTP Error: 400 Bad Reqeust 401 Unauthorized 409 Conflict 500 Internal Error :param account: Account identifier. """ 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: add_account_identity(identity_key=identity, id_type=authtype, account=account, email=email, password=password, issuer=ctx.env.get('issuer'), default=default, vo=ctx.env.get('vo')) 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()
def POST(self, account): """ create account with given account name. HTTP Success: 201 Created HTTP Error: 400 Bad Reqeust 401 Unauthorized 409 Conflict 500 Internal Error :param Rucio-Account: Account identifier. :param Rucio-Auth-Token: as an 32 character hex string. :params Rucio-Type: the type of the new account. """ json_data = data() try: parameter = loads(json_data) except ValueError: raise generate_http_error( 400, 'ValueError', 'cannot decode json parameter dictionary') type, email = None, None try: type = parameter['type'] except KeyError as error: if error.args[0] == 'type': 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: email = parameter['email'] except KeyError as error: if 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(account, type, email, issuer=ctx.env.get('issuer')) except Duplicate as error: raise generate_http_error(409, 'Duplicate', error.args[0]) except AccessDenied as error: raise generate_http_error(401, 'AccessDenied', 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()
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()
def POST(self, account, name): """ Create a new subscription. HTTP Success: 201 Created HTTP Error: 400 Bad Request 401 Unauthorized 409 Conflict 500 Internal Error """ dry_run = 0 json_data = data() try: params = loads(json_data) params = params['options'] filter = params['filter'] replication_rules = params['replication_rules'] comments = params['comments'] lifetime = params['lifetime'] retroactive = params['retroactive'] dry_run = params['dry_run'] priority = params.get('priority', 3) or 3 except ValueError: raise generate_http_error(400, 'ValueError', 'Cannot decode json parameter list') try: subscription_id = add_subscription( name=name, account=account, filter=filter, replication_rules=replication_rules, comments=comments, lifetime=lifetime, retroactive=retroactive, dry_run=dry_run, priority=priority, issuer=ctx.env.get('issuer'), vo=ctx.env.get('vo')) except (InvalidObject, TypeError) as error: raise generate_http_error(400, 'InvalidObject', error.args[0]) except AccessDenied as error: raise generate_http_error(401, 'AccessDenied', error.args[0]) except SubscriptionDuplicate as error: raise generate_http_error(409, 'SubscriptionDuplicate', 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) raise Created(subscription_id)
def POST(self, scope, name): """ Create a new data identifier. HTTP Success: 200 OK HTTP Error: 401 Unauthorized 500 InternalError :param scope: Create the data identifier within this scope. :param name: Create the data identifier with this name. """ statuses, meta, rules, lifetime, dids, rse = {}, {}, [], None, [], None try: json_data = loads(data()) type = json_data['type'] if 'statuses' in json_data: statuses = json_data['statuses'] if 'meta' in json_data: meta = json_data['meta'] if 'rules' in json_data: rules = json_data['rules'] if 'lifetime' in json_data: lifetime = json_data['lifetime'] if 'dids' in json_data: dids = json_data['dids'] if 'rse' in json_data: rse = json_data['rse'] except ValueError: raise generate_http_error(400, 'ValueError', 'Cannot decode json parameter list') except KeyError as error: raise generate_http_error(400, 'ValueError', str(error)) try: add_did(scope=scope, name=name, type=type, statuses=statuses, meta=meta, rules=rules, lifetime=lifetime, dids=dids, rse=rse, issuer=ctx.env.get('issuer')) except DataIdentifierNotFound as error: raise generate_http_error(404, 'DataIdentifierNotFound', error.args[0]) except DuplicateContent as error: raise generate_http_error(409, 'DuplicateContent', 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 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()
def POST(self): """ Declare a list of bad replicas by DID. HTTP Success: 200 OK HTTP Error: 400 BadRequest 401 Unauthorized 409 Conflict 500 InternalError """ json_data = data() dids = [] rse = None reason = None expires_at = None header('Content-Type', 'application/x-json-stream') try: params = parse_response(json_data) if 'dids' in params: dids = params['dids'] if 'rse' in params: rse = params['rse'] if 'reason' in params: reason = params['reason'] state = BadFilesStatus.BAD if 'expires_at' in params and params['expires_at']: expires_at = datetime.strptime(params['expires_at'], "%Y-%m-%dT%H:%M:%S.%f") not_declared_files = add_bad_dids(dids=dids, rse=rse, issuer=ctx.env.get('issuer'), state=state, reason=reason, expires_at=expires_at, vo=ctx.env.get('vo')) except (ValueError, InvalidType) as error: raise generate_http_error(400, 'ValueError', error.args[0]) except AccessDenied as error: raise generate_http_error(401, 'AccessDenied', error.args[0]) except ReplicaNotFound as error: raise generate_http_error(404, 'ReplicaNotFound', 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(format_exc()) raise InternalError(error) raise Created(dumps(not_declared_files))
def POST(self, scope, name, key): """ Add metadata to a data identifier. HTTP Success: 201 Created HTTP Error: 400 Bad Request 401 Unauthorized 404 Not Found 409 Conflict 500 Internal Error :param scope: The scope name. :param name: The data identifier name. :param key: the key. """ json_data = data() try: params = loads(json_data) value = params['value'] recursive = params.get('recursive', False) except ValueError: raise generate_http_error(400, 'ValueError', 'Cannot decode json parameter list') try: set_metadata(scope=scope, name=name, key=key, value=value, issuer=ctx.env.get('issuer'), recursive=recursive, vo=ctx.env.get('vo')) except DataIdentifierNotFound as error: raise generate_http_error(404, 'DataIdentifierNotFound', error.args[0]) except Duplicate as error: raise generate_http_error(409, 'Duplicate', error.args[0]) except KeyNotFound as error: raise generate_http_error(400, 'KeyNotFound', error.args[0]) except InvalidMetadata as error: raise generate_http_error(400, 'InvalidMetadata', error.args[0]) except InvalidValueForKey as error: raise generate_http_error(400, 'InvalidValueForKey', 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()
def POST(self): """ Create file replicas at a given RSE. HTTP Success: 201 Created HTTP Error: 401 Unauthorized 405 Method Not Allowed 409 Conflict 500 Internal Error 503 Service Unavailable """ json_data = data() try: parameters = parse_response(json_data) except (ValueError, InvalidType): raise generate_http_error(400, 'ValueError', 'Cannot decode json parameter list') try: add_files(lfns=parameters['lfns'], issuer=ctx.env.get('issuer'), ignore_availability=parameters.get( 'ignore_availability', False)) except InvalidPath as error: raise generate_http_error(400, 'InvalidPath', error.args[0]) except AccessDenied as error: raise generate_http_error(401, 'AccessDenied', error.args[0]) except UnsupportedOperation as error: raise generate_http_error(405, 'UnsupportedOperation', error.args[0]) except Duplicate as error: raise generate_http_error(409, 'Duplicate', error.args[0]) except DataIdentifierAlreadyExists as error: raise generate_http_error(409, 'DataIdentifierAlreadyExists', error.args[0]) except RSENotFound as error: raise generate_http_error(404, 'RSENotFound', error.args[0]) except DatabaseException as error: raise generate_http_error(503, 'DatabaseException', error.args[0]) except ResourceTemporaryUnavailable as error: raise generate_http_error(503, 'ResourceTemporaryUnavailable', error.args[0]) except RucioException as error: print(format_exc()) raise generate_http_error(500, error.__class__.__name__, error.args[0]) except Exception as error: print(format_exc()) raise InternalError(error) raise Created()
def POST(self, rse, scheme): """ Create a protocol for a given RSE. HTTP Success: 201 Created HTTP Error: 400 Bad request 401 Unauthorized 404 Resource not Found 409 Conflict 500 Internal Error """ json_data = data() try: parameters = loads(json_data) except ValueError: raise generate_http_error( 400, 'ValueError', 'Cannot decode json parameter dictionary') # Fill defaults and check mandatory parameters parameters['scheme'] = scheme try: add_protocol(rse, issuer=ctx.env.get('issuer'), vo=ctx.env.get('vo'), data=parameters) except RSENotFound as error: raise generate_http_error(404, 'RSENotFound', error.args[0]) 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 InvalidObject as error: raise generate_http_error(400, 'InvalidObject', error.args[0]) except RSEProtocolDomainNotSupported as error: raise generate_http_error(404, 'RSEProtocolDomainNotSupported', error.args[0]) except RSEProtocolPriorityError as error: raise generate_http_error(409, 'RSEProtocolPriorityError', 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()
def POST(self): """ Declare a list of bad PFNs. HTTP Success: 200 OK HTTP Error: 400 BadRequest 401 Unauthorized 409 Conflict 500 InternalError """ json_data = data() pfns = [] reason = None state = None expires_at = None header('Content-Type', 'application/x-json-stream') try: params = parse_response(json_data) if 'pfns' in params: pfns = params['pfns'] if 'reason' in params: reason = params['reason'] if 'state' in params: state = params['state'] if 'expires_at' in params: expires_at = datetime.strptime(params['expires_at'], "%Y-%m-%dT%H:%M:%S.%f") add_bad_pfns(pfns=pfns, issuer=ctx.env.get('issuer'), state=state, reason=reason, expires_at=expires_at) except (ValueError, InvalidType) as error: raise generate_http_error(400, 'ValueError', error.args[0]) except AccessDenied as error: raise generate_http_error(401, 'AccessDenied', error.args[0]) except ReplicaNotFound as error: raise generate_http_error(404, 'ReplicaNotFound', 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(format_exc()) raise InternalError(error) raise Created()
def POST(self, key): """ Create a new allowed key (value is NULL). HTTP Success: 201 Created HTTP Error: 401 Unauthorized 404 Not Found 409 Conflict 500 Internal Error :param Rucio-Auth-Account: Account identifier. :param Rucio-Auth-Token: as an 32 character hex string. :params Rucio-Account: account belonging to the new scope. """ json_data = data().decode() try: params = json_data and loads(json_data) if params and 'value_type' in params: value_type = params['value_type'] if params and 'value_regexp' in params: value_regexp = params['value_regexp'] if params and 'key_type' in params: key_type = params['key_type'] except ValueError: raise generate_http_error(400, 'ValueError', 'Cannot decode json parameter list') try: add_key(key=key, key_type=key_type, value_type=value_type, value_regexp=value_regexp, issuer=ctx.env.get('issuer'), vo=ctx.env.get('vo')) except Duplicate as error: raise generate_http_error(409, 'Duplicate', error.args[0]) except UnsupportedValueType as error: raise generate_http_error(400, 'UnsupportedValueType', error.args[0]) except UnsupportedKeyType as error: raise generate_http_error(400, 'UnsupportedKeyType', 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) raise Created()
def POST(self, input_scope, input_name, output_scope, output_name, nbfiles): """ Return the file associated to a GUID. HTTP Success: 201 Created HTTP Error: 401 Unauthorized 404 Not Found 409 Conflict 500 Internal Error :param input_scope: The scope of the input DID. :param input_name: The name of the input DID. :param output_scope: The scope of the output dataset. :param output_name: The name of the output dataset. :param nbfiles: The number of files to register in the output dataset. """ try: create_did_sample(input_scope=input_scope, input_name=input_name, output_scope=output_scope, output_name=output_name, issuer=ctx.env.get('issuer'), nbfiles=nbfiles, vo=ctx.env.get('vo')) except DataIdentifierNotFound as error: raise generate_http_error(404, 'DataIdentifierNotFound', error.args[0]) except DuplicateContent as error: raise generate_http_error(409, 'DuplicateContent', 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 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()
def POST(self, account, rse): """ Create or update an account limit. HTTP Success: 201 Created HTTP Error: 400 Bad Request 401 Unauthorized 404 Not Found 500 Internal Error :param X-Rucio-Auth-Account: Account identifier. :param X-Rucio-Auth-Token: As an 32 character hex string. :param account: Account name. :param rse: RSE name. """ json_data = data() try: parameter = loads(json_data) except ValueError: raise generate_http_error( 400, 'ValueError', 'cannot decode json parameter dictionary') try: bytes = parameter['bytes'] except KeyError as exception: if exception.args[0] == 'type': raise generate_http_error(400, 'KeyError', '%s not defined' % str(exception)) except TypeError: raise generate_http_error(400, 'TypeError', 'body must be a json dictionary') try: set_local_account_limit(account=account, rse=rse, bytes=bytes, issuer=ctx.env.get('issuer'), vo=ctx.env.get('vo')) except AccessDenied as exception: raise generate_http_error(401, 'AccessDenied', exception.args[0]) except RSENotFound as exception: raise generate_http_error(404, 'RSENotFound', exception.args[0]) except AccountNotFound as exception: raise generate_http_error(404, 'AccountNotFound', exception.args[0]) except Exception as exception: print(format_exc()) raise InternalError(exception) raise Created()
def POST(self): """ Create a new Lifetime Model exception. HTTP Success: 201 Created HTTP Error: 400 Bad Request 401 Unauthorized 409 Conflict 500 Internal Error """ json_data = data() dids, pattern, comments, expires_at = [], None, None, None try: params = loads(json_data) if 'dids' in params: dids = params['dids'] if 'pattern' in params: pattern = params['pattern'] if 'comments' in params: comments = params['comments'] if 'expires_at' in params: expires_at = params['expires_at'] except ValueError: raise generate_http_error(400, 'ValueError', 'Cannot decode json parameter list') try: exception_id = add_exception(dids=dids, account=ctx.env.get('issuer'), vo=ctx.env.get('vo'), pattern=pattern, comments=comments, expires_at=expires_at) except InvalidObject as error: raise generate_http_error(400, 'InvalidObject', error.args[0]) except AccessDenied as error: raise generate_http_error(401, 'AccessDenied', error.args[0]) except LifetimeExceptionDuplicate as error: raise generate_http_error(409, 'LifetimeExceptionDuplicate', 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) raise Created(dumps(exception_id))
def POST(self, account, key): """ Add attributes to an account. HTTP Success: 201 Created HTTP Error: 400 Bad Reqeust 401 Unauthorized 409 Conflict 500 Internal Error :param account: Account identifier. """ json_data = data() try: parameter = loads(json_data) except ValueError: raise generate_http_error( 400, 'ValueError', 'cannot decode json parameter dictionary') try: key = parameter['key'] value = parameter['value'] except KeyError as error: if error.args[0] == 'key' or error.args[0] == 'value': 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_attribute(key=key, value=value, account=account, issuer=ctx.env.get('issuer'), vo=ctx.env.get('vo')) 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 Exception as error: print(str(format_exc())) raise InternalError(error) raise Created()