def parse(self, component_types): initial_value = self.initial_value if initial_value is None: return None type_name = self.sibling(SchemaInputType).value component_types = component_types or {} undefined_property_error = "Undefined property {1} in default value " \ "of input {0}." input_name = self.ancestor(InputSchemaProperty).name return utils.parse_value( value=initial_value, type_name=type_name, data_types=component_types, undefined_property_error_message=undefined_property_error, missing_property_error_message="Value of input {0} is missing " "property {1}.", node_name=input_name, path=[], raise_on_missing_property=True)
def parse(self, component_types): type_name = self.sibling(SchemaPropertyType).value initial_value = self.initial_value if initial_value is None: if type_name is not None and type_name not in constants.USER_PRIMITIVE_TYPES: initial_value = {} else: return None component_types = component_types or {} prop_name = self.ancestor(SchemaProperty).name undefined_property_error = "Undefined property {1} in default" " value of type {0}" current_type = self.ancestor(Schema).parent().name return utils.parse_value( value=initial_value, type_name=type_name, data_types=component_types, undefined_property_error_message=undefined_property_error, missing_property_error_message="illegal state", node_name=current_type, path=[prop_name], raise_on_missing_property=False, )
def parse(self, component_types): type_name = self.sibling(SchemaPropertyType).value initial_value = self.initial_value if initial_value is None: if type_name is not None \ and type_name not in constants.USER_PRIMITIVE_TYPES: initial_value = {} else: return None component_types = component_types or {} prop_name = self.ancestor(SchemaProperty).name undefined_property_error = 'Undefined property {1} in default' \ ' value of type {0}' current_type = self.ancestor(Schema).parent().name return utils.parse_value( value=initial_value, type_name=type_name, data_types=component_types, undefined_property_error_message=undefined_property_error, missing_property_error_message='illegal state', node_name=current_type, path=[prop_name], raise_on_missing_property=False)
def _set_plan_inputs(plan, inputs=None): inputs = inputs if inputs else {} # Verify inputs satisfied missing_inputs = [] for input_name, input_def in plan[INPUTS].items(): input_is_missing = False if input_name in inputs: try: str(json.dumps(inputs[input_name], ensure_ascii=False)) except UnicodeEncodeError: raise exceptions.DSLParsingInputTypeException( exceptions.ERROR_INVALID_CHARS, 'Illegal characters in input: {0}. ' 'Only valid ascii chars are supported.'.format(input_name)) else: if DEFAULT in input_def and input_def[DEFAULT] is not None: inputs[input_name] = input_def[DEFAULT] else: missing_inputs.append(input_name) input_is_missing = True # Verify inputs comply with the given constraints and also the # data_type, if mentioned input_constraints = constraints.extract_constraints(input_def) if not input_is_missing: constraints.validate_input_value( input_name, input_constraints, inputs[input_name]) try: utils.parse_value( value=inputs[input_name], type_name=input_def.get(TYPE, None), data_types=plan.get(DATA_TYPES, {}), undefined_property_error_message="Undefined property " "{1} in value of " "input {0}.", missing_property_error_message="Value of input {0} " "is missing property " "{1}.", node_name=input_name, path=[], raise_on_missing_property=True) except exceptions.DSLParsingLogicException as e: raise exceptions.DSLParsingException( exceptions.ERROR_INPUT_VIOLATES_DATA_TYPE_SCHEMA, str(e)) if missing_inputs: raise exceptions.MissingRequiredInputError( "Required inputs {0} were not specified - expected " "inputs: {1}".format(missing_inputs, list(plan[INPUTS])) ) # Verify all inputs appear in plan not_expected = [input_name for input_name in inputs if input_name not in plan[INPUTS]] if not_expected: raise exceptions.UnknownInputError( "Unknown inputs {0} specified - " "expected inputs: {1}".format(not_expected, list(plan[INPUTS]))) plan[INPUTS] = inputs
def _set_plan_inputs(plan, inputs, auto_correct_types, values_getter): inputs = inputs if inputs else {} # Verify inputs satisfied missing_inputs = [] for input_name, input_def in plan[INPUTS].items(): input_is_missing = skip_input_validation = False if input_name in inputs: try: str(json.dumps(inputs[input_name], ensure_ascii=False)) except UnicodeEncodeError: raise exceptions.DSLParsingInputTypeException( exceptions.ERROR_INVALID_CHARS, 'Illegal characters in input: {0}. ' 'Only valid ascii chars are supported.'.format(input_name)) elif DEFAULT in input_def and input_def[DEFAULT] is not None: inputs[input_name] = input_def[DEFAULT] else: # Try to get some defaults from the data_type maybe or in other # words just try to parse the value before validating it. try: parsed_value = utils.parse_value( {}, type_name=input_def.get(TYPE, None), data_types=plan.get(DATA_TYPES, {}), undefined_property_error_message="Undefined property " "{1} in value of " "input {0}.", missing_property_error_message="Value of input {0} " "is missing property " "{1}.", node_name=input_name, path=[], raise_on_missing_property=True) except exceptions.DSLParsingException: parsed_value = None finally: if parsed_value: inputs[input_name] = parsed_value elif input_def.get('required', True): missing_inputs.append(input_name) input_is_missing = True else: skip_input_validation = True inputs[input_name] = None if skip_input_validation: continue # Verify inputs comply with the given constraints and also the # data_type, if mentioned input_constraints = constraints.extract_constraints(input_def) if not input_is_missing: if auto_correct_types: inputs[input_name] = utils.cast_to_type( inputs[input_name], input_def.get(TYPE, None)) constraints.validate_input_value(input_name, input_constraints, inputs[input_name], input_def.get(TYPE), input_def.get(ITEM_TYPE), values_getter) inputs_complete = inputs[input_name] try: inputs_complete = utils.parse_value( value=inputs[input_name], type_name=input_def.get(TYPE, None), data_types=plan.get(DATA_TYPES, {}), undefined_property_error_message="Undefined property " "{1} in value of " "input {0}.", missing_property_error_message="Value of input {0} " "is missing property " "{1}.", node_name=input_name, path=[], raise_on_missing_property=True) except exceptions.DSLParsingLogicException as e: raise exceptions.DSLParsingException( exceptions.ERROR_INPUT_VIOLATES_DATA_TYPE_SCHEMA, str(e)) inputs[input_name] = inputs_complete if missing_inputs: raise exceptions.MissingRequiredInputError( "Required inputs {0} were not specified - expected " "inputs: {1}".format(missing_inputs, list(plan[INPUTS]))) # Verify all inputs appear in plan not_expected = [ input_name for input_name in inputs if input_name not in plan[INPUTS] ] if not_expected: raise exceptions.UnknownInputError("Unknown inputs {0} specified - " "expected inputs: {1}".format( not_expected, list(plan[INPUTS]))) plan[INPUTS] = inputs