From dda12167850f2855cf471584948f55ac7973501e Mon Sep 17 00:00:00 2001 From: DW Talton Date: Fri, 10 Jan 2020 14:03:59 -0700 Subject: [PATCH] Add nexus2 API endpoints Change-Id: I8ba68e819fbbcda8208e88d83007880cf543a194 Signed-off-by: DW Talton --- .coafile | 8 +- docs/commands/index.rst | 1 + docs/commands/nexus2.rst | 43 ++++ lftools/api/client.py | 14 +- lftools/api/endpoints/nexus2.py | 318 ++++++++++++++++++++++++ lftools/api/endpoints/{nexus.py => nexus3.py} | 7 +- lftools/api/endpoints/readthedocs.py | 2 + lftools/cli/__init__.py | 7 +- lftools/cli/dco.py | 2 + lftools/cli/nexus.py | 5 +- lftools/cli/nexus2/__init__.py | 37 +++ lftools/cli/nexus2/privilege.py | 65 +++++ lftools/cli/nexus2/repository.py | 70 ++++++ lftools/cli/nexus2/role.py | 70 ++++++ lftools/cli/nexus2/user.py | 70 ++++++ lftools/cli/nexus3/__init__.py | 28 ++- lftools/cli/nexus3/asset.py | 8 +- lftools/cli/nexus3/privilege.py | 4 +- lftools/cli/nexus3/repository.py | 6 +- lftools/cli/nexus3/role.py | 8 +- lftools/cli/nexus3/script.py | 16 +- lftools/cli/nexus3/tag.py | 10 +- lftools/cli/nexus3/task.py | 7 +- lftools/cli/nexus3/user.py | 6 +- lftools/cli/rtd.py | 2 + lftools/shell/dco.py | 2 + releasenotes/notes/nexus2-d2f5afe25daee1d3.yaml | 19 ++ tox.ini | 3 +- 28 files changed, 785 insertions(+), 53 deletions(-) create mode 100644 docs/commands/nexus2.rst create mode 100644 lftools/api/endpoints/nexus2.py rename lftools/api/endpoints/{nexus.py => nexus3.py} (99%) create mode 100644 lftools/cli/nexus2/__init__.py create mode 100644 lftools/cli/nexus2/privilege.py create mode 100644 lftools/cli/nexus2/repository.py create mode 100644 lftools/cli/nexus2/role.py create mode 100644 lftools/cli/nexus2/user.py create mode 100644 releasenotes/notes/nexus2-d2f5afe25daee1d3.yaml diff --git a/.coafile b/.coafile index 5b4657be..6c057d37 100644 --- a/.coafile +++ b/.coafile @@ -5,7 +5,11 @@ ignore = .tox/**, .gitreview, .gitmodules, .pytest_cache/**, - node_modules/** + node_modules/**, + docs/conf.py, + lftools/cli/nexus2/**, + lftools/cli/nexus3/**, + .venv/** [all.Documentation] bears = WriteGoodLintBear @@ -25,8 +29,6 @@ bears = BanditBear, PyFlakesBear, PyImportSortBear files = lftools/**.py -ignore += docs/conf.py -ignore += lftools/cli/nexus3/*.py known_first_party_imports = lftools known_third_party_imports = defusedxml, diff --git a/docs/commands/index.rst b/docs/commands/index.rst index c1bc7756..734ec0cf 100644 --- a/docs/commands/index.rst +++ b/docs/commands/index.rst @@ -19,6 +19,7 @@ It supports the following commands: lfidapi license nexus + nexus2 nexus3 openstack rtd diff --git a/docs/commands/nexus2.rst b/docs/commands/nexus2.rst new file mode 100644 index 00000000..f0069971 --- /dev/null +++ b/docs/commands/nexus2.rst @@ -0,0 +1,43 @@ +.. _nexus2: + +****** +Nexus3 +****** + +.. program-output:: lftools nexus2 --help + +.. _nexus2_commands: + +Commands +======== + +.. contents:: Nexus2 Commands + :local: + +.. _nexus2_privileges: + +privilege +--------- + +.. program-output:: lftools nexus2 privilege --help + +.. _nexus2_repository: + +repository +---------- + +.. program-output:: lftools nexus2 repository --help + +.. _nexus2_role: + +role +---- + +.. program-output:: lftools nexus2 role --help + +.. _nexus2_user: + +user +---- + +.. program-output:: lftools nexus2 user --help diff --git a/lftools/api/client.py b/lftools/api/client.py index 6173f59a..52ed2542 100644 --- a/lftools/api/client.py +++ b/lftools/api/client.py @@ -34,9 +34,10 @@ class RestApi(object): self.password = self.creds["password"] self.r = requests.Session() self.r.auth = (self.username, self.password) - self.r.headers.update( - {"Content-Type": "application/json; charset=UTF-8"} - ) + self.r.headers.update({ + "Content-Type": "application/json; charset=UTF-8", + "Accept": "application/json" + }) if self.creds["authtype"] == "token": self.token = self.creds["token"] @@ -48,9 +49,10 @@ class RestApi(object): def _request(self, url, method, data=None, timeout=30): """Execute the request.""" - resp = self.r.request( - method, self.endpoint + url, data=data, timeout=timeout - ) + resp = self.r.request(method, + self.endpoint + url, + data=data, + timeout=timeout) # Some massaging to make our gerrit python code work if resp.status_code == 409: diff --git a/lftools/api/endpoints/nexus2.py b/lftools/api/endpoints/nexus2.py new file mode 100644 index 00000000..a4b44741 --- /dev/null +++ b/lftools/api/endpoints/nexus2.py @@ -0,0 +1,318 @@ +# SPDX-License-Identifier: EPL-1.0 +############################################################################## +# Copyright (c) 2019 The Linux Foundation and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +############################################################################## + +"""Nexus2 REST API interface.""" + +__author__ = 'DW Talton' + +import json +import logging + +from lftools import config +import lftools.api.client as client + +log = logging.getLogger(__name__) + + +class Nexus2(client.RestApi): + """API endpoint wrapper for Nexus2.""" + + def __init__(self, **params): + """Initialize the class.""" + self.params = params + self.fqdn = self.params["fqdn"] + if "creds" not in self.params: + creds = { + "authtype": "basic", + "username": config.get_setting(self.fqdn, "username"), + "password": config.get_setting(self.fqdn, "password"), + "endpoint": config.get_setting(self.fqdn, "endpoint"), + } + params["creds"] = creds + + super(Nexus2, self).__init__(**params) + +############ +# Privileges + def privilege_list(self): + """List privileges.""" + result = self.get('service/local/privileges')[1]['data'] + + privilege_list = [] + for privilege in result: + privilege_list.append([ + privilege['name'], + privilege['id'] + ]) + + privilege_list.sort() + return privilege_list + + def privilege_create(self, name, description, repo): + """Create a new privilege. + + :param name: the privilege name + :param description: the privilege description + :param repo: the repo to attach to the privilege + """ + data = { + 'data': { + 'name': name, + 'description': description, + 'type': 'target', + 'repositoryTargetId': 'any', + 'repositoryId': repo, + 'repositoryGroupId': '', + 'method': ['create', 'read', 'update', 'delete'] + } + } + + json_data = json.dumps(data) + result = self.post('service/local/privileges_target', data=json_data) + + if result[0].status_code == 201: + return 'Privilege successfully created.' + + def privilege_delete(self, privilege_id): + """Delete a privilege. + + :param privilege_id: the ID of the privilege (from privilege list) + """ + result = self.delete('service/local/privileges/{}'.format(privilege_id)) + + if result.status_code == 204: + return "Privilege successfully deleted." + +############## +# Repositories + def repo_list(self): + """Get a list of repositories.""" + result = self.get('service/local/repositories')[1]['data'] + + repo_list = [] + for repo in result: + repo_list.append([ + repo['name'], + repo['repoType'], + repo['provider'], + repo['id'] + ]) + + return repo_list + + def repo_create(self, repo_type, repo_id, repo_name, repo_provider, repo_policy, repo_upstream_url): + """Add a new repo. + + :param repo_type: the type of repo. Valid types are 'proxy' and 'hosted' + :param repo_id: the ID for the repository + :param repo_name: the name for the repository + :param repo_provider: the provider type. Valid types are 'maven2' and 'site' + :param repo_policy: the repo policy. Valid types are 'RELEASE', 'SNAPSHOT', 'MIXED' + :param repo_upstream_url: the URL to an upstream repo when creating a proxy repo + """ + # common data regardless of repo type + data = { + "data": { + "browseable": True, + "exposed": True, + "id": repo_id, + "indexable": True, + "name": repo_name, + "notFoundCacheTTL": 1440, + "provider": repo_provider, + "providerRole": "org.sonatype.nexus.proxy.repository.Repository", + "repoPolicy": repo_policy, + 'repoType': repo_type + } + } + + if repo_type == "hosted": + data['data'].update({ + "checksumPolicy": "IGNORE", + "downloadRemoteIndexes": False, + "writePolicy": "ALLOW_WRITE_ONCE" + }) + if repo_provider == 'site': + data['data'].update({ + 'repoPolicy': 'MIXED', + 'writePolicy': 'ALLOW_WRITE', + 'indexable': False, + }) + + if repo_type == 'proxy': + data['data'].update({ + 'artifactMaxAge': -1, + 'autoBlockActive': True, + "checksumPolicy": "WARN", + "downloadRemoteIndexes": True, + 'fileTypeValidation': True, + 'metadataMaxAge': 1440, + 'remoteStorage': { + 'authentication': None, + 'connectionSettings': None, + 'remoteStorageUrl': repo_upstream_url + } + }) + + json_data = json.dumps(data) + result = self.post("service/local/repositories", data=json_data) + + if result[0].status_code == 201: + return "Repo successfully created." + else: + return "Failed to create new repository" + + def repo_delete(self, repo_id): + """Permanently delete a repo. + + :param repo_id: the ID of the repo from repo list. + """ + result = self.delete('service/local/repositories/{}'.format(repo_id)) + + if result.status_code == 204: + return "Repo successfully deleted." + else: + exit(1) + +####### +# Roles + def role_list(self): + """List all roles.""" + result = self.get('service/local/roles')[1] + + role_list = [] + for role in result['data']: + + # wacky string concat is to provide the right format + # so that tabulate will iterate the string at the newline + # breaks and show multiline columns in a nice way + roles_string = '' + privs_string = '' + if 'roles' in role: + for roles in role['roles']: + roles_string += roles + '\n' + + if 'privileges' in role: + for privs in role['privileges']: + privs_string += privs + '\n' + + role_list.append([ + role['id'], + role['name'], + roles_string, + privs_string + ]) + + return role_list + + def role_create(self, role_id, role_name, role_description, roles_list=None, privs_list=None): + """Create a new role. + + :param role_id: the ID name of the role (string) + :param role_name: the actual name of the role + :param role_description: the description of the role + :param roles_list: (optional) a list of existing roles to attach to this role + :param privs_list: (optional) a list of existing privs to attach to this role + """ + data = { + 'data': { + 'id': role_id, + 'name': role_name, + 'description': role_description, + 'sessionTimeout': 0, + 'userManaged': True + } + } + + if roles_list: + data['data']['roles'] = roles_list.split(',') + + if privs_list: + data['data']['privileges'] = privs_list.split(',') + + json_data = json.dumps(data) + result = self.post('service/local/roles', data=json_data) + + if result[0].status_code == 201: + return "Role successfully created." + + return result + + def role_delete(self, role_id): + """Permanently delete a role. + + :param role_id: The ID of the role to delete (from role list) + """ + result = self.delete('service/local/roles/{}'.format(role_id)) + + if result.status_code == 204: + return "Role successfully deleted." + +####### +# Users + def user_list(self): + """List all users.""" + result = self.get('service/local/plexus_users/allConfigured')[1]['data'] + user_list = [] + for user in result: + role_list = [] + for role in user['roles']: + role_list.append([ + role['roleId'] + ]) + + user_list.append([ + user['userId'], + user['firstName'], + user['lastName'], + user['status'], + role_list + ]) + + return user_list + + def user_create(self, username, firstname, lastname, email, roles): + """Add a new user. + + :param username: the username + :param firstname: the user's first name + :param lastname: the user's last name + :param email: the user's email address + :param roles: a comma-separated list of roles to add the user to + """ + role_list = roles.split(',') + data = { + 'data': { + 'userId': username, + 'firstName': firstname, + 'lastName': lastname, + 'status': 'active', + 'email': email, + 'roles': role_list + } + } + + json_data = json.dumps(data) + result = self.post('service/local/users', data=json_data) + + if result[0].status_code == 201: + return "User successfully created." + else: + return "Failed to create new user" + + def user_delete(self, username): + """Permanently delete a user. + + :param username: The username to delete (from user list) + """ + result = self.delete('service/local/users/{}'.format(username)) + + if result.status_code == 204: + return "User successfully deleted." diff --git a/lftools/api/endpoints/nexus.py b/lftools/api/endpoints/nexus3.py similarity index 99% rename from lftools/api/endpoints/nexus.py rename to lftools/api/endpoints/nexus3.py index df4d265a..0e36bdf0 100644 --- a/lftools/api/endpoints/nexus.py +++ b/lftools/api/endpoints/nexus3.py @@ -9,6 +9,9 @@ ############################################################################## """Nexus3 REST API interface.""" + +__author__ = 'DW Talton' + import json import logging @@ -18,7 +21,7 @@ import lftools.api.client as client log = logging.getLogger(__name__) -class Nexus(client.RestApi): +class Nexus3(client.RestApi): """API endpoint wrapper for Nexus3.""" def __init__(self, **params): @@ -34,7 +37,7 @@ class Nexus(client.RestApi): } params["creds"] = creds - super(Nexus, self).__init__(**params) + super(Nexus3, self).__init__(**params) def create_role(self, name, description, privileges, roles): """Create a new role. diff --git a/lftools/api/endpoints/readthedocs.py b/lftools/api/endpoints/readthedocs.py index d39a4c1a..f5cfcd7b 100644 --- a/lftools/api/endpoints/readthedocs.py +++ b/lftools/api/endpoints/readthedocs.py @@ -10,6 +10,8 @@ """Read the Docs REST API interface.""" +__author__ = 'DW Talton' + import json from lftools import config diff --git a/lftools/cli/__init__.py b/lftools/cli/__init__.py index 87370a95..d87e7414 100644 --- a/lftools/cli/__init__.py +++ b/lftools/cli/__init__.py @@ -9,7 +9,6 @@ ############################################################################## """CLI main for lftools.""" -__author__ = 'Thanh Ha' import configparser import getpass @@ -28,7 +27,8 @@ from lftools.cli.infofile import infofile from lftools.cli.jenkins import jenkins_cli from lftools.cli.lfidapi import lfidapi from lftools.cli.license import license -from lftools.cli.nexus3 import nexus3 +from lftools.cli.nexus2 import nexus_two +from lftools.cli.nexus3 import nexus_three from lftools.cli.nexus import nexus from lftools.cli.rtd import rtd from lftools.cli.schema import schema @@ -88,7 +88,8 @@ cli.add_command(infofile) cli.add_command(jenkins_cli, name='jenkins') cli.add_command(license) cli.add_command(nexus) -cli.add_command(nexus3) +cli.add_command(nexus_two) +cli.add_command(nexus_three) cli.add_command(rtd) cli.add_command(schema) cli.add_command(lfidapi) diff --git a/lftools/cli/dco.py b/lftools/cli/dco.py index 4b1ec5e1..a5e2f83f 100644 --- a/lftools/cli/dco.py +++ b/lftools/cli/dco.py @@ -9,6 +9,8 @@ ############################################################################## """Script to check a git repository for commits missing DCO.""" +__author__ = 'DW Talton' + import sys import click diff --git a/lftools/cli/nexus.py b/lftools/cli/nexus.py index d9a21178..c11c17b6 100644 --- a/lftools/cli/nexus.py +++ b/lftools/cli/nexus.py @@ -21,7 +21,10 @@ NEXUS_URL_ENV = 'NEXUS_URL' @click.group() @click.pass_context def nexus(ctx): - """Provide an interface to Nexus.""" + """(Deprecated) Use the Nexus2 API Interface. + + Provide an interface to Nexus. + """ pass diff --git a/lftools/cli/nexus2/__init__.py b/lftools/cli/nexus2/__init__.py new file mode 100644 index 00000000..4c214398 --- /dev/null +++ b/lftools/cli/nexus2/__init__.py @@ -0,0 +1,37 @@ +# SPDX-License-Identifier: EPL-1.0 +############################################################################## +# Copyright (c) 2019 The Linux Foundation and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +############################################################################## + +"""Nexus2 REST API sub-interfaces.""" + +__author__ = 'DW Talton' + + +from lftools.api.endpoints import nexus2 + +from .privilege import * +from .repository import * +from .role import * +from .user import * + + +@click.group(name="nexus2") +@click.argument('fqdn') +@click.pass_context +def nexus_two(ctx, fqdn): + """The Nexus2 API Interface.""" + nexus2_obj = nexus2.Nexus2(fqdn=fqdn) + ctx.obj = {"nexus2": nexus2_obj} + pass + + +nexus_two.add_command(privilege) +nexus_two.add_command(repo) +nexus_two.add_command(role) +nexus_two.add_command(user) diff --git a/lftools/cli/nexus2/privilege.py b/lftools/cli/nexus2/privilege.py new file mode 100644 index 00000000..f3965382 --- /dev/null +++ b/lftools/cli/nexus2/privilege.py @@ -0,0 +1,65 @@ +# SPDX-License-Identifier: EPL-1.0 +############################################################################## +# Copyright (c) 2019 The Linux Foundation and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +############################################################################## + +"""Nexus2 REST API user interface.""" + +__author__ = 'DW Talton' + +import logging + +import click +from tabulate import tabulate + +log = logging.getLogger(__name__) + + +@click.group() +@click.pass_context +def privilege(ctx): + """User primary interface.""" + pass + + +@privilege.command(name="list") +@click.pass_context +def list(ctx): + """List privileges.""" + r = ctx.obj["nexus2"] + data = r.privilege_list() + log.info( + tabulate( + data, + headers=[ + "Name", + "ID" + ] + )) + + +@privilege.command(name="create") +@click.argument("name") +@click.argument("description") +@click.argument("repo") +@click.pass_context +def create(ctx, name, description, repo): + """Create a new privilege.""" + r = ctx.obj["nexus2"] + data = r.privilege_create(name, description, repo) + log.info(data) + + +@privilege.command(name="delete") +@click.argument("privilege_id") +@click.pass_context +def delete(ctx, privilege_id): + """Delete a privilege.""" + r = ctx.obj["nexus2"] + data = r.privilege_delete(privilege_id) + log.info(data) diff --git a/lftools/cli/nexus2/repository.py b/lftools/cli/nexus2/repository.py new file mode 100644 index 00000000..c2f2b376 --- /dev/null +++ b/lftools/cli/nexus2/repository.py @@ -0,0 +1,70 @@ +# SPDX-License-Identifier: EPL-1.0 +############################################################################## +# Copyright (c) 2019 The Linux Foundation and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +############################################################################## + +"""Nexus2 REST API repository interface.""" + +__author__ = 'DW Talton' + +import logging + +import click +from tabulate import tabulate + +log = logging.getLogger(__name__) + + +@click.group() +@click.pass_context +def repo(ctx): + """Repository primary interface.""" + pass + + +@repo.command(name="list") +@click.pass_context +def repo_list(ctx): + """List repositories.""" + r = ctx.obj["nexus2"] + data = r.repo_list() + log.info( + tabulate( + data, + headers=[ + "Name", + "Type", + "Provider", + "ID" + ] + )) + + +@repo.command(name="create") +@click.argument("repo_type") +@click.argument("repo_id") +@click.argument("repo_name") +@click.argument("repo_provider") +@click.argument("repo_policy") +@click.option('-u', '--upstream-repo', 'repo_upstream_url') +@click.pass_context +def create(ctx, repo_type, repo_id, repo_name, repo_provider, repo_policy, repo_upstream_url): + """Create a new repository.""" + r = ctx.obj["nexus2"] + data = r.repo_create(repo_type, repo_id, repo_name, repo_provider, repo_policy, repo_upstream_url) + log.info(data) + + +@repo.command(name="delete") +@click.argument("repo_id") +@click.pass_context +def delete(ctx, repo_id): + """Permanently delete a repo.""" + r = ctx.obj["nexus2"] + data = r.repo_delete(repo_id) + log.info(data) diff --git a/lftools/cli/nexus2/role.py b/lftools/cli/nexus2/role.py new file mode 100644 index 00000000..37913b2b --- /dev/null +++ b/lftools/cli/nexus2/role.py @@ -0,0 +1,70 @@ +# SPDX-License-Identifier: EPL-1.0 +############################################################################## +# Copyright (c) 2019 The Linux Foundation and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +############################################################################## + +"""Nexus2 REST API user interface.""" + +__author__ = 'DW Talton' + +import logging + +import click +from tabulate import tabulate + +log = logging.getLogger(__name__) + + +@click.group() +@click.pass_context +def role(ctx): + """User primary interface.""" + pass + + +@role.command(name="list") +@click.pass_context +def role_list(ctx): + """List users.""" + r = ctx.obj["nexus2"] + data = r.role_list() + log.info( + tabulate( + data, + headers=[ + "ID", + "Name", + "Roles", + "Privileges" + ], + tablefmt="grid" + )) + + +@role.command(name="create") +@click.argument("role_id") +@click.argument("role_name") +@click.option('-d', "role_description", required=False) +@click.option('-r', "roles_list", required=False) +@click.option('-p', "privileges_list", required=False) +@click.pass_context +def role_create(ctx, role_id, role_name, role_description, roles_list, privileges_list): + """Create a new role.""" + r = ctx.obj["nexus2"] + data = r.role_create(role_id, role_name, role_description, roles_list, privileges_list) + log.info(data) + + +@role.command(name="delete") +@click.argument("role_id") +@click.pass_context +def role_delete(ctx, role_id): + """Delete a role.""" + r = ctx.obj["nexus2"] + data = r.role_delete(role_id) + log.info(data) diff --git a/lftools/cli/nexus2/user.py b/lftools/cli/nexus2/user.py new file mode 100644 index 00000000..33b64012 --- /dev/null +++ b/lftools/cli/nexus2/user.py @@ -0,0 +1,70 @@ +# SPDX-License-Identifier: EPL-1.0 +############################################################################## +# Copyright (c) 2019 The Linux Foundation and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +############################################################################## + +"""Nexus2 REST API user interface.""" + +__author__ = 'DW Talton' + +import logging + +import click +from tabulate import tabulate + +log = logging.getLogger(__name__) + + +@click.group() +@click.pass_context +def user(ctx): + """User primary interface.""" + pass + + +@user.command(name="list") +@click.pass_context +def user_list(ctx): + """List users.""" + r = ctx.obj["nexus2"] + data = r.user_list() + log.info( + tabulate( + data, + headers=[ + "ID", + "First Name", + "Last Name", + "Status", + "Roles" + ] + )) + + +@user.command(name="add") +@click.argument("username") +@click.argument("firstname") +@click.argument("lastname") +@click.argument("email") +@click.argument("roles") +@click.pass_context +def user_create(ctx, username, firstname, lastname, email, roles): + """Add a new user.""" + r = ctx.obj["nexus2"] + data = r.user_create(username, firstname, lastname, email, roles) + log.info(data) + + +@user.command(name="delete") +@click.argument("username") +@click.pass_context +def user_details(ctx, username): + """Delete a user.""" + r = ctx.obj["nexus2"] + data = r.user_delete(username) + log.info(data) diff --git a/lftools/cli/nexus3/__init__.py b/lftools/cli/nexus3/__init__.py index d4085207..5fc8260d 100644 --- a/lftools/cli/nexus3/__init__.py +++ b/lftools/cli/nexus3/__init__.py @@ -10,6 +10,8 @@ """Nexus3 REST API sub-interfaces.""" +__author__ = 'DW Talton' + from .asset import * from .privilege import * from .repository import * @@ -20,21 +22,21 @@ from .task import * from .user import * -@click.group() +@click.group(name="nexus3") @click.argument("fqdn") @click.pass_context -def nexus3(ctx, fqdn): - """Provide an interface to Nexus3.""" - nexus_obj = nexus.Nexus(fqdn=fqdn) - ctx.obj = {"nexus": nexus_obj} +def nexus_three(ctx, fqdn): + """The Nexus3 API Interface.""" + nexus3_obj = nexus3.Nexus3(fqdn=fqdn) + ctx.obj = {"nexus3": nexus3_obj} pass -nexus3.add_command(asset) -nexus3.add_command(privilege) -nexus3.add_command(repository) -nexus3.add_command(role) -nexus3.add_command(script) -nexus3.add_command(tag) -nexus3.add_command(task) -nexus3.add_command(user) +nexus_three.add_command(asset) +nexus_three.add_command(privilege) +nexus_three.add_command(repository) +nexus_three.add_command(role) +nexus_three.add_command(script) +nexus_three.add_command(tag) +nexus_three.add_command(task) +nexus_three.add_command(user) diff --git a/lftools/cli/nexus3/asset.py b/lftools/cli/nexus3/asset.py index 1aac887b..417a6b21 100644 --- a/lftools/cli/nexus3/asset.py +++ b/lftools/cli/nexus3/asset.py @@ -10,12 +10,14 @@ """Nexus3 REST API asset interface.""" +__author__ = 'DW Talton' + import logging from pprint import pformat import click -from lftools.api.endpoints import nexus +from lftools.api.endpoints import nexus3 log = logging.getLogger(__name__) @@ -32,7 +34,7 @@ def asset(ctx): @click.pass_context def asset_list(ctx, repository): """List assets.""" - r = ctx.obj["nexus"] + r = ctx.obj["nexus3"] data = r.list_assets(repository) for item in data: log.info(pformat(item)) @@ -45,7 +47,7 @@ def asset_list(ctx, repository): @click.pass_context def asset_search(ctx, query_string, repository, details): """Search assets.""" - r = ctx.obj["nexus"] + r = ctx.obj["nexus3"] data = r.search_asset(query_string, repository, details) if details: diff --git a/lftools/cli/nexus3/privilege.py b/lftools/cli/nexus3/privilege.py index 32841daf..e9b94f88 100644 --- a/lftools/cli/nexus3/privilege.py +++ b/lftools/cli/nexus3/privilege.py @@ -10,6 +10,8 @@ """Nexus3 REST API privileges interface.""" +__author__ = 'DW Talton' + import logging import click @@ -29,7 +31,7 @@ def privilege(ctx): @click.pass_context def list_privileges(ctx): """List privileges.""" - r = ctx.obj["nexus"] + r = ctx.obj["nexus3"] data = r.list_privileges() log.info( tabulate(data, headers=["Type", "Name", "Description", "Read Only"]) diff --git a/lftools/cli/nexus3/repository.py b/lftools/cli/nexus3/repository.py index 981fe13c..312669cf 100644 --- a/lftools/cli/nexus3/repository.py +++ b/lftools/cli/nexus3/repository.py @@ -10,12 +10,14 @@ """Nexus3 REST API repository interface.""" +__author__ = 'DW Talton' + import logging from pprint import pformat import click -from lftools.api.endpoints import nexus # noqa: F401 +from lftools.api.endpoints import nexus3 # noqa: F401 log = logging.getLogger(__name__) @@ -31,6 +33,6 @@ def repository(ctx): @click.pass_context def list_repositories(ctx): """List repositories.""" - r = ctx.obj["nexus"] + r = ctx.obj["nexus3"] data = r.list_repositories() log.info(pformat(data)) diff --git a/lftools/cli/nexus3/role.py b/lftools/cli/nexus3/role.py index 6c25e1c7..e021be51 100644 --- a/lftools/cli/nexus3/role.py +++ b/lftools/cli/nexus3/role.py @@ -10,13 +10,15 @@ """Nexus3 REST API role interface.""" +__author__ = 'DW Talton' + import logging from pprint import pformat import click from tabulate import tabulate -from lftools.api.endpoints import nexus # noqa: F401 +from lftools.api.endpoints import nexus3 # noqa: F401 log = logging.getLogger(__name__) @@ -32,7 +34,7 @@ def role(ctx): @click.pass_context def list_roles(ctx): """List roles.""" - r = ctx.obj["nexus"] + r = ctx.obj["nexus3"] data = r.list_roles() log.info(tabulate(data, headers=["Roles"])) @@ -45,6 +47,6 @@ def list_roles(ctx): @click.pass_context def create_role(ctx, name, description, privileges, roles): """Create roles.""" - r = ctx.obj["nexus"] + r = ctx.obj["nexus3"] data = r.create_role(name, description, privileges, roles) log.info(pformat(data)) diff --git a/lftools/cli/nexus3/script.py b/lftools/cli/nexus3/script.py index b02dc599..55201d9c 100644 --- a/lftools/cli/nexus3/script.py +++ b/lftools/cli/nexus3/script.py @@ -10,11 +10,13 @@ """Nexus3 REST API script interface.""" +__author__ = 'DW Talton' + import logging import click -from lftools.api.endpoints import nexus # noqa: F401 +from lftools.api.endpoints import nexus3 # noqa: F401 log = logging.getLogger(__name__) @@ -32,7 +34,7 @@ def script(ctx): @click.pass_context def create_script(ctx, name, filename): """Create a new script.""" - r = ctx.obj["nexus"] + r = ctx.obj["nexus3"] data = r.create_script(name, filename) log.info(data) @@ -42,7 +44,7 @@ def create_script(ctx, name, filename): @click.pass_context def delete_script(ctx, name): """Delete a script.""" - r = ctx.obj["nexus"] + r = ctx.obj["nexus3"] data = r.delete_script(name) log.info(data) @@ -51,7 +53,7 @@ def delete_script(ctx, name): @click.pass_context def list_scripts(ctx): """List all scripts.""" - r = ctx.obj["nexus"] + r = ctx.obj["nexus3"] data = r.list_scripts() log.info(data) @@ -61,7 +63,7 @@ def list_scripts(ctx): @click.pass_context def read_script(ctx, name): """Get script contents.""" - r = ctx.obj["nexus"] + r = ctx.obj["nexus3"] data = r.read_script(name) log.info(data) @@ -71,7 +73,7 @@ def read_script(ctx, name): @click.pass_context def run_script(ctx, name): """Run a script.""" - r = ctx.obj["nexus"] + r = ctx.obj["nexus3"] data = r.run_script(name) log.info(data) @@ -82,6 +84,6 @@ def run_script(ctx, name): @click.pass_context def update_script(ctx, name, content): """Update script contents.""" - r = ctx.obj["nexus"] + r = ctx.obj["nexus3"] data = r.update_script(name, content) log.info(data) diff --git a/lftools/cli/nexus3/tag.py b/lftools/cli/nexus3/tag.py index c98606d8..4d9d0064 100644 --- a/lftools/cli/nexus3/tag.py +++ b/lftools/cli/nexus3/tag.py @@ -10,6 +10,8 @@ """Nexus3 REST API tag interface.""" +__author__ = 'DW Talton' + import logging from pprint import pformat @@ -31,7 +33,7 @@ def tag(ctx): @click.pass_context def add_tag(ctx, name, attributes): """Add a tag.""" - r = ctx.obj["nexus"] + r = ctx.obj["nexus3"] data = r.create_tag(name, attributes) log.info(pformat(data)) @@ -41,7 +43,7 @@ def add_tag(ctx, name, attributes): @click.pass_context def delete_tag(ctx, name): """Delete a tag.""" - r = ctx.obj["nexus"] + r = ctx.obj["nexus3"] data = r.delete_tag(name) log.info(pformat(data)) @@ -50,7 +52,7 @@ def delete_tag(ctx, name): @click.pass_context def list_tags(ctx): """List tags.""" - r = ctx.obj["nexus"] + r = ctx.obj["nexus3"] data = r.list_tags() log.info(pformat(data)) @@ -60,6 +62,6 @@ def list_tags(ctx): @click.pass_context def show_tag(ctx, name): """Show tags.""" - r = ctx.obj["nexus"] + r = ctx.obj["nexus3"] data = r.show_tag(name) log.info(pformat(data)) diff --git a/lftools/cli/nexus3/task.py b/lftools/cli/nexus3/task.py index 5d30e253..405a27dc 100644 --- a/lftools/cli/nexus3/task.py +++ b/lftools/cli/nexus3/task.py @@ -9,12 +9,15 @@ ############################################################################## """Nexus3 REST API task interface.""" + +__author__ = 'DW Talton' + import logging import click from tabulate import tabulate -from lftools.api.endpoints import nexus # noqa: F401 +from lftools.api.endpoints import nexus3 # noqa: F401 log = logging.getLogger(__name__) @@ -30,7 +33,7 @@ def task(ctx): @click.pass_context def list_tasks(ctx): """List tasks.""" - r = ctx.obj["nexus"] + r = ctx.obj["nexus3"] data = r.list_tasks() log.info( tabulate( diff --git a/lftools/cli/nexus3/user.py b/lftools/cli/nexus3/user.py index 43821a74..1668fb2c 100644 --- a/lftools/cli/nexus3/user.py +++ b/lftools/cli/nexus3/user.py @@ -10,12 +10,14 @@ """Nexus3 REST API user interface.""" +__author__ = 'DW Talton' + import logging import click from tabulate import tabulate -from lftools.api.endpoints import nexus # noqa: F401 +from lftools.api.endpoints import nexus3 # noqa: F401 log = logging.getLogger(__name__) @@ -32,7 +34,7 @@ def user(ctx): @click.pass_context def search_user(ctx, username): """Search users.""" - r = ctx.obj["nexus"] + r = ctx.obj["nexus3"] data = r.list_user(username) log.info( tabulate( diff --git a/lftools/cli/rtd.py b/lftools/cli/rtd.py index f38177a5..2327cb3b 100644 --- a/lftools/cli/rtd.py +++ b/lftools/cli/rtd.py @@ -10,6 +10,8 @@ """Read the Docs interface.""" +__author__ = 'DW Talton' + import logging from pprint import pformat diff --git a/lftools/shell/dco.py b/lftools/shell/dco.py index dc9b96d1..d819435a 100644 --- a/lftools/shell/dco.py +++ b/lftools/shell/dco.py @@ -10,6 +10,8 @@ ############################################################################## """Functions for DCO check tasks.""" +__author__ = 'DW Talton' + import logging from os import chdir from os import getcwd diff --git a/releasenotes/notes/nexus2-d2f5afe25daee1d3.yaml b/releasenotes/notes/nexus2-d2f5afe25daee1d3.yaml new file mode 100644 index 00000000..10c5ee17 --- /dev/null +++ b/releasenotes/notes/nexus2-d2f5afe25daee1d3.yaml @@ -0,0 +1,19 @@ +--- +features: + - | + Nexus2 API operations. + + Usage: lftools nexus2 [OPTIONS] COMMAND [ARGS]... + + .. code-block:: none + + Commands: + privilege Privilege primary interface. + repository Repository primary interface. + role Role primary interface. + user User primary interface. + + .. code-block:: none + + Options: + --help Show this message and exit. diff --git a/tox.ini b/tox.ini index 87b25baf..fe8e6332 100644 --- a/tox.ini +++ b/tox.ini @@ -8,7 +8,8 @@ envlist = pre-commit, py35, py36, - py37 + py37, + py38 skip_missing_interpreters = true [testenv] -- 2.16.6