Пример #1
0
def main():
    state_map = ['present', 'absent', 'read', 'list']
    rclass_state_map = VALID_RCLASSES
    packageType_state_map = VALID_PACKAGETYPES
    module_args = dict(
        artifactory_url=dict(type='str', required=True),
        name=dict(type='str', required=True),
        repo_position=dict(type='int', default=None),
        repo_config=dict(type='str', default=None),
        username=dict(type='str', default=None),
        password=dict(type='str', no_log=True, default=None),
        auth_token=dict(type='str', no_log=True, default=None),
        validate_certs=dict(type='bool', default=False),
        client_cert=dict(type='path', default=None),
        client_key=dict(type='path', default=None),
        force_basic_auth=dict(type='bool', default=False),
        state=dict(type='str', default='read', choices=state_map),
        rclass=dict(type='str', default=None, choices=rclass_state_map),
        packageType=dict(type='str',
                         default=None,
                         choices=packageType_state_map),
        url=dict(type='str', default=None),
        repoLayoutRef=dict(type='str', default=None),
        repo_config_dict=dict(type='dict', default=dict()),
    )

    result = dict(changed=False,
                  original_message='',
                  message='',
                  config=dict())

    module = AnsibleModule(
        argument_spec=module_args,
        required_together=[['username', 'password']],
        required_one_of=[['password', 'auth_token']],
        mutually_exclusive=[['password', 'auth_token']],
        required_if=[['state', 'present', ['artifactory_url', 'name']],
                     ['state', 'absent', ['artifactory_url', 'name']],
                     ['state', 'read', ['artifactory_url', 'name']]],
        supports_check_mode=True,
    )

    artifactory_url = module.params['artifactory_url']
    repository = module.params['name']
    repo_position = module.params['repo_position']
    repo_config = module.params['repo_config']
    username = module.params['username']
    password = module.params['password']
    auth_token = module.params['auth_token']
    validate_certs = module.params['validate_certs']
    client_cert = module.params['client_cert']
    client_key = module.params['client_key']
    force_basic_auth = module.params['force_basic_auth']
    state = module.params['state']
    repo_config_dict = module.params['repo_config_dict']

    if repo_config:
        # temporarily convert to dict for validation
        repo_config = ast.literal_eval(repo_config)

    fail_messages = []

    fails = art_base.validate_config_params(repo_config, repo_config_dict,
                                            'repo_config', 'repo_config_dict')
    fail_messages.extend(fails)

    fails = art_base.validate_top_level_params('rclass', module, repo_config,
                                               repo_config_dict, 'repo_config',
                                               'repo_config_dict')
    fail_messages.extend(fails)
    fails = art_base.validate_top_level_params('packageType', module,
                                               repo_config, repo_config_dict,
                                               'repo_config',
                                               'repo_config_dict')
    fail_messages.extend(fails)
    fails = art_base.validate_top_level_params('url', module, repo_config,
                                               repo_config_dict, 'repo_config',
                                               'repo_config_dict')
    fail_messages.extend(fails)
    fails = art_base.validate_top_level_params('repoLayoutRef', module,
                                               repo_config, repo_config_dict,
                                               'repo_config',
                                               'repo_config_dict')
    fail_messages.extend(fails)

    # Populate failure messages
    failure_message = "".join(fail_messages)

    # Conflicting config values should not be resolved
    if failure_message:
        module.fail_json(msg=failure_message, **result)

    repo_dict = dict()
    if module.params['name']:
        repo_dict['key'] = module.params['name']
    if module.params['rclass']:
        repo_dict['rclass'] = module.params['rclass']
    if module.params['packageType']:
        repo_dict['packageType'] = module.params['packageType']
    if module.params['url']:
        repo_dict['url'] = module.params['url']
    if module.params['repoLayoutRef']:
        repo_dict['repoLayoutRef'] = module.params['repoLayoutRef']
    if repo_config:
        repo_dict.update(repo_config)
    if repo_config_dict:
        repo_dict.update(repo_config_dict)
    repo_config = str(repo_dict)

    result['original_message'] = ("Perform state '%s' against repo '%s' "
                                  "within artifactory '%s'" %
                                  (state, repository, artifactory_url))

    art_repo = ArtifactoryRepoManagement(artifactory_url=artifactory_url,
                                         repo=repository,
                                         repo_position=repo_position,
                                         repo_config=repo_config,
                                         username=username,
                                         password=password,
                                         auth_token=auth_token,
                                         validate_certs=validate_certs,
                                         client_cert=client_cert,
                                         client_key=client_key,
                                         force_basic_auth=force_basic_auth,
                                         config_map=URI_CONFIG_MAP)

    art_base.run_module(module, art_repo, "repos", result, fail_messages,
                        repo_config)
Пример #2
0
def main():
    state_map = ['present', 'absent', 'read', 'list']
    module_args = dict(
        artifactory_url=dict(type='str', required=True),
        name=dict(type='str', default=''),
        group_config=dict(type='str', default=None),
        username=dict(type='str', default=None),
        auth_password=dict(type='str', no_log=True, default=None),
        auth_token=dict(type='str', no_log=True, default=None),
        validate_certs=dict(type='bool', default=False),
        client_cert=dict(type='path', default=None),
        client_key=dict(type='path', default=None),
        force_basic_auth=dict(type='bool', default=False),
        state=dict(type='str', default='read', choices=state_map),
        group_config_dict=dict(type='dict', default=dict()),
    )

    result = dict(
        changed=False,
        original_message='',
        message='',
        config=dict()
    )

    module = AnsibleModule(
        argument_spec=module_args,
        required_together=[['username', 'auth_password']],
        required_one_of=[['auth_password', 'auth_token']],
        mutually_exclusive=[['auth_password', 'auth_token']],
        required_if=[['state', 'present', ['artifactory_url', 'name']],
                     ['state', 'absent', ['artifactory_url', 'name']],
                     ['state', 'read', ['artifactory_url', 'name']]],
        supports_check_mode=True,
    )

    artifactory_url = module.params['artifactory_url']
    name = module.params['name']
    group_config = module.params['group_config']
    username = module.params['username']
    auth_password = module.params['auth_password']
    auth_token = module.params['auth_token']
    validate_certs = module.params['validate_certs']
    client_cert = module.params['client_cert']
    client_key = module.params['client_key']
    force_basic_auth = module.params['force_basic_auth']
    state = module.params['state']
    group_config_dict = module.params['group_config_dict']

    if group_config:
        # temporarily convert to dict for validation
        group_config = ast.literal_eval(group_config)

    fail_messages = []

    fails = art_base.validate_config_params(group_config, group_config_dict,
                                            'group_config',
                                            'group_config_dict')
    fail_messages.extend(fails)
    fails = art_base.validate_top_level_params('name', module, group_config,
                                               group_config_dict,
                                               'group_config',
                                               'group_config_dict')
    fail_messages.extend(fails)

    # Populate failure messages
    failure_message = "".join(fail_messages)

    # Conflicting config values should not be resolved
    if failure_message:
        module.fail_json(msg=failure_message, **result)

    sec_dict = dict()
    if module.params['name']:
        sec_dict['name'] = module.params['name']
    if group_config:
        sec_dict.update(group_config)
    if group_config_dict:
        sec_dict.update(group_config_dict)
    group_config = str(sec_dict)

    result['original_message'] = ("Perform state '%s' against target '%s' "
                                  "within artifactory '%s'"
                                  % (state, name, artifactory_url))

    art_grp = art_base.ArtifactoryBase(
        artifactory_url=artifactory_url,
        name=name,
        art_config=group_config,
        username=username,
        password=auth_password,
        auth_token=auth_token,
        validate_certs=validate_certs,
        client_cert=client_cert,
        client_key=client_key,
        force_basic_auth=force_basic_auth,
        config_map=URI_CONFIG_MAP)
    art_base.run_module(module, art_grp, "groups", result,
                        fail_messages, group_config)
Пример #3
0
def main():
    state_map = ['present', 'absent', 'read', 'list']
    module_args = dict(
        artifactory_url=dict(type='str', required=True),
        name=dict(type='str', default=''),
        perm_config=dict(type='str', default=None),
        username=dict(type='str', default=None),
        auth_password=dict(type='str', no_log=True, default=None),
        auth_token=dict(type='str', no_log=True, default=None),
        validate_certs=dict(type='bool', default=False),
        client_cert=dict(type='path', default=None),
        client_key=dict(type='path', default=None),
        force_basic_auth=dict(type='bool', default=False),
        state=dict(type='str', default='read', choices=state_map),
        perm_config_dict=dict(type='dict', default=dict()),
        repositories=dict(type='list', default=None),
    )

    result = dict(changed=False,
                  original_message='',
                  message='',
                  config=dict())

    module = AnsibleModule(
        argument_spec=module_args,
        required_together=[['username', 'auth_password']],
        required_one_of=[['auth_password', 'auth_token']],
        mutually_exclusive=[['auth_password', 'auth_token']],
        required_if=[['state', 'present', ['artifactory_url', 'name']],
                     ['state', 'absent', ['artifactory_url', 'name']],
                     ['state', 'read', ['artifactory_url', 'name']]],
        supports_check_mode=True,
    )

    artifactory_url = module.params['artifactory_url']
    name = module.params['name']
    perm_config = module.params['perm_config']
    username = module.params['username']
    auth_password = module.params['auth_password']
    auth_token = module.params['auth_token']
    validate_certs = module.params['validate_certs']
    client_cert = module.params['client_cert']
    client_key = module.params['client_key']
    force_basic_auth = module.params['force_basic_auth']
    state = module.params['state']
    perm_config_dict = module.params['perm_config_dict']

    if perm_config:
        # temporarily convert to dict for validation
        perm_config = ast.literal_eval(perm_config)

    fail_messages = []

    fails = art_base.validate_config_params(perm_config, perm_config_dict,
                                            'perm_config', 'perm_config_dict')
    fail_messages.extend(fails)
    fails = art_base.validate_top_level_params('name', module, perm_config,
                                               perm_config_dict, 'perm_config',
                                               'perm_config_dict')
    fail_messages.extend(fails)
    fails = art_base.validate_top_level_params('repositories', module,
                                               perm_config, perm_config_dict,
                                               'perm_config',
                                               'perm_config_dict')
    fail_messages.extend(fails)

    # Populate failure messages
    failure_message = "".join(fail_messages)

    # Conflicting config values should not be resolved
    if failure_message:
        module.fail_json(msg=failure_message, **result)

    sec_dict = dict()
    if module.params['name']:
        sec_dict['name'] = module.params['name']
    if module.params['repositories']:
        sec_dict['repositories'] = module.params['repositories']
    if perm_config:
        sec_dict.update(perm_config)
    if perm_config_dict:
        sec_dict.update(perm_config_dict)
    # Artifactory stores the name as lowercase (even if it was passed as
    # multi-case). Calls against that name after it is created will fail
    # since artifactory only recognizes the lower case name.
    sec_dict['name'] = sec_dict['name'].lower()
    name = name.lower()
    perm_config = str(sec_dict)

    result['original_message'] = ("Perform state '%s' against target '%s' "
                                  "within artifactory '%s'" %
                                  (state, name, artifactory_url))

    art_perm = ArtifactoryPermissions(artifactory_url=artifactory_url,
                                      name=name,
                                      perm_config=perm_config,
                                      username=username,
                                      password=auth_password,
                                      auth_token=auth_token,
                                      validate_certs=validate_certs,
                                      client_cert=client_cert,
                                      client_key=client_key,
                                      force_basic_auth=force_basic_auth,
                                      config_map=URI_CONFIG_MAP)
    art_base.run_module(module, art_perm, "permission target", result,
                        fail_messages, perm_config)