def GET(self, scope): """ Return all data identifiers in the given scope. HTTP Success: 200 OK HTTP Error: 401 Unauthorized 406 Not Acceptable 404 Not Found :param scope: The scope name. """ header('Content-Type', 'application/x-json-stream') name = None recursive = False if ctx.query: params = parse_qs(ctx.query[1:]) if 'name' in params: name = params['name'][0] if 'recursive' in params: recursive = True try: for did in scope_list(scope=scope, name=name, recursive=recursive): yield render_json(**did) + '\n' except DataIdentifierNotFound as error: raise generate_http_error(404, 'DataIdentifierNotFound', error.args[0]) except Exception as error: print(format_exc()) raise InternalError(error)
def test_api_did(self): """ DID (API): Test external representation of DIDs """ # add some dids add_did(self.scope_name, 'ext_parent', 'container', issuer='root', account=self.account_name, **self.vo) add_did(self.scope_name, 'ext_child', 'dataset', issuer='root', account=self.account_name, **self.vo) attachment = {'scope': self.scope_name, 'name': 'ext_parent', 'dids': [{'scope': self.scope_name, 'name': 'ext_child', 'type': 'DATASET'}]} attach_dids_to_dids([attachment], issuer='root', **self.vo) # test scope_list out = scope_list(self.scope_name, recursive=True, **self.vo) out = list(out) assert_not_equal(0, len(out)) parent_found = False for did in out: assert_equal(did['scope'], self.scope_name) if did['parent'] is not None: parent_found = True assert_equal(did['parent']['scope'], self.scope_name) assert_true(parent_found) # test get_did add_did_to_followed(self.scope_name, 'ext_parent', self.account_name, **self.vo) out = get_users_following_did('ext_parent', self.scope_name, **self.vo) out = list(out) assert_not_equal(0, len(out)) for user in out: assert_equal(user['user'], self.account_name)
def get(self, scope): """ Return all data identifiers in the given scope. .. :quickref: Scopes; List all dids for scope **Example request**: .. sourcecode:: http GET /dids/scope1/?name=container1&recursive HTTP/1.1 Host: rucio.cern.ch **Example response**: .. sourcecode:: http HTTP/1.1 200 OK Vary: Accept Content-Type: application/x-json-stream {"scope": "scope1", "type": "CONTAINER", "name": "container1", "parent": null, "level": 0} {"scope": "scope1", "type": "DATASET", "name": "dataset1", "parent": {"scope": "scope1", "name": "container1"}, "level": 1} {"scope": "scope1", "type": "FILE", "name": "file1", "parent": {"scope": "scope1", "name": "dataset1"}, "level": 2} :query name: specify a DID name :query recursive: flag to do a recursive search :resheader Content-Type: application/x-json-stream :status 200: DIDs found :status 401: Invalid Auth Token :status 404: no DIDs found in scope :status 406: Not Acceptable :returns: Line separated dictionaries of DIDs """ name = request.args.get('name', None) recursive = False if 'recursive' in request.args: recursive = True try: data = "" for did in scope_list(scope=scope, name=name, recursive=recursive): data += render_json(**did) + '\n' return Response(data, content_type='application/x-json-stream') except DataIdentifierNotFound as error: return generate_http_error_flask(404, 'DataIdentifierNotFound', error.args[0]) except Exception as error: print(format_exc()) return error, 500
def test_api_did(self): """ DID (API): Test external representation of DIDs """ # add some dids ext_parent = did_name_generator('container') ext_child = did_name_generator('dataset') add_did(self.scope_name, ext_parent, 'container', issuer='root', account=self.account_name, **self.vo) add_did(self.scope_name, ext_child, 'dataset', issuer='root', account=self.account_name, **self.vo) attachment = { 'scope': self.scope_name, 'name': ext_parent, 'dids': [{ 'scope': self.scope_name, 'name': ext_child, 'type': 'DATASET' }] } attach_dids_to_dids([attachment], issuer='root', **self.vo) # test scope_list out = scope_list(self.scope_name, recursive=True, **self.vo) out = list(out) assert 0 != len(out) parent_found = False for did in out: assert did['scope'] == self.scope_name if did['parent'] is not None: parent_found = True assert did['parent']['scope'] == self.scope_name assert parent_found # test get_did add_did_to_followed(self.scope_name, ext_parent, self.account_name, **self.vo) out = get_users_following_did(ext_parent, self.scope_name, **self.vo) out = list(out) assert 0 != len(out) for user in out: assert user['user'] == self.account_name
def generate(name, recursive, vo): for did in scope_list(scope=scope, name=name, recursive=recursive, vo=vo): yield render_json(**did) + '\n'