def add_to_call_parameters(self, call_parameters, parsed_args): # Check if ``--cli-input-json`` was specified in the command line. input_json = getattr(parsed_args, 'cli_input_json', None) if input_json is not None: # Retrieve the JSON from the file if needed. retrieved_json = get_paramfile(input_json) # Nothing was retrieved from the file. So assume the argument # is already a JSON string. if retrieved_json is None: retrieved_json = input_json try: # Try to load the JSON string into a python dictionary input_data = json.loads(retrieved_json) except ValueError as e: raise ParamError( self.name, "Invalid JSON: %s\nJSON received: %s" % (e, retrieved_json)) # We run the ParamFileVisitor over the input data to resolve any # paramfile references in it. input_data = ParamFileVisitor().visit( input_data, self._operation_model.input_shape) # Add the members from the input JSON to the call parameters. self._update_call_parameters(call_parameters, input_data) return True
def test_blob_visitor(self): contents = b'This is a test' filename = self.files.create_file('jobOne.hql', contents, mode='wb') # We have modified our test model to mark jobXml with x-no-paramfile. params = {'jobs': {'job1': {'script': 'fileb://' + filename, 'jobXml': 'fileb://' + filename}}} shape = self.resolver.get_shape_by_name( 'blob-test', 'BlobParamFileTest') visited = ParamFileVisitor().visit(params, shape) params['jobs']['job1']['script'] = contents self.assertEqual(params, visited)
def test_explicit_map_visitor(self): contents = 'This is a test' filename = self.files.create_file('jobOne.hql', contents) # We have modified our test model to mark jobXml with x-no-paramfile. params = {'jobs': {'job1': {'script': 'file://' + filename, 'jobXml': 'file://' + filename}}} shape = self.resolver.get_shape_by_name( 'map-paramfile-test', 'ExplicitMapParamFileTest') visited = ParamFileVisitor().visit(params, shape) params['jobs']['job1']['script'] = contents self.assertEqual(params, visited)
def test_visitor(self): contents = 'This is a test' filename = self.files.create_file('jobOne.hql', contents) # We have modified our test model to mark jobXml with x-no-paramfile. params = {'clusterName': u'foo', 'jobs': [{'hiveJob': {'script': 'file://' + filename, 'jobXml': 'file://' + filename}}]} shape = self.resolver.get_shape_by_name( 'submit-jobs-request', 'SubmitJobsRequest') visited = ParamFileVisitor().visit(params, shape) params['jobs'][0]['hiveJob']['script'] = contents self.assertEqual(params, visited)
def _build_call_parameters(self, args, arg_table): # We need to convert the args specified on the command # line as valid **kwargs we can hand to botocore. service_params = {} # args is an argparse.Namespace object so we're using vars() # so we can iterate over the parsed key/values. parsed_args = vars(args) for arg_object in arg_table.values(): py_name = arg_object.py_name if py_name in parsed_args: value = parsed_args[py_name] value = unpack_argument(arg_object, value) arg_object.add_to_params(service_params, value) # We run the ParamFileVisitor over the input data to resolve any # paramfile references in it. service_params = ParamFileVisitor().visit( service_params, self._operation_model.input_shape) return service_params