diff --git a/scripts/build_env/main.py b/scripts/build_env/main.py index bd470711..1091cc82 100644 --- a/scripts/build_env/main.py +++ b/scripts/build_env/main.py @@ -1,4 +1,6 @@ import argparse +import os +import pathlib from envgenehelper import * from envgenehelper.deployer import * @@ -278,11 +280,56 @@ def validate_appregdefs(render_dir, env_name): if os.path.exists(regdef_dir): regdef_files = findAllYamlsInDir(regdef_dir) if not regdef_files: - logger.info(f"No RegDef YAMLs found in {regdef_dir}") + print(f"[INFO] No RegDef YAMLs found in {regdef_dir}") for file in regdef_files: - logger.info(f"RegDef file: {file}") - validate_yaml_by_scheme_or_fail(file, "schemas/regdef.schema.json") - + print(f"[VALIDATING] RegDef file: {file}") + + # Detect version and use appropriate schema + regdef_content = openYaml(file) + version = str(regdef_content.get('version', '1.0')) + + if version != '1.0': + schema_path = "schemas/regdef-v2.schema.json" + print( + f" Using RegDef V2 schema for {os.path.basename(file)} " + f"(version: {version})" + ) + # Validate authConfig references for V2 + validate_regdef_v2_authconfig(regdef_content, file) + else: + schema_path = "schemas/regdef.schema.json" + print(f" Using RegDef V1 schema for {os.path.basename(file)}") + + validate_yaml_by_scheme_or_fail(file, schema_path) + + +def validate_regdef_v2_authconfig(regdef_content, file_path): + """Validate authConfig references in V2 RegDefs""" + auth_configs = regdef_content.get('authConfig', {}) + + # Config sections that may reference authConfig + config_sections = [ + 'mavenConfig', + 'dockerConfig', + 'goConfig', + 'rawConfig', + 'npmConfig', + 'helmConfig', + 'helmAppConfig', + ] + + for config_type in config_sections: + if config_type in regdef_content: + config = regdef_content[config_type] + if isinstance(config, dict) and 'authConfig' in config: + auth_ref = config['authConfig'] + if auth_ref not in auth_configs: + raise ValueError( + f"RegDef {os.path.basename(file_path)}: " + f"authConfig reference '{auth_ref}' in {config_type} " + f"not found in authConfig section. " + f"Available authConfigs: {list(auth_configs.keys())}" + ) def render_environment(env_name, cluster_name, templates_dir, all_instances_dir, output_dir, g_template_version, work_dir):