def mbi_generate_config_templates(family: str) -> Dict[str, str]: """Generate all possible configuration for selected family. :param family: Family description. :raises SPSDKError: [description] :return: Dictionary of individual templates (key is name of template, value is template itself). """ ret: Dict[str, str] = {} # 1: Generate all configuration for MBI mbi_classes = get_mbi_classes(family) for mbi in mbi_classes: mbi_cls, target, authentication = mbi_classes[mbi] schemas = [] schemas.extend( mbi_get_validation_schemas(["family", "image_type", "output_file"])) schemas.extend(mbi_cls.get_validation_schemas()) override = {} override["family"] = family override["outputImageExecutionTarget"] = target override["outputImageAuthenticationType"] = authentication yaml_data = ConfigTemplate( f"Master Boot Image Configuration template for {family}, {mbi_cls.IMAGE_TYPE[1]}.", schemas, override, ).export_to_yaml() ret[mbi] = yaml_data return ret
def test_config_template(): schema = { "type": "object", "title": "main_title", "description": "main_description", "properties": { "n1": { "type": "bool", "title": "n1_title", "description": "n1_description", "default": "false", }, "n2": { "type": "string", "title": "n2_title", "description": "n2_description", "default": "n2_value", }, "n3": { "type": "string", "title": "n3_title", "description": "n3_description", "default": "n3_value", }, }, "required": ["n2"], "if": { "properties": { "n1": "true" } }, "then": { "required": ["n3"] }, } my_yml_template = ConfigTemplate("Super Main Title", [schema]).export_to_yaml() assert _is_yaml_comment(my_yml_template, "main_description") assert _is_yaml_comment(my_yml_template, "n1_description", "n1") assert _is_yaml_comment(my_yml_template, "n2_description", "n2") assert _is_yaml_comment(my_yml_template, "n3_description", "n3") assert _is_yaml_comment(my_yml_template, "[Optional]", "n1") assert _is_yaml_comment(my_yml_template, "[Required]", "n2") assert _is_yaml_comment(my_yml_template, "[Conditionally required]", "n3")
def get_template(schemas: Dict, name: str) -> str: """Get template for schemas :param schemas: dictionary with validation schemas :type schemas: Dict :param name: Name that will be displayed as a title :type name: str :return: string with YAML template :rtype: str """ override = {} yaml_data = ConfigTemplate( name, schemas, override, ).export_to_yaml() return yaml_data
def generate_config_template(cls, family: str) -> Dict[str, str]: """Generate configuration for selected family. :param family: Family description. :return: Dictionary of individual templates (key is name of template, value is template itself). """ ret: Dict[str, str] = {} config_file = cls.load_config_file() schemas = cls.get_validation_schemas() override = {} override["family"] = family override["revisions"] = config_file[family]["latest"] preset_properties = {} presets = load_configuration( os.path.join( TrustZone.PRESET_DIR, config_file[family]["revisions"][override["revisions"]])) for key, value in presets.items(): preset_properties[key] = { "type": ["string", "number"], "title": "TZ Preset", "description": f"Preset for {key}", "format": "number", "template_value": f"{value}", } schemas[0]["properties"]["trustZonePreset"][ "properties"] = preset_properties yaml_data = ConfigTemplate( f"Trust Zone Configuration template for {family}.", schemas, override, ).export_to_yaml() ret[f"{family}_tz"] = yaml_data return ret
def generate_config_template(cls, family: str) -> Dict[str, str]: """Generate configuration for selected family. :param family: Family description. :return: Dictionary of individual templates (key is name of template, value is template itself). """ ret: Dict[str, str] = {} if family in cls.get_supported_families(): config_file = cls.load_config_file() schemas = cls.get_validation_schemas(family) override = {} override["family"] = family override["revisions"] = config_file[family]["latest"] yaml_data = ConfigTemplate( f"Trust Zone Configuration template for {family}.", schemas, override, ).export_to_yaml() ret[f"{family}_tz"] = yaml_data return ret
def generate_config_template(cls, family: str) -> Dict[str, str]: """Generate configuration for selected family. :param family: Family description. :return: Dictionary of individual templates (key is name of template, value is template itself). """ ret: Dict[str, str] = {} if family in cls.get_supported_families(): schemas = cls.get_validation_schemas() schemas.append( ValidationSchemas.get_schema_file(SB3_SCH_FILE)["sb3_output"]) override = {} override["family"] = family yaml_data = ConfigTemplate( f"Secure Binary v3.1 Configuration template for {family}.", schemas, override, ).export_to_yaml() ret[f"{family}_sb31"] = yaml_data return ret