From: Eric Ball Date: Fri, 1 Mar 2019 23:43:29 +0000 (-0800) Subject: Add global extra roles for "nexus create repo" X-Git-Tag: v0.22.0~2^2 X-Git-Url: https://gerrit.linuxfoundation.org/infra/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F52%2F14752%2F2;p=releng%2Flftools.git Add global extra roles for "nexus create repo" This will allow users to specify common roles only once, rather than having to add "extra_privs" to each repo. Documents in the docs repo have also been updated, and are now linked to from the lftools docs. Issue: RELENG-291 Change-Id: Ia35d92fa742ca8202f1d4ad7794bf8549e0a8a77 Signed-off-by: Eric Ball --- diff --git a/docs/commands/nexus.rst b/docs/commands/nexus.rst index 0ac1a611..0df01963 100644 --- a/docs/commands/nexus.rst +++ b/docs/commands/nexus.rst @@ -28,6 +28,9 @@ repo .. program-output:: lftools nexus create repo --help +For details and examples, please see +:ref:`Create Nexus2 repos with lftools ` + .. _nexus-reorder-staged-repos: reorder-staged-repos diff --git a/lftools/cli/nexus.py b/lftools/cli/nexus.py index 56901580..a1d928a2 100644 --- a/lftools/cli/nexus.py +++ b/lftools/cli/nexus.py @@ -49,7 +49,7 @@ def create(ctx): @create.command() @click.option( '-c', '--config', type=str, required=True, - help='Repo config file for how to the Nexus repository should be created.') + help='Repo config file for how the Nexus repository should be created.') @click.option( '-s', '--settings', type=str, required=True, help='Config file containing administrative settings.') diff --git a/lftools/nexus/cmd.py b/lftools/nexus/cmd.py index 802470d2..b5301d7a 100644 --- a/lftools/nexus/cmd.py +++ b/lftools/nexus/cmd.py @@ -121,9 +121,14 @@ def create_repos(config_file, settings_file): with open(settings_file, 'r') as f: settings = yaml.safe_load(f) - for setting in ['nexus', 'user', 'password', 'email_domain']: + for setting in ['email_domain', 'base_groupId', 'repositories']: + if not setting in config: + log.error('{} needs to be defined in {}'.format(setting, config_file)) + sys.exit(1) + + for setting in ['nexus', 'user', 'password']: if not setting in settings: - log.error('{} needs to be defined'.format(setting)) + log.error('{} needs to be defined in {}'.format(setting, settings_file)) sys.exit(1) _nexus = Nexus(settings['nexus'], settings['user'], settings['password']) @@ -165,21 +170,26 @@ def create_repos(config_file, settings_file): except LookupError as e: _nexus.create_user(name, email, role_id, password, extra_privs) - def build_repo(repo, repoId, config, base_groupId): + def build_repo(repo, repoId, config, base_groupId, global_privs, email_domain): log.info('-> Building for {}.{} in Nexus'.format(base_groupId, repo)) groupId = '{}.{}'.format(base_groupId, repo) target = util.create_repo_target_regex(groupId) - if 'extra_privs' in config: + if not global_privs and not 'extra_privs' in config: + extra_privs = [] + elif global_privs: + extra_privs = global_privs + if 'extra_privs' in config: + extra_privs += config['extra_privs'] + log.info('Privileges for this repo:' + ', '.join(extra_privs)) + elif 'extra_privs' in config: extra_privs = config['extra_privs'] log.info('Privileges for this repo:' + ', '.join(extra_privs)) - else: - extra_privs = [] create_nexus_perms( repoId, [target], - settings['email_domain'], + email_domain, config['password'], extra_privs) @@ -192,11 +202,19 @@ def create_repos(config_file, settings_file): sub_repo, sub_repo_id, config['repositories'][sub_repo], - groupId) + groupId, + extra_privs, + email_domain) log.warning('Nexus repo creation started. Aborting now could leave tasks undone!') + if 'global_privs' in config: + global_privs = config['global_privs'] + else: + global_privs = [] + for repo in config['repositories']: - build_repo(repo, repo, config['repositories'][repo], config['base_groupId']) + build_repo(repo, repo, config['repositories'][repo], + config['base_groupId'], global_privs, config['email_domain']) def search(settings_file, url, repo, pattern):