Example #1
0
def dso_nexus_add_repo(url, login_username, login_password, verbose,
                       repository_names):
    """Add new Maven repositories to the Nexus instance specified by URL"""
    exit_code = 0
    errors = {}
    with nexus.Nexus(url, login_username, login_password,
                     verbosity=verbose) as api:
        for repository_name in repository_names.split(','):
            if not api.search_repos(repository_name):
                try:
                    if api.add_repo(repository_name) is not None:
                        print(f'{repository_name} added')
                    else:
                        exit_code += 1
                        print(f'{repository_name} failed')
                except Exception as e:
                    exit_code += 1
                    errors[repository_name] = e.msg
                    print(f'{repository_name} failed')
            else:
                print(f'{repository_name} ok')
    for repo, error in errors.items():
        sys.stderr.write(f'Error adding {repo}:\n{error}\n')
    sys.stderr.flush
    exit(exit_code)
Example #2
0
def dso_nexus_search_repo(url, login_username, login_password, verbose,
                          repository_name):
    """Search for and display information about a repository in the Nexus
    instance specified by URL"""
    with nexus.Nexus(url, login_username, login_password,
                     verbosity=verbose) as api:
        pprint(api.search_repos(repository_name))
Example #3
0
def dso_nexus_update_group_repo(url, login_username, login_password, verbose,
                                group_repository_name,
                                member_repository_names):
    """Update group repo with the list of member repositories"""
    exit_code = 0
    errors = {}
    with nexus.Nexus(url, login_username, login_password,
                     verbosity=verbose) as api:
        if api.search_repos(group_repository_name):
            try:
                if api.update_group_repo(
                        group_repository_name,
                        member_repository_names.split(',')) is not None:
                    print(f'group repo {group_repository_name} added')
                else:
                    exit_code += 1
                    print(f'group repo {group_repository_name} failed')
            except Exception as e:
                exit_code += 1
                errors[group_repository_name] = e.msg
                print(f'group repo {group_repository_name} failed')
        else:
            print(f'group repo {group_repository_name} doesn\'t exist')
    for repo, error in errors.items():
        sys.stderr.write(f'Error updating group repo {repo}:\n{error}\n')
    sys.stderr.flush
    exit(exit_code)
Example #4
0
def dso_nexus_run_script(url, login_username, login_password, verbose,
                         script_name, body):
    """Run the specified Script in the Nexus instance specified by URL"""
    with nexus.Nexus(url, login_username, login_password,
                     verbosity=verbose) as api:
        try:
            api.run_script(script_name, body)
        except Exception:
            print(f'{script_name} failed')
            exit(1)
Example #5
0
def dso_nexus_add_script(url, login_username, login_password, verbose,
                         script_name, script_content, script_type):
    """Add new Scripts to the Nexus instance specified by URL"""
    with nexus.Nexus(url, login_username, login_password,
                     verbosity=verbose) as api:
        try:
            api.add_script(script_name, script_content, script_type)
        except Exception:
            print(f'{script_name} failed')
            exit(1)
Example #6
0
def dso_nexus_add_user(url, login_username, login_password, verbose, usernames,
                       passwords):
    """Add users to the Nexus instance specified by URL"""
    exit_code = 0
    with nexus.Nexus(url, login_username, login_password,
                     verbosity=verbose) as api:
        for username, password in zip(usernames.split(','),
                                      passwords.split(',')):
            if api.search_users(username):
                print(f'{username} ok')
                continue
            new_user = api.add_user(username, password)
            if new_user is not None:
                print(f'{username} added')
            else:
                exit_code += 1
                print(f'{username} failed')
    exit(exit_code)
Example #7
0
def dso_nexus_list_repos(url, login_username, login_password, verbose):
    """List all of the repositories on the Nexus instance specified by URL"""
    with nexus.Nexus(url, login_username, login_password,
                     verbosity=verbose) as api:
        pprint(api.list_repos())
Example #8
0
def dso_nexus_search_user(url, login_username, login_password, verbose,
                          username):
    """Search for users by username on the Nexus instance specified by URL"""
    with nexus.Nexus(url, login_username, login_password,
                     verbosity=verbose) as api:
        pprint(api.search_users(username))