def fetch(org_label: str, project_label: str, file_id: str, rev: Optional[int] = None, tag: Optional[str] = None, out_filepath: Optional[str] = None) -> Dict: """ Fetches a distant file and returns the metadata of this file. In addition, if the argument `out_filepath` can be of three forms: - out_filepath=None (default): the binary is not fetched - out_filepath="./some/folder/" the binary is fetched and written in this dir with it's original filename - out_filepath="./somefile.jpg" the binary is fetched and written under this exact filename In case of error, an exception is thrown. :param org_label: The label of the organization that the file belongs to :param project_label: The label of the project that the file belongs to :param file_id: id of the file :param rev: OPTIONAL fetches a specific revision of a file (default: None, fetches the last) :param tag: OPTIONAL fetches the file version that has a specific tag (default: None) :param out_filepath: OPTIONAL the filename to write (default: None) :return: Payload of the whole file as a dictionary """ if rev is not None and tag is not None: raise Exception( "The arguments rev and tag are mutually exclusive. One or the other must be chosen." ) # the elements composing the query URL need to be URL-encoded org_label = url_encode(org_label) project_label = url_encode(project_label) file_id = url_encode(file_id) path = [SEGMENT, org_label, project_label, file_id] response_metadata = http_get(path, rev=rev, tag=tag) response_binary = http_get(path, get_raw_response=True, accept="all", stream=True, rev=rev, tag=tag) if out_filepath is not None: if os.path.isdir(out_filepath): out_filepath = os.path.join(out_filepath, response_metadata["_filename"]) # we write the result of the request into a file with open(out_filepath, "wb") as f: for chunk in response_binary.iter_content(): f.write(chunk) return response_metadata
def list_(endpoint: str) -> Dict: """List realms (full path version). :param endpoint: Endpoint for realms. :return: A Nexus results list with the Nexus payloads of the realms. """ return http_get(endpoint)
def fetch(org_label, project_label, schema_id, rev=None, tag=None): """ Fetches a distant schema and returns the payload as a dictionary. In case of error, an exception is thrown. :param org_label: The label of the organization that the resource belongs to :param project_label: The label of the project that the resource belongs to :param schema_id: id of the schema :param rev: OPTIONAL fetches a specific revision of a schema (default: None, fetches the last) :param tag: OPTIONAL fetches the schema version that has a specific tag (default: None) :return: Payload of the whole schema as a dictionary """ if rev is not None and tag is not None: raise Exception( "The arguments rev and tag are mutually exclusive. One or the other must be chosen." ) org_label = url_encode(org_label) project_label = url_encode(project_label) schema_id = url_encode(schema_id) path = "/schemas/" + org_label + "/" + project_label + "/" + schema_id if rev is not None: path = path + "?rev=" + str(rev) if tag is not None: path = path + "?tag=" + str(tag) return http_get(path, use_base=True)
def fetch(rev: int = None) -> Dict: """Fetch the permissions. :param rev: (optional) Revision number of the permissions. :return: A Nexus payload with the permissions. """ return http_get([SEGMENT], rev=rev)
def list(org_label: str, project_label: str, pagination_from: int = None, pagination_size: int = None, deprecated: bool = None, type: str = None, created_by: str = None, updated_by: str = None, rev: int = None) -> Dict: """List resolvers corresponding to some criteria. :param org_label: Label of the organization the resolver belongs to. :param project_label: Label of the project the resolver belongs to. :param pagination_from: (optional) Pagination index to start from. Default: ``0``. :param pagination_size: (optional) Number of results to return per page. Default: ``20``. :param deprecated: (optional) Deprecation status of the resolvers to keep. :param type: (optional) Type of the resolvers to keep, given as an IRI. :param created_by: (optional) Identity ID of the creator of the resolvers to keep, given as an IRI. :param updated_by: (optional) Identity ID of the last identity which has updated the resolvers to keep, given as en IRI. :param rev: (optional) Revision number of the resolvers to keep. :return: A Nexus results list with the Nexus metadata of the matching resolvers. """ params = _params(pagination_from, pagination_size, deprecated, type, created_by, updated_by, rev) return http_get([SEGMENT, org_label, project_label], params=params)
def fetch(org_label, project_label, view_id, rev=None, tag=None): """ Fetches a distant view and returns the payload as a dictionary. In case of error, an exception is thrown. :param org_label: The label of the organization that the view belongs to :param project_label: The label of the project that the view belongs to :param view_id: id of the view :param rev: OPTIONAL fetches a specific revision of a view (default: None, fetches the last) :param tag: OPTIONAL fetches the view version that has a specific tag (default: None) :return: Payload of the whole view as a dictionary """ if rev is not None and tag is not None: raise Exception( "The arguments rev and tag are mutually exclusive. One or the other must be chosen." ) # the element composing the query URL need to be URL-encoded org_label = url_encode(org_label) project_label = url_encode(project_label) view_id = url_encode(view_id) path = "/views/" + org_label + "/" + project_label + "/" + view_id if rev is not None: path = path + "?rev=" + str(rev) if tag is not None: path = path + "?tag=" + str(tag) return http_get(path, use_base=True)
def fetch(subpath: str, rev: int = None) -> Dict: """Fetch a realm. :param subpath: Subpath of the realm. :param rev: (optional) Revision number of the realm. :return: The Nexus payload of the fetched realm. """ return http_get([SEGMENT, subpath], rev=rev)
def fetch_(endpoint: str, rev: int = None) -> Dict: """Fetch the permissions (full path version). :param endpoint: Endpoint for permissions. :param rev: (optional) Revision number of the permissions. :return: A Nexus payload with the permissions. """ return http_get(endpoint, rev=rev)
def fetch_(path: str, rev: int = None) -> Dict: """Fetch a realm (full path version). :param path: Full path of the realm. :param rev: (optional) Revision number of the realm. :return: The Nexus payload of the fetched realm. """ return http_get(path, rev=rev)
def tags(org_label: str, project_label: str, storage_id: str) -> Dict: """Fetch tags for storage. :param org_label: Label of the organization the storage belongs to. :param project_label: Label of the project the storage belongs to. :param storage_id: the storage ID :return: The tags for the storage. """ return http_get([SEGMENT, org_label, project_label, url_encode(storage_id), "tags"])
def tags(resource): """ List all the tags added to this resource, along with their version numbers :param resource: payload of a previously fetched resource :return: payload containing the list of tags and versions """ path = resource["_self"] + "/tags" return http_get(path, use_base=False)
def tags(file: Dict) -> Dict: """ List all the tags added to this file, along with their version numbers :param file: Payload of a previously fetched file. :return: payload containing the list of tags and versions """ path = file["_self"] + "/tags" return http_get(path)
def fetch_(path: str, rev: int = None, self: bool = True) -> Dict: """Fetch the ACLs on a full path. :param path: Full path on which fetching the ACLs. :param rev: (optional) Revision number of the ACLs. :param self: (optional) If 'True', only the ACLs containing the identities found in the authentication token are returned. If 'False', all the ACLs on the current subpath are returned. :return: A Nexus results list with the Nexus payloads of the ACLs. """ return http_get(path, rev=rev, self=self)
def fetch(org_label: str, project_label: str, storage_id: str, tag: Optional[str] = None, rev: Optional[int] = None) -> Dict: """Fetch a storage :param org_label: Label of the organization the storage belongs to. :param project_label: Label of the project the storage belongs to. :param storage_id: the storage ID :param tag: tag to fetch :param rev: revision to fetch :return: storage payload """ return http_get([SEGMENT, org_label, project_label, url_encode(storage_id)], rev=rev, tag=tag)
def fetch_(path: str, tag: str = None, rev: int = None) -> Dict: """Fetch a resolver (full path version). Raise an ``Exception`` if ``rev`` and ``tag`` are used together. :param path: Full path of the resolver (i.e. includes its ID), URL encoded. :param tag: (optional) Tag of the resolver. :param rev: (optional) Revision number of the resolver. :return: The Nexus payload of the fetched resolver. """ _check(rev, tag) return http_get(path, rev=rev, tag=tag)
def stats(org_label: str, project_label: str, view_id: str) -> Dict: """ Fetch indexing statistics for a view. :param org_label: Label of the organization the view belongs to. :param project_label: Label of the project the view belongs to. :param view_id: ID of the view. :return: the view's indexing statistics. """ return http_get( ["views", org_label, project_label, url_encode(view_id), "statistics"])
def list_(path: str, ancestors: bool = False, self: bool = True) -> Dict: """List ACLs on a full path. :param path: Full path on which listing the ACLs. :param ancestors: (optional) If 'True', the ACLs on the parent path of the subpath are returned. If 'False', only the ACLs on the current subpath are returned. :param self: (optional) If 'True', only the ACLs containing the identities found in the authentication token are returned. If 'False', all the ACLs on the current subpath are returned. :return: A Nexus results list with the Nexus payloads of the ACLs. """ return http_get(path, ancestors=ancestors, self=self)
def list(org_label, project_label, pagination_from=0, pagination_size=20, deprecated=None, type=None, rev=None, schema=None, created_by=None, updated_by=None, resource_id=None): """ List the resources available for a given organization and project. :param org_label: The label of the organization that the resource belongs to :param project_label: The label of the project that the resource belongs to :param schema: OPTIONAL Lists only the resource for a given schema (default: None) :param pagination_from: OPTIONAL The pagination index to start from (default: 0) :param pagination_size: OPTIONAL The maximum number of elements to returns at once (default: 20) :param deprecated: OPTIONAL Get only deprecated resource if True and get only non-deprecated results if False. If not specified (default), return both deprecated and not deprecated resource. :param type: OPTIONAL Lists only the resource for a given type (default: None) :param rev: OPTIONAL List only the resource with this particular revision :param created_by: OPTIONAL List only the resources created by a certain user :param updated_by: OPTIONAL List only the resources that were updated by a certain user :param resource_id: OPTIONAL List only the resources with this id. Relevant only when combined with other args :return: The raw payload as a dictionary """ org_label = url_encode(org_label) project_label = url_encode(project_label) path = "/resources/" + org_label + "/" + project_label # if schema: # schema = url_encode(schema) # path = path + "/" + schema params = { "from": pagination_from, "size": pagination_size, "type": type, "deprecated": deprecated, "rev": rev, "schema": schema, "created_by": created_by, "updated_by": updated_by, "id": resource_id } return http_get(path, use_base=True, params=params)
def list(pagination_from=0, pagination_size=20): """ NOT WORKING List all the organizations. :param pagination_from: OPTIONAL Index of the list to start from (default: 0) :param pagination_size: OPTIONAL Size of the list (default: 20) :return: The payload from the Nexus API as a dictionary. This contains the Nexus metadata of the organization """ path = "/orgs?from=" + str(pagination_from) + "&size=" + str( pagination_size) return http_get(path, use_base=True)
def fetch(org_label, rev=None): """ Fetch an organization. :param org_label: The label of the organization :param rev: OPTIONAL The specific revision of the wanted organization. If not provided, will get the last :return: All the details of this organization, as a dictionary """ org_label = url_encode(org_label) path = "/orgs/" + org_label if rev is not None: path = path + "?rev=" + str(rev) return http_get(path, use_base=True)
def list(org_label: str, project_label: str, pagination_from: int = 0, pagination_size: int = 20, deprecated: Optional[bool] = None, type: Optional[str] = None, rev: Optional[int] = None, schema: Optional[str] = None, created_by: Optional[str] = None, updated_by: Optional[str] = None, file_id: Optional[str] = None) -> Dict: """ List the files available for a given organization and project. :param org_label: The label of the organization that the file belongs to :param project_label: The label of the project that the file belongs to :param pagination_from: OPTIONAL The pagination index to start from (default: 0) :param pagination_size: OPTIONAL The maximum number of elements to returns at once (default: 20) :param deprecated: OPTIONAL Get only deprecated file if True and get only non-deprecated results if False. If not specified (default), return both deprecated and not deprecated file. :param type: OPTIONAL Lists only the file for a given type (default: None) :param rev: OPTIONAL List only the resource with this particular revision :param schema: OPTIONAL list only the views with a certain schema :param created_by: OPTIONAL List only the file created by a certain user :param updated_by: OPTIONAL List only the file that were updated by a certain user :param file_id: OPTIONAL List only the file with this id. Relevant only when combined with other args :return: The raw list payload as a dictionary """ org_label = url_encode(org_label) project_label = url_encode(project_label) path = [SEGMENT, org_label, project_label] params = { "from": pagination_from, "size": pagination_size, "type": type, "deprecated": deprecated, "rev": rev, "schema": schema, "created_by": created_by, "updated_by": updated_by, "id": file_id } return http_get(path, params=params)
def fetch(org_label, project_label, rev=None): """ Fetch a project and all its details. Note: This does not give the list of resources. To get that, use the `resource` package. :param org_label: The label of the organization that contains the project to be fetched :param project_label: label of a the project to fetch :param rev: OPTIONAL The specific revision of the wanted project. If not provided, will get the last. :return: All the details of this project, as a dictionary """ org_label = url_encode(org_label) project_label = url_encode(project_label) path = "/projects/" + org_label + "/" + project_label if rev is not None: path = path + "?rev=" + str(rev) return http_get(path, use_base=True)
def fetch(org_label: str, project_label: str, id: str, tag: str = None, rev: int = None) -> Dict: """Fetch a resolver. Raise an ``Exception`` if ``rev`` and ``tag`` are used together. :param org_label: Label of the organization the resolver belongs to. :param project_label: Label of the project the resolver belongs to. :param id: ID of the resolver, given as an IRI which is not URL encoded. :param tag: (optional) Tag of the resolver. :param rev: (optional) Revision number of the resolver. :return: The Nexus payload of the fetched resolver. """ _check(rev, tag) encoded_id = encode_url(id) return http_get([SEGMENT, org_label, project_label, encoded_id], rev=rev, tag=tag)
def list(org_label, project_label, pagination_from=0, pagination_size=20, deprecated=None, full_text_search_query=None): """ List all the schemas available. :param org_label: Label of the organization to which listing the schema :param project_label: Label of the project to which listing the schema :param pagination_from: OPTIONAL The pagination index to start from (default: 0) :param pagination_size: OPTIONAL The maximum number of elements to returns at once (default: 20) :param deprecated: OPTIONAL Get only deprecated resource if True and get only non-deprecated results if False. If not specified (default), return both deprecated and not deprecated resource. :param full_text_search_query: A string to look for as a full text query :return: The raw payload as a dictionary :return: List of schema and some Nexus metadata """ org_label = url_encode(org_label) project_label = url_encode(project_label) path = "/schemas/" + org_label + "/" + project_label path = path + "?from=" + str(pagination_from) + "&size=" + str( pagination_size) if deprecated is not None: deprecated = "true" if deprecated else "false" path = path + "&deprecated=" + deprecated if full_text_search_query: full_text_search_query = url_encode(full_text_search_query) path = path + "&q=" + full_text_search_query return http_get(path, use_base=True)
def list(org_label=None, pagination_from=0, pagination_size=20, deprecated=None, full_text_search_query=None): """ List all the projects. If the arguments org_label is provided, this will list only the projects of this given organization. If not provided, all the projects from all organizations will be listed. :param org_label: OPTIONAL get only the list of project for this given organization :param pagination_from: OPTIONAL Index of the list to start from (default: 0) :param pagination_size: OPTIONAL Size of the list (default: 20) :param deprecated: OPTIONAL Lists only the deprecated if True, lists only the non-deprecated if False, lists everything if not provided or None (default: None) :param full_text_search_query: OPTIONAL List only the projects that match this query :return: The payload from the Nexus API as a dictionary. This contains the Nexus metadata and the list of projects """ path = "/projects" if org_label is not None: org_label = url_encode(org_label) path = path + "/" + org_label path = path + "?from=" + str(pagination_from) + "&size=" + str( pagination_size) if deprecated is not None: deprecated = "true" if deprecated else "false" path = path + "&deprecated=" + deprecated if full_text_search_query is not None: full_text_search_query = url_encode(full_text_search_query) path = path + "&q=" + full_text_search_query return http_get(path, use_base=True)
def fetch() -> Dict: """Fetch the identities. :return: A list with the Nexus payloads of the identities. """ return http_get([SEGMENT])
def list() -> Dict: """List realms. :return: A Nexus results list with the Nexus payloads of the realms. """ return http_get([SEGMENT])
def fetch_(endpoint: str) -> Dict: """Fetch the identities (full path version). :return: A list with the Nexus payloads of the identities. """ return http_get(endpoint)