Lookup credential id and pass in credential rather than scm_credential (#24624)

* Lookup credential id and pass in credential rather than scm_credential

* Change the excepting handling to catch missing credentials

* Make error messages for not found lookups more useful
pull/24809/head
Lee Shakespeare 8 years ago committed by jctanner
parent 1487ec0ea2
commit def76a3c3b

@ -208,21 +208,27 @@ def main():
project = tower_cli.get_resource('project') project = tower_cli.get_resource('project')
try: try:
if state == 'present': if state == 'present':
org_res = tower_cli.get_resource('organization') try:
org = org_res.get(name=organization) org_res = tower_cli.get_resource('organization')
org = org_res.get(name=organization)
except (exc.NotFound) as excinfo:
module.fail_json(msg='Failed to update project, organization not found: {0}'.format(organization), changed=False)
try:
cred_res = tower_cli.get_resource('credential')
cred = cred_res.get(name=scm_credential)
except (exc.NotFound) as excinfo:
module.fail_json(msg='Failed to update project, credential not found: {0}'.format(scm_credential), changed=False)
result = project.modify(name=name, description=description, result = project.modify(name=name, description=description,
organization=org['id'], organization=org['id'],
scm_type=scm_type, scm_url=scm_url, local_path=local_path, scm_type=scm_type, scm_url=scm_url, local_path=local_path,
scm_branch=scm_branch, scm_clean=scm_clean, scm_credential=scm_credential, scm_branch=scm_branch, scm_clean=scm_clean, credential=cred['id'],
scm_delete_on_update=scm_delete_on_update, scm_delete_on_update=scm_delete_on_update,
scm_update_on_launch=scm_update_on_launch, scm_update_on_launch=scm_update_on_launch,
create_on_missing=True) create_on_missing=True)
json_output['id'] = result['id'] json_output['id'] = result['id']
elif state == 'absent': elif state == 'absent':
result = project.delete(name=name) result = project.delete(name=name)
except (exc.NotFound) as excinfo:
module.fail_json(msg='Failed to update project, organization not found: {0}'.format(excinfo), changed=False)
except (exc.ConnectionError, exc.BadRequest) as excinfo: except (exc.ConnectionError, exc.BadRequest) as excinfo:
module.fail_json(msg='Failed to update project: {0}'.format(excinfo), changed=False) module.fail_json(msg='Failed to update project: {0}'.format(excinfo), changed=False)

Loading…
Cancel
Save