nexuscli package¶
Subpackages¶
Submodules¶
nexuscli.exception module¶
-
class
nexuscli.exception.CliReturnCode¶ Bases:
enum.EnumError codes returned by
nexuscli.cli-
API_ERROR= 2¶
-
CONNECTION_ERROR= 3¶
-
DOWNLOAD_ERROR= 4¶
-
INVALID_CREDENTIALS= 5¶
-
INVALID_SUBCOMMAND= 10¶
-
NO_FILES= 1¶
-
POLICY_NOT_FOUND= 20¶
-
REPOSITORY_NOT_FOUND= 30¶
-
SUBCOMMAND_ERROR= 11¶
-
SUCCESS= 0¶
-
UNKNOWN_ERROR= 99¶
-
-
exception
nexuscli.exception.DownloadError(message)¶ Bases:
nexuscli.exception.NexusClientBaseErrorError retrieving artefact from Nexus service.
-
exit_code= 4¶
-
-
exception
nexuscli.exception.NexusClientAPIError(message)¶ Bases:
nexuscli.exception.NexusClientBaseErrorUnexpected response from Nexus service.
-
exit_code= 2¶
-
-
exception
nexuscli.exception.NexusClientBaseError(message)¶ Bases:
click.exceptions.ClickException-
exit_code= 99¶
-
-
exception
nexuscli.exception.NexusClientConnectionError(message)¶ Bases:
nexuscli.exception.NexusClientBaseErrorGeneric network connector error.
-
exit_code= 3¶
-
-
exception
nexuscli.exception.NexusClientCreateCleanupPolicyError(message)¶ Bases:
nexuscli.exception.NexusClientBaseErrorUsed when a cleanup policy creation operation in Nexus fails.
-
exit_code= 11¶
-
-
exception
nexuscli.exception.NexusClientCreateRepositoryError(message)¶ Bases:
nexuscli.exception.NexusClientBaseErrorUsed when a repository creation operation in Nexus fails.
-
exit_code= 11¶
-
-
exception
nexuscli.exception.NexusClientInvalidCleanupPolicy(message)¶ Bases:
nexuscli.exception.NexusClientBaseErrorThe given cleanup policy does not exist in Nexus.
-
exit_code= 11¶
-
-
exception
nexuscli.exception.NexusClientInvalidCredentials(message)¶ Bases:
nexuscli.exception.NexusClientBaseErrorLogin credentials not accepted by Nexus service. Usually the result of a HTTP 401 response.
-
exit_code= 5¶
-
-
exception
nexuscli.exception.NexusClientInvalidRepository(message)¶ Bases:
nexuscli.exception.NexusClientBaseErrorThe given repository does not exist in Nexus.
-
exit_code= 30¶
-
-
exception
nexuscli.exception.NexusClientInvalidRepositoryPath(message)¶ Bases:
nexuscli.exception.NexusClientBaseErrorUsed when an operation against the Nexus service uses an invalid or non-existent path.
nexuscli.nexus_client module¶
-
class
nexuscli.nexus_client.NexusClient(config=None)¶ Bases:
objectA class to interact with Nexus 3’s API.
Unless all keyword arguments
url,userandpasswordare supplied, the class will attempt to read the configuration file and, if unsuccessful, use defaults.- Parameters
config (NexusConfig) – instance containing the configuration for the Nexus service used by this instance.
-
property
cleanup_policies¶ Instance of
CleanupPolicyCollection. This will automatically use the existing instance ofNexusClientto communicate with the Nexus service.
-
delete(repository_path)¶ Delete artefacts, recursively if
repository_pathis a directory.
-
download(source, destination, flatten=False, nocache=False)¶ Process a download. The source must be a valid Nexus 3 repository path, including the repository name as the first component of the path.
The destination must be a local file name or directory.
If a file name is given as destination, the asset may be renamed. The final destination will depend on
flatten.- Parameters
source (str) – location of artefact or directory on the repository service.
destination (str) – path to the local file or directory.
flatten (bool) – if True, the remote path isn’t reproduced locally.
nocache (bool) – if True, force download of a directory or artefact, ignoring an existing local copy. If false, it will not re-download an existing copy if its checksum matches the one in Nexus (as determined by
nexuscli.nexus_util.has_same_hash()).
- Returns
number of downloaded files.
- Return type
-
download_file(download_url, destination)¶ Download an asset from Nexus artefact repository to local file system.
-
http_delete(endpoint, **kwargs)¶ Performs a HTTP DELETE request on the given endpoint.
- Parameters
endpoint (str) – name of the Nexus REST API endpoint.
kwargs – as per
requests.request().
- Return type
-
http_get(endpoint)¶ Performs a HTTP GET request on the given endpoint.
- Parameters
endpoint (str) – name of the Nexus REST API endpoint.
- Return type
-
http_head(endpoint)¶ Performs a HTTP HEAD request on the given endpoint.
- Parameters
endpoint (str) – name of the Nexus REST API endpoint.
- Return type
-
http_post(endpoint, **kwargs)¶ Performs a HTTP POST request on the given endpoint.
- Parameters
endpoint (str) – name of the Nexus REST API endpoint.
kwargs – as per
requests.request().
- Return type
-
http_put(endpoint, **kwargs)¶ Performs a HTTP PUT request on the given endpoint.
- Parameters
endpoint (str) – name of the Nexus REST API endpoint.
kwargs – as per
requests.request().
- Return type
-
http_request(method, endpoint, service_url=None, **kwargs)¶ Performs a HTTP request to the Nexus REST API on the specified endpoint.
- Parameters
method – one of
get,put,post,delete.endpoint (str) – URI path to be appended to the service URL.
service_url (str) – override the default URL to use for the request, which is created by joining
rest_urlandendpoint.kwargs – as per
requests.request().
- Return type
-
list(repository_path)¶ List all the artefacts, recursively, in a given
repository_path.- Parameters
repository_path (str) – location on the repository service.
- Returns
artefacts under
repository_path.- Return type
-
list_raw(repository_path)¶ As per
list()but yields raw Nexus artefacts as dicts.- Parameters
repository_path (str) – location on the repository service.
- Return type
-
property
repositories¶ Instance of
RepositoryCollection. This will automatically use the existing instance ofNexusClientto communicate with the Nexus service.- Return type
-
property
rest_url¶ Full URL to the Nexus REST API, based on the
urlandversionfromconfig.- Return type
-
property
scripts¶ Instance of
ScriptCollection. This will automatically use the existing instance ofNexusClientto communicate with the Nexus service.
-
property
server_version¶ Parse the Server header from a Nexus request response and return as version information. The method expects the header Server to be present and formatted as, e.g., ‘Nexus/3.19.1-01 (OSS)’
- Returns
the parsed version. If it can’t be determined, return None.
- Return type
Union[None,semver.VersionInfo]
-
split_component_path(component_path)¶ Splits a given component path into repository, directory, filename.
A Nexus component path for a raw directory must have this format:
repository_name/directory[(/subdir1)...][/|filename]A path ending in
/represents a directory; otherwise it represents a filename.>>> dst0 = 'myrepo0/dir/' >>> dst1 = 'myrepo1/dir/subdir/' >>> dst2 = 'myrepo2/dir/subdir/file' >>> dst3 = 'myrepo3/dir/subdir/etc/file.ext' >>> split_component_path(dst0) >>> ('myrepo0', 'dir', None) >>> split_component_path(dst1) >>> ('myrepo1', 'dir/subdir', None) >>> split_component_path(dst2) >>> ('myrepo2', 'dir/subdir', 'file') >>> split_component_path(dst3) >>> ('myrepo3', 'dir/subdir/etc', 'file.ext')
-
upload(source, destination, recurse=True, flatten=False)¶ Process an upload. The source must be either a local file name or directory. The flatten and recurse options are honoured for directory uploads.
The destination must be a valid Nexus 3 repository path, including the repository name as the first component of the path.
- Parameters
source (str) – location of file or directory to be uploaded.
destination (str) – destination path in Nexus, including repository name and, if required, directory name (e.g. raw repos require a directory).
recurse (bool) – do not process sub directories for uploads to remote
flatten (bool) – Flatten directory structure by not reproducing local directory structure remotely
- Returns
number of files uploaded.
nexuscli.nexus_config module¶
-
class
nexuscli.nexus_config.NexusConfig(username='admin', password='', url='http://localhost:8081', x509_verify=True, api_version='v1', config_path=None)¶ Bases:
objectA class to hold Nexus 3’s configuration.
Unless keyword arguments
url,userandpasswordare supplied, the class will attempt to read the configuration file and, if unsuccessful, use defaults.- Parameters
username (str) – username for Nexus service at given url.
password (str) – password for username above.
url (str) – URL to Nexus 3 OSS service.
x509_verify (bool) – toggle certificate validation.
api_version (str) – Nexus REST API version to be used.
config_path (str) – local file containing configuration above in JSON format with these keys:
nexus_url,nexus_user,nexus_passandnexus_verify.
-
property
config_file¶ Path to configuration file, as given by
config_pathduring instantiation.- Return type
-
dump()¶ Writes the current configuration to disk under property:config_file.
If a file already exists, it will be overwritten. The permission will be set to read/write to the owner only.
-
load()¶ Load the configuration settings from the file specified by
config_file.The configuration file is in JSON format and expects these keys:
nexus_user,nexus_pass,nexus_url,nexus_verify.
nexuscli.nexus_util module¶
-
nexuscli.nexus_util.calculate_hash(hash_name, file_path_or_handle)¶ Calculate a hash for the given file.
-
nexuscli.nexus_util.ensure_exists(path, is_dir=False)¶ Ensures a path exists.
- Parameters
path (pathlib.Path) – the path to ensure
is_dir (bool) – whether the path is a directory.
-
nexuscli.nexus_util.filtered_list_gen(raw_response, term=None, partial_match=True)¶ - Iterates over items yielded by raw_response_gen, validating that:
the path dict key is a str
the path value starts with starts_with (if provided)
>>> r = [{ >>> 'checksum': { >>> 'md5': 'd94b865aa7620c46ef8faef7059a311c', >>> 'sha1': '2186934d880cf24dd9ecc578335e290026695522', >>> 'sha256': 'b7bb3424a6a6(...)4113bc38fd7807528481a8ffe3cf', >>> 'sha512': 'e7806f3caa3e(...)3caeb9bbc54bbde286c07f837fdc' >>> }, >>> 'downloadUrl': 'http://nexus/repository/repo_name/a/file.ext', >>> 'format': 'yum', >>> 'id': 'Y2xvdWRlcmEtbWFuYWdlcj(...)mRiNWU0YjllZWQzMg', >>> 'path': 'a/fake.rpm', >>> 'repository': 'cloudera-manager'}] >>> >>> for i in filtered_list_gen(r, starts_with='a/fake.rpm') >>> print(i['path']) a/fake.rpm >>> for i in filtered_list_gen(r, starts_with='b') >>> print(i['path']) # (nothing printed)
- Parameters
raw_response (iterable) – an iterable that yields one element of a nexus search response at a time, such as the one returned by _paginate_get().
term (str) – if defined, only items with an attribute path that starts with the given parameter are returned.
partial_match (bool) – if True, include items whose artefact path starts with the given term.
- Yields
dict – items that matched the filter.
-
nexuscli.nexus_util.groovy_script(script_name)¶ Returns the content for a groovy script located in the package installation path under script/groovy.
E.g.: groovy_script(‘foo’) returns the content for the file at
.../site-packages/nexuscli/script/groovy/foo.groovy.- Parameters
script_name – file name of the groovy script;
.groovyis appended to this parameter to form the file name.- Returns
content for the groovy script
- Return type
-
nexuscli.nexus_util.has_same_hash(artefact, filepath)¶ Checks if a Nexus artefact has the same hash as a local filepath.
- Parameters
artefact (dict) – as returned by
list_raw()filepath – local file path
- Returns
True if artefact and filepath have the same hash.
- Return type