mirror of
https://github.com/ansible/awx.git
synced 2024-10-28 02:25:27 +03:00
Merge pull request #4596 from ryanpetrello/fix-cli-required-args
cli: fix a few bugs related to required OPTIONS Reviewed-by: https://github.com/apps/softwarefactory-project-zuul
This commit is contained in:
commit
9e849ad3e6
@ -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)
|
||||
|
@ -92,12 +92,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']]
|
||||
@ -110,6 +112,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…
Reference in New Issue
Block a user