def load_schemas(ref=None, included_files=[]): """Loads ECS and custom schemas. They are returned deeply nested and merged.""" # ECS fields (from git ref or not) if ref: schema_files_raw = load_schemas_from_git(ref) else: schema_files_raw = load_schema_files(ecs_helpers.ecs_files()) fields = deep_nesting_representation(schema_files_raw) # Custom additional files if included_files and len(included_files) > 0: print('Loading user defined schemas: {0}'.format(included_files)) # If --ref provided and --include loading experimental schemas if ref and EXPERIMENTAL_SCHEMA_DIR in included_files: exp_schema_files_raw = load_schemas_from_git( ref, target_dir=EXPERIMENTAL_SCHEMA_DIR) exp_fields = deep_nesting_representation(exp_schema_files_raw) fields = merge_fields(fields, exp_fields) included_files.remove(EXPERIMENTAL_SCHEMA_DIR) # Remaining additional custom files (never from git ref) custom_files = ecs_helpers.glob_yaml_files(included_files) custom_fields = deep_nesting_representation( load_schema_files(custom_files)) fields = merge_fields(fields, custom_fields) return fields
def load_schemas_from_files(files=ecs_helpers.ecs_files()): schemas = [] for file in files: with open(file) as f: content = f.read() schemas.append(content) return schemas
def load_schemas(ref=None, included_files=[]): """Loads ECS and custom schemas. They are returned deeply nested and merged.""" # ECS fields (from git ref or not) if ref: schema_files_raw = load_schemas_from_git(ref) else: schema_files_raw = load_schema_files(ecs_helpers.ecs_files()) fields = deep_nesting_representation(schema_files_raw) # Custom additional files (never from git ref) if included_files and len(included_files) > 0: print('Loading user defined schemas: {0}'.format(included_files)) custom_files = ecs_helpers.get_glob_files(included_files, ecs_helpers.YAML_EXT) custom_fields = deep_nesting_representation( load_schema_files(custom_files)) fields = merge_fields(fields, custom_fields) return fields
def load_schemas(files=ecs_helpers.ecs_files()): """Loads the list of files and performs schema level cleanup""" fields_intermediate = load_schema_files(files) finalize_schemas(fields_intermediate) return fields_intermediate