Add nexus2 API endpoints 80/62780/13
authorDW Talton <dtalton@contractor.linuxfoundation.org>
Fri, 10 Jan 2020 21:03:59 +0000 (14:03 -0700)
committerDW Talton <dtalton@contractor.linuxfoundation.org>
Thu, 13 Feb 2020 21:34:40 +0000 (14:34 -0700)
Change-Id: I8ba68e819fbbcda8208e88d83007880cf543a194
Signed-off-by: DW Talton <dtalton@contractor.linuxfoundation.org>
28 files changed:
.coafile
docs/commands/index.rst
docs/commands/nexus2.rst [new file with mode: 0644]
lftools/api/client.py
lftools/api/endpoints/nexus2.py [new file with mode: 0644]
lftools/api/endpoints/nexus3.py [moved from lftools/api/endpoints/nexus.py with 99% similarity]
lftools/api/endpoints/readthedocs.py
lftools/cli/__init__.py
lftools/cli/dco.py
lftools/cli/nexus.py
lftools/cli/nexus2/__init__.py [new file with mode: 0644]
lftools/cli/nexus2/privilege.py [new file with mode: 0644]
lftools/cli/nexus2/repository.py [new file with mode: 0644]
lftools/cli/nexus2/role.py [new file with mode: 0644]
lftools/cli/nexus2/user.py [new file with mode: 0644]
lftools/cli/nexus3/__init__.py
lftools/cli/nexus3/asset.py
lftools/cli/nexus3/privilege.py
lftools/cli/nexus3/repository.py
lftools/cli/nexus3/role.py
lftools/cli/nexus3/script.py
lftools/cli/nexus3/tag.py
lftools/cli/nexus3/task.py
lftools/cli/nexus3/user.py
lftools/cli/rtd.py
lftools/shell/dco.py
releasenotes/notes/nexus2-d2f5afe25daee1d3.yaml [new file with mode: 0644]
tox.ini

index 5b4657b..6c057d3 100644 (file)
--- 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,
index c1bc775..734ec0c 100644 (file)
@@ -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 (file)
index 0000000..f006997
--- /dev/null
@@ -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
index 6173f59..52ed254 100644 (file)
@@ -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 (file)
index 0000000..a4b4474
--- /dev/null
@@ -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."
similarity index 99%
rename from lftools/api/endpoints/nexus.py
rename to lftools/api/endpoints/nexus3.py
index df4d265..0e36bdf 100644 (file)
@@ -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.
index d39a4c1..f5cfcd7 100644 (file)
@@ -10,6 +10,8 @@
 
 """Read the Docs REST API interface."""
 
+__author__ = 'DW Talton'
+
 import json
 
 from lftools import config
index 87370a9..d87e741 100644 (file)
@@ -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)
index 4b1ec5e..a5e2f83 100644 (file)
@@ -9,6 +9,8 @@
 ##############################################################################
 """Script to check a git repository for commits missing DCO."""
 
+__author__ = 'DW Talton'
+
 import sys
 
 import click
index d9a2117..c11c17b 100644 (file)
@@ -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 (file)
index 0000000..4c21439
--- /dev/null
@@ -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 (file)
index 0000000..f396538
--- /dev/null
@@ -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 (file)
index 0000000..c2f2b37
--- /dev/null
@@ -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 (file)
index 0000000..37913b2
--- /dev/null
@@ -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 (file)
index 0000000..33b6401
--- /dev/null
@@ -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)
index d408520..5fc8260 100644 (file)
@@ -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)
index 1aac887..417a6b2 100644 (file)
 
 """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:
index 32841da..e9b94f8 100644 (file)
@@ -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"])
index 981fe13..312669c 100644 (file)
 
 """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))
index 6c25e1c..e021be5 100644 (file)
 
 """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))
index b02dc59..55201d9 100644 (file)
 
 """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)
index c98606d..4d9d006 100644 (file)
@@ -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))
index 5d30e25..405a27d 100644 (file)
@@ -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(
index 43821a7..1668fb2 100644 (file)
 
 """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(
index f38177a..2327cb3 100644 (file)
@@ -10,6 +10,8 @@
 
 """Read the Docs interface."""
 
+__author__ = 'DW Talton'
+
 
 import logging
 from pprint import pformat
index dc9b96d..d819435 100644 (file)
@@ -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 (file)
index 0000000..10c5ee1
--- /dev/null
@@ -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 87b25ba..fe8e633 100644 (file)
--- a/tox.ini
+++ b/tox.ini
@@ -8,7 +8,8 @@ envlist =
     pre-commit,
     py35,
     py36,
-    py37
+    py37,
+    py38
 skip_missing_interpreters = true
 
 [testenv]