1
0
mirror of https://github.com/ansible/awx.git synced 2024-10-27 17:55:10 +03:00

Merge pull request #4697 from ryanpetrello/cli-human-uniqueness

cli: fix a minor bug in uniqueness rule detection

Reviewed-by: https://github.com/apps/softwarefactory-project-zuul
This commit is contained in:
softwarefactory-project-zuul[bot] 2019-09-10 15:01:34 +00:00 committed by GitHub
commit 19d6941034
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 11 deletions

View File

@ -181,7 +181,7 @@ class CLI(object):
_filter == '.' and
self.resource in UNIQUENESS_RULES
):
_filter = UNIQUENESS_RULES[self.resource]
_filter = ', '.join(UNIQUENESS_RULES[self.resource])
formatted = format_response(
response,

View File

@ -14,9 +14,9 @@ from .resource import DEPRECATED_RESOURCES_REVERSE
UNIQUENESS_RULES = {
'me': 'id, username',
'users': 'id, username',
'instances': 'id, hostname',
'me': ('id', 'username'),
'users': ('id', 'username'),
'instances': ('id', 'hostname'),
}
@ -34,17 +34,13 @@ def pk_or_name(v2, model_name, value, page=None):
if model_name in DEPRECATED_RESOURCES_REVERSE:
model_name = DEPRECATED_RESOURCES_REVERSE[model_name]
if model_name in UNIQUENESS_RULES:
identity = UNIQUENESS_RULES[model_name][-1]
if hasattr(v2, model_name):
page = getattr(v2, model_name)
if model_name in UNIQUENESS_RULES:
identity = UNIQUENESS_RULES[model_name][-1]
if page:
if model_name == 'users':
identity = 'username'
elif model_name == 'instances':
model_name = 'hostname'
results = page.get(**{identity: value})
if results.count == 1:
return int(results.results[0].id)