From ea36be3a0e96dd12e95b4b77c8963092307013ca Mon Sep 17 00:00:00 2001 From: Ryan Petrello Date: Mon, 26 Aug 2019 13:03:58 -0400 Subject: [PATCH] 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 --- awx/api/serializers.py | 3 +++ awxkit/awxkit/cli/options.py | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/awx/api/serializers.py b/awx/api/serializers.py index bc35ed4710..4c5124e078 100644 --- a/awx/api/serializers.py +++ b/awx/api/serializers.py @@ -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) diff --git a/awxkit/awxkit/cli/options.py b/awxkit/awxkit/cli/options.py index 88e1ef06b2..68546d3ed3 100644 --- a/awxkit/awxkit/cli/options.py +++ b/awxkit/awxkit/cli/options.py @@ -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),