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:
commit
19d6941034
@ -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,
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user