mirror of
https://github.com/ansible/awx.git
synced 2026-01-09 23:12:08 -03:30
cli: fix a few bugs related to required OPTIONS
see: https://github.com/ansible/awx/issues/4581 see: https://github.com/ansible/awx/issues/4583 see: https://github.com/ansible/awx/issues/4560
This commit is contained in:
parent
e19035079e
commit
ea36be3a0e
@ -1990,6 +1990,9 @@ class InventorySourceSerializer(UnifiedJobTemplateSerializer, InventorySourceOpt
|
||||
fields = ('*', 'name', 'inventory', 'update_on_launch', 'update_cache_timeout',
|
||||
'source_project', 'update_on_project_update') + \
|
||||
('last_update_failed', 'last_updated') # Backwards compatibility.
|
||||
extra_kwargs = {
|
||||
'inventory': {'required': True}
|
||||
}
|
||||
|
||||
def get_related(self, obj):
|
||||
res = super(InventorySourceSerializer, self).get_related(obj)
|
||||
|
||||
@ -88,12 +88,14 @@ class ResourceOptionsParser(object):
|
||||
'field': int,
|
||||
'integer': int,
|
||||
'boolean': strtobool,
|
||||
'field': int, # foreign key
|
||||
}.get(param['type'], str),
|
||||
}
|
||||
meta_map = {
|
||||
'string': 'TEXT',
|
||||
'integer': 'INTEGER',
|
||||
'boolean': 'BOOLEAN',
|
||||
'field': 'ID', # foreign key
|
||||
}
|
||||
if param.get('choices', []):
|
||||
kwargs['choices'] = [c[0] for c in param['choices']]
|
||||
@ -106,6 +108,20 @@ class ResourceOptionsParser(object):
|
||||
elif param['type'] in meta_map:
|
||||
kwargs['metavar'] = meta_map[param['type']]
|
||||
|
||||
if param['type'] == 'field':
|
||||
kwargs['help'] = 'the ID of the associated {}'.format(k)
|
||||
|
||||
# SPECIAL CUSTOM LOGIC GOES HERE :'(
|
||||
# There are certain requirements that aren't captured well by our
|
||||
# HTTP OPTIONS due to $reasons
|
||||
# This is where custom handling for those goes.
|
||||
if self.resource == 'users' and method == 'create' and k == 'password':
|
||||
kwargs['required'] = required = True
|
||||
if self.resource == 'ad_hoc_commands' and method == 'create' and k in ('inventory', 'credential'):
|
||||
kwargs['required'] = required = True
|
||||
if self.resource == 'job_templates' and method == 'create' and k in ('project', 'playbook'):
|
||||
kwargs['required'] = required = True
|
||||
|
||||
if required:
|
||||
required_group.add_argument(
|
||||
'--{}'.format(k),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user