mirror of
https://github.com/ansible/awx.git
synced 2026-03-23 11:55:04 -02:30
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:
@@ -1990,6 +1990,9 @@ class InventorySourceSerializer(UnifiedJobTemplateSerializer, InventorySourceOpt
|
|||||||
fields = ('*', 'name', 'inventory', 'update_on_launch', 'update_cache_timeout',
|
fields = ('*', 'name', 'inventory', 'update_on_launch', 'update_cache_timeout',
|
||||||
'source_project', 'update_on_project_update') + \
|
'source_project', 'update_on_project_update') + \
|
||||||
('last_update_failed', 'last_updated') # Backwards compatibility.
|
('last_update_failed', 'last_updated') # Backwards compatibility.
|
||||||
|
extra_kwargs = {
|
||||||
|
'inventory': {'required': True}
|
||||||
|
}
|
||||||
|
|
||||||
def get_related(self, obj):
|
def get_related(self, obj):
|
||||||
res = super(InventorySourceSerializer, self).get_related(obj)
|
res = super(InventorySourceSerializer, self).get_related(obj)
|
||||||
|
|||||||
@@ -92,12 +92,14 @@ class ResourceOptionsParser(object):
|
|||||||
'field': int,
|
'field': int,
|
||||||
'integer': int,
|
'integer': int,
|
||||||
'boolean': strtobool,
|
'boolean': strtobool,
|
||||||
|
'field': int, # foreign key
|
||||||
}.get(param['type'], str),
|
}.get(param['type'], str),
|
||||||
}
|
}
|
||||||
meta_map = {
|
meta_map = {
|
||||||
'string': 'TEXT',
|
'string': 'TEXT',
|
||||||
'integer': 'INTEGER',
|
'integer': 'INTEGER',
|
||||||
'boolean': 'BOOLEAN',
|
'boolean': 'BOOLEAN',
|
||||||
|
'field': 'ID', # foreign key
|
||||||
}
|
}
|
||||||
if param.get('choices', []):
|
if param.get('choices', []):
|
||||||
kwargs['choices'] = [c[0] for c in param['choices']]
|
kwargs['choices'] = [c[0] for c in param['choices']]
|
||||||
@@ -110,6 +112,20 @@ class ResourceOptionsParser(object):
|
|||||||
elif param['type'] in meta_map:
|
elif param['type'] in meta_map:
|
||||||
kwargs['metavar'] = meta_map[param['type']]
|
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:
|
if required:
|
||||||
required_group.add_argument(
|
required_group.add_argument(
|
||||||
'--{}'.format(k),
|
'--{}'.format(k),
|
||||||
|
|||||||
Reference in New Issue
Block a user