def single_line_short_description(schema_or_field, strict=True): error = single_line_short_check(schema_or_field['field_details']['short'], schema_or_field['field_details']['name']) if error: if strict: raise ValueError(error) else: ecs_helpers.strict_warning(error)
def single_line_beta_description(schema_or_field, strict=True): if "\n" in schema_or_field['field_details']['beta']: msg = "Beta descriptions must be single line.\n" msg += f"Offending field or field set: {schema_or_field['field_details']['name']}" if strict: raise ValueError(msg) else: ecs_helpers.strict_warning(msg)
def single_line_short_override_description(schema_or_field, strict=True): for field in schema_or_field['schema_details']['reusable']['expected']: if not 'short_override' in field: continue error = single_line_short_check(field['short_override'], field['full']) if error: if strict: raise ValueError(error) else: ecs_helpers.strict_warning(error)
def check_example_value(field, strict=True): """ Checks if value of the example field is of type list or dict. Fails or warns (depending on strict mode) if so. """ example_value = field['field_details'].get('example', None) if isinstance(example_value, (list, dict)): name = field['field_details']['name'] msg = f"Example value for field `{name}` contains an object or array which must be quoted to avoid YAML interpretation." if strict: raise ValueError(msg) else: ecs_helpers.strict_warning(msg)
def single_line_short_description(schema_or_field, strict=True): short_length = len(schema_or_field['field_details']['short']) if "\n" in schema_or_field['field_details'][ 'short'] or short_length > SHORT_LIMIT: msg = "Short descriptions must be single line, and under {} characters (current length: {}).\n".format( SHORT_LIMIT, short_length) msg += "Offending field or field set: {}\nShort description:\n {}".format( schema_or_field['field_details']['name'], schema_or_field['field_details']['short']) if strict: raise ValueError(msg) else: ecs_helpers.strict_warning(msg)
def strict_warning_handler(message, strict): """Handles warnings based on --strict mode""" if strict: raise ValueError(message) else: ecs_helpers.strict_warning(message)