def accumulate_field(details, memo): '''Visitor function that accumulates all field details in the memo dict''' if 'schema_details' in details or ecs_helpers.is_intermediate(details): return field_details = copy.deepcopy(details['field_details']) remove_internal_attributes(field_details) flat_name = field_details['flat_name'] memo[flat_name] = field_details
def field_assertions_and_warnings(field): '''Additional checks on a fleshed out field''' if not ecs_helpers.is_intermediate(field): single_line_short_description(field) if field['field_details']['level'] not in ACCEPTABLE_FIELD_LEVELS: msg = "Invalid level for field '{}'.\nValue: {}\nAcceptable values: {}".format( field['field_details']['name'], field['field_details']['level'], ACCEPTABLE_FIELD_LEVELS) raise ValueError(msg)
def field_cleanup(field): field_mandatory_attributes(field) if ecs_helpers.is_intermediate(field): return ecs_helpers.dict_clean_string_values(field['field_details']) if 'allowed_values' in field['field_details']: for allowed_value in field['field_details']['allowed_values']: ecs_helpers.dict_clean_string_values(allowed_value) field_defaults(field) field_assertions_and_warnings(field)
def field_mandatory_attributes(field): '''Ensures for the presence of the mandatory field attributes and raises if any are missing''' if ecs_helpers.is_intermediate(field): return current_field_attributes = sorted(field['field_details'].keys()) missing_attributes = ecs_helpers.list_subtract(FIELD_MANDATORY_ATTRIBUTES, current_field_attributes) if len(missing_attributes) > 0: msg = "Field is missing the following mandatory attributes: {}.\nFound these: {}.\nField details: {}" raise ValueError(msg.format(', '.join(missing_attributes), current_field_attributes, field))
def field_cleanup(field): field_mandatory_attributes(field) if ecs_helpers.is_intermediate(field): return ecs_helpers.dict_clean_string_values(field['field_details']) # TODO Temporarily commented out to simplify initial rewrite review # if 'allowed_values' in field['field_details']: # for allowed_value in field['field_details']['allowed_values']: # ecs_helpers.dict_clean_string_values(allowed_value) field_defaults(field) field_assertions_and_warnings(field)
def field_assertions_and_warnings(field): '''Additional checks on a fleshed out field''' if not ecs_helpers.is_intermediate(field): # check short description length if in strict mode single_line_short_description(field, strict=strict_mode) check_example_value(field, strict=strict_mode) if 'beta' in field['field_details']: single_line_beta_description(field, strict=strict_mode) if field['field_details']['level'] not in ACCEPTABLE_FIELD_LEVELS: msg = "Invalid level for field '{}'.\nValue: {}\nAcceptable values: {}".format( field['field_details']['name'], field['field_details']['level'], ACCEPTABLE_FIELD_LEVELS) raise ValueError(msg)
def field_mandatory_attributes(field): """Ensures for the presence of the mandatory field attributes and raises if any are missing""" if ecs_helpers.is_intermediate(field): return current_field_attributes = sorted(field['field_details'].keys()) missing_attributes = ecs_helpers.list_subtract(FIELD_MANDATORY_ATTRIBUTES, current_field_attributes) # `alias` fields require a target `path` attribute. if field['field_details'].get('type') == 'alias' and 'path' not in current_field_attributes: missing_attributes.append('path') # `scaled_float` fields require a `scaling_factor` attribute. if field['field_details'].get('type') == 'scaled_float' and 'scaling_factor' not in current_field_attributes: missing_attributes.append('scaling_factor') if len(missing_attributes) > 0: msg = "Field is missing the following mandatory attributes: {}.\nFound these: {}.\nField details: {}" raise ValueError(msg.format(', '.join(missing_attributes), current_field_attributes, field))