nexuscli.api.repository package

Submodules

nexuscli.api.repository.collection module

class nexuscli.api.repository.collection.RepositoryCollection(client=None)

Bases: object

A class to manage Nexus 3 repositories.

Parameters

client (nexuscli.nexus_client.NexusClient) – the client instance that will be used to perform operations against the Nexus 3 service. You must provide this at instantiation or set it before calling any methods that require connectivity to Nexus.

create(repository)

Creates a Nexus repository with the given format and type.

Parameters

repository (Repository) – the instance containing the settings for the repository to be created.

Raises

NexusClientCreateRepositoryError – error creating repository.

delete(name)

Delete a repository.

Parameters

name (str) – name of the repository to be deleted.

get_by_name(name)

Get a Nexus 3 repository by its name.

Parameters

name (str) – name of the repository wanted

Return type

nexuscli.api.repository.model.Repository

Raises

exception.NexusClientInvalidRepository – when a repository with the given name isn’t found.

get_raw_by_name(name)

Return the raw dict for the repository called name. Remember to refresh() to get the latest from the server.

Parameters

name (str) – name of the repository wanted

Return type

dict

Raises

exception.NexusClientInvalidRepository – when a repository with the given name isn’t found.

raw_list()

A raw representation of the Nexus repositories.

Returns

for the format, see List Repositories.

Return type

dict

refresh()

Refresh local list of repositories with latest from service. A raw representation of repositories can be fetched using raw_list().

nexuscli.api.repository.collection.get_repository_class(raw_configuration)

Given a raw repository configuration, returns its corresponding class.

Parameters

raw_configuration (dict) – configuration as returned by the SCRIPT_NAME_GET groovy script.

Returns

repository class

nexuscli.api.repository.model module

class nexuscli.api.repository.model.AptHostedRepository(name, gpg_keypair: str = None, passphrase=None, **kwargs)

Bases: nexuscli.api.repository.model.AptRepository, nexuscli.api.repository.model.HostedRepository

property configuration

As per Repository.configuration but specific to this repository recipe and type.

Return type

str

class nexuscli.api.repository.model.AptProxyRepository(name, flat=False, **kwargs)

Bases: nexuscli.api.repository.model.AptRepository, nexuscli.api.repository.model.ProxyRepository

property configuration

As per Repository.configuration but specific to this repository recipe and type.

Return type

str

class nexuscli.api.repository.model.AptRepository(name, distribution='bionic', **kwargs)

Bases: nexuscli.api.repository.model.Repository

RECIPES = ('apt',)
property configuration

Repository configuration represented as a python dict. The dict returned by this property can be converted to JSON for use with the nexus3-cli-repository-create groovy script created by the create() method.

Example structure and attributes common to all repositories:

>>> common_configuration = {
>>>     'name': 'my-repository',
>>>     'online': True,
>>>     'recipeName': 'raw',
>>>     '_state': 'present',
>>>     'attributes': {
>>>         'storage': {
>>>             'blobStoreName': 'default',
>>>         },
>>>         'cleanup': {
>>>             'policyName': None,
>>>         }
>>>     }
>>> }

Depending on the repository type and format (recipe), other attributes will be present.

Returns

repository configuration

Return type

dict

class nexuscli.api.repository.model.BowerHostedRepository(name, write_policy='ALLOW', **kwargs)

Bases: nexuscli.api.repository.model.HostedRepository

class nexuscli.api.repository.model.BowerProxyRepository(name, remote_url=None, auto_block=True, content_max_age=1440, metadata_max_age=1440, negative_cache_enabled=True, negative_cache_ttl=1440, remote_auth_type=None, remote_username=None, remote_password=None, **kwargs)

Bases: nexuscli.api.repository.model.ProxyRepository

class nexuscli.api.repository.model.DockerHostedRepository(name, write_policy='ALLOW', **kwargs)

Bases: nexuscli.api.repository.model.HostedRepository, nexuscli.api.repository.model.DockerRepository

class nexuscli.api.repository.model.DockerProxyRepository(name, index_type='REGISTRY', use_trust_store_for_index_access=False, index_url='https://index.docker.io/', **kwargs)

Bases: nexuscli.api.repository.model.ProxyRepository, nexuscli.api.repository.model.DockerRepository

INDEX_TYPES = ('REGISTRY', 'HUB', 'CUSTOM')
property configuration

As per Repository.configuration but specific to this repository recipe and type.

Return type

str

class nexuscli.api.repository.model.DockerRepository(name, http_port=8084, https_port=8085, v1_enabled=False, force_basic_auth=False, **kwargs)

Bases: nexuscli.api.repository.model.Repository

RECIPES = ('docker',)
property configuration

As per Repository.configuration but specific to this repository recipe and type.

Return type

str

class nexuscli.api.repository.model.HostedRepository(name, write_policy='ALLOW', **kwargs)

Bases: nexuscli.api.repository.model.Repository

A hosted Nexus repository.

Parameters
TYPE = 'hosted'
WRITE_POLICIES = ['ALLOW', 'ALLOW_ONCE', 'DENY']

Nexus 3 repository write policies supported by this class.

property configuration

As per Repository.configuration but specific to this repository recipe and type.

Return type

str

upload_directory(src_dir, dst_dir, recurse=True, flatten=False)

Uploads all files in a directory to the specified destination directory in this repository, honouring options flatten and recurse.

Parameters
  • src_dir – path to local directory to be uploaded

  • dst_dir – destination directory in dst_repo

  • recurse (bool) – when True, upload directory recursively.

  • flatten – when True, the source directory tree isn’t replicated on the destination.

Returns

number of files uploaded

Return type

int

upload_file(src_file, dst_dir, dst_file=None)

Uploads a singe file to the directory and file name specified.

Parameters
  • src_file – path to the local file to be uploaded.

  • dst_dir – directory under dst_repo to place file in.

  • dst_file – destination file name. If not given, the basename of src_file name is used.

class nexuscli.api.repository.model.MavenHostedRepository(name, write_policy='ALLOW', **kwargs)

Bases: nexuscli.api.repository.model.HostedRepository, nexuscli.api.repository.model.MavenRepository

A Maven hosted Nexus repository.

See HostedRepository and MavenRepository

class nexuscli.api.repository.model.MavenProxyRepository(name, layout_policy='PERMISSIVE', version_policy='RELEASE', **kwargs)

Bases: nexuscli.api.repository.model.MavenRepository, nexuscli.api.repository.model.ProxyRepository

A Maven proxy Nexus repository.

See MavenRepository and ProxyRepository

class nexuscli.api.repository.model.MavenRepository(name, layout_policy='PERMISSIVE', version_policy='RELEASE', **kwargs)

Bases: nexuscli.api.repository.model.Repository

A base Maven Nexus repository.

Parameters
  • name (str) – name of the repository.

  • layout_policy – one of LAYOUT_POLICIES. See Nexus documentation for details.

  • version_policy – one of VERSION_POLICIES. See Nexus documentation for details.

  • kwargs – see Repository

LAYOUT_POLICIES = ('PERMISSIVE', 'STRICT')

Maven layout policies

RECIPES = ('maven',)
VERSION_POLICIES = ('RELEASE', 'SNAPSHOT', 'MIXED')

Maven version policies

property configuration

As per Repository.configuration but specific to this repository recipe and type.

Return type

str

class nexuscli.api.repository.model.NpmHostedRepository(name, write_policy='ALLOW', **kwargs)

Bases: nexuscli.api.repository.model.HostedRepository

class nexuscli.api.repository.model.NpmProxyRepository(name, remote_url=None, auto_block=True, content_max_age=1440, metadata_max_age=1440, negative_cache_enabled=True, negative_cache_ttl=1440, remote_auth_type=None, remote_username=None, remote_password=None, **kwargs)

Bases: nexuscli.api.repository.model.ProxyRepository

class nexuscli.api.repository.model.NugetHostedRepository(name, write_policy='ALLOW', **kwargs)

Bases: nexuscli.api.repository.model.HostedRepository

class nexuscli.api.repository.model.NugetProxyRepository(name, remote_url=None, auto_block=True, content_max_age=1440, metadata_max_age=1440, negative_cache_enabled=True, negative_cache_ttl=1440, remote_auth_type=None, remote_username=None, remote_password=None, **kwargs)

Bases: nexuscli.api.repository.model.ProxyRepository

class nexuscli.api.repository.model.ProxyRepository(name, remote_url=None, auto_block=True, content_max_age=1440, metadata_max_age=1440, negative_cache_enabled=True, negative_cache_ttl=1440, remote_auth_type=None, remote_username=None, remote_password=None, **kwargs)

Bases: nexuscli.api.repository.model.Repository

A proxy Nexus repository.

Parameters
  • name (str) – name of the repository.

  • remote_url (str) – The URL of the repository being proxied, including the protocol scheme.

  • auto_block (bool) – Auto-block outbound connections on the repository if remote peer is detected as unreachable/unresponsive.

  • content_max_age (int) – How long (in minutes) to cache artifacts before rechecking the remote repository. Release repositories should use -1.

  • metadata_max_age (int) – How long (in minutes) to cache metadata before rechecking the remote repository.

  • negative_cache_enabled (bool) – Cache responses for content not present in the proxied repository

  • negative_cache_ttl (int) – How long to cache the fact that a file was not found in the repository (in minutes)

  • kwargs – see Repository

TYPE = 'proxy'
property configuration

As per Repository.configuration but specific to this repository recipe and type.

Return type

str

class nexuscli.api.repository.model.PypiHostedRepository(name, write_policy='ALLOW', **kwargs)

Bases: nexuscli.api.repository.model.HostedRepository

class nexuscli.api.repository.model.PypiProxyRepository(name, remote_url=None, auto_block=True, content_max_age=1440, metadata_max_age=1440, negative_cache_enabled=True, negative_cache_ttl=1440, remote_auth_type=None, remote_username=None, remote_password=None, **kwargs)

Bases: nexuscli.api.repository.model.ProxyRepository

class nexuscli.api.repository.model.RawHostedRepository(name, write_policy='ALLOW', **kwargs)

Bases: nexuscli.api.repository.model.HostedRepository

class nexuscli.api.repository.model.RawProxyRepository(name, remote_url=None, auto_block=True, content_max_age=1440, metadata_max_age=1440, negative_cache_enabled=True, negative_cache_ttl=1440, remote_auth_type=None, remote_username=None, remote_password=None, **kwargs)

Bases: nexuscli.api.repository.model.ProxyRepository

class nexuscli.api.repository.model.Repository(name, nexus_client=None, recipe='raw', blob_store_name='default', strict_content_type_validation=False, cleanup_policy=None)

Bases: object

A base Nexus repository.

Nexus 3 repository recipes (formats) supported by this class:

Parameters
  • name (str) – name of the repository.

  • nexus_client (nexuscli.nexus_client.NexusClient) – the NexusClient instance that will be used to perform operations against the Nexus 3 service. You must provide this at instantiation or set it before calling any methods that require connectivity to Nexus.

  • recipe (str) – format (recipe) of the new repository. Must be one of RECIPES. See Nexus documentation for details.

  • blob_store_name (str) – name of an existing blob store; ‘default’ should work on most installations.

  • strict_content_type_validation (bool) – Whether to validate file extension against its content type.

  • cleanup_policy (str) – name of an existing repository clean-up policy.

RECIPES = ('bower', 'npm', 'nuget', 'pypi', 'raw', 'rubygems')
TYPE = None
property cleanup_policy

Groovy-formatted value for the cleanup/policy attribute.

property configuration

Repository configuration represented as a python dict. The dict returned by this property can be converted to JSON for use with the nexus3-cli-repository-create groovy script created by the create() method.

Example structure and attributes common to all repositories:

>>> common_configuration = {
>>>     'name': 'my-repository',
>>>     'online': True,
>>>     'recipeName': 'raw',
>>>     '_state': 'present',
>>>     'attributes': {
>>>         'storage': {
>>>             'blobStoreName': 'default',
>>>         },
>>>         'cleanup': {
>>>             'policyName': None,
>>>         }
>>>     }
>>> }

Depending on the repository type and format (recipe), other attributes will be present.

Returns

repository configuration

Return type

dict

property recipe_name

The Nexus 3 name for this repository’s recipe (format). This is almost always the same as name with maven being the notable exception.

class nexuscli.api.repository.model.RubygemsHostedRepository(name, write_policy='ALLOW', **kwargs)

Bases: nexuscli.api.repository.model.HostedRepository

class nexuscli.api.repository.model.RubygemsProxyRepository(name, remote_url=None, auto_block=True, content_max_age=1440, metadata_max_age=1440, negative_cache_enabled=True, negative_cache_ttl=1440, remote_auth_type=None, remote_username=None, remote_password=None, **kwargs)

Bases: nexuscli.api.repository.model.ProxyRepository

class nexuscli.api.repository.model.YumHostedRepository(name, write_policy='ALLOW', **kwargs)

Bases: nexuscli.api.repository.model.HostedRepository, nexuscli.api.repository.model.YumRepository

A Yum hosted Nexus repository.

See HostedRepository and YumRepository

class nexuscli.api.repository.model.YumProxyRepository(name, remote_url=None, auto_block=True, content_max_age=1440, metadata_max_age=1440, negative_cache_enabled=True, negative_cache_ttl=1440, remote_auth_type=None, remote_username=None, remote_password=None, **kwargs)

Bases: nexuscli.api.repository.model.ProxyRepository, nexuscli.api.repository.model.YumRepository

A Yum proxy Nexus repository.

See ProxyRepository and YumRepository

class nexuscli.api.repository.model.YumRepository(name, depth=1, **kwargs)

Bases: nexuscli.api.repository.model.Repository

A Yum base Nexus repository.

Parameters
  • name (str) – name of the repository.

  • depth (int) – The Yum repodata depth. Usually 1.

  • kwargs – see Repository

RECIPES = ('yum',)
property configuration

As per Repository.configuration but specific to this repository recipe and type.

Return type

str

nexuscli.api.repository.upload module

Methods to implement upload for specific repository formats (recipes)

nexuscli.api.repository.upload.upload_file_raw(repository, src_file, dst_dir, dst_file)

Upload a single file to a raw repository.

Parameters
  • repository (nexuscli.api.repository.model.Repository) – repository instance used to access Nexus 3 service.

  • src_file – path to the local file to be uploaded.

  • dst_dir – directory under dst_repo to place file in. When None, the file is placed under the root of the raw repository

  • dst_file – destination file name.

Raises
nexuscli.api.repository.upload.upload_file_yum(repository, src_file, dst_dir, dst_file)

Upload a single file to a yum repository.

Parameters
  • repository (nexuscli.api.repository.model.Repository) – repository instance used to access Nexus 3 service.

  • src_file – path to the local file to be uploaded.

  • dst_dir – directory under dst_repo to place file in.

  • dst_file – destination file name.

Raises

exception.NexusClientAPIError – unknown response from Nexus API.

nexuscli.api.repository.util module

nexuscli.api.repository.util.get_files(src_dir, recurse=True)

Walks the given directory and collects files to be uploaded. If recurse option is False, only the files on the root of the directory will be returned.

Parameters
  • src_dir – location of files

  • recurse – If false, only the files on the root of src_dir are returned

Returns

file set to be used with upload_directory

Return type

set

nexuscli.api.repository.util.get_upload_subdirectory(dst_dir, file_path, flatten=False)

Find the destination subdirectory based on given parameters. This is mostly so the flatten option is honoured.

Parameters
  • dst_dir – destination directory

  • file_path – file path, using REMOTE_PATH_SEPARATOR as the directory separator.

  • flatten (bool) – when True, sub_directory will be flattened (ie: file_path structure will not be present in the destination directory)

Returns

the appropriate sub directory in the destination directory.

Return type

str

nexuscli.api.repository.validations module

nexuscli.api.repository.validations.ensure_known(target, value, known)

Validate whether the a target argument is known and supported. The target is only used to provide a friendlier message to the user. The given value is checked against known and supported.

Parameters
  • target (str) – name of the target, as known to the end-user.

  • value (str) – value of the target key.

  • known (list,tuple) – known possible values for the target.

Raises

ValueError – if given value is not in known.

Module contents