Exemple #1
0
def format_security_options(security_option, field, type_context, edge_config):
    sections = []

    if security_option.configure_for_untrusted_downstream:
        sections.append(
            indent(
                4,
                'This field should be configured in the presence of untrusted *downstreams*.'
            ))
    if security_option.configure_for_untrusted_upstream:
        sections.append(
            indent(
                4,
                'This field should be configured in the presence of untrusted *upstreams*.'
            ))
    if edge_config.note:
        sections.append(indent(4, edge_config.note))

    example_dict = json_format.MessageToDict(edge_config.example)
    validate_fragment.validate_fragment(field.type_name[1:], example_dict)
    field_name = type_context.name.split('.')[-1]
    example = {field_name: example_dict}
    sections.append(
        indent(4, 'Example configuration for untrusted environments:\n\n') +
        indent(4, '.. code-block:: yaml\n\n') +
        '\n'.join(indent_lines(6,
                               yaml.dump(example).split('\n'))))

    return '.. attention::\n' + '\n\n'.join(sections)
def main():
    errors = []
    for arg in sys.argv[1:]:
        try:
            validate_fragment("envoy.config.bootstrap.v3.Bootstrap",
                              yaml.safe_load(pathlib.Path(arg).read_text()))
        except (ParseError, KeyError) as e:
            errors.append(arg)
            print(f"\nERROR (validation failed): {arg}\n{e}\n\n")

    if errors:
        raise SystemExit(
            f"ERROR: some configuration files ({len(errors)}) failed to validate"
        )
def main(output):
    # Load as YAML, emit as JSON and then parse as proto to provide type
    # checking.
    manifest = json_format.Parse(json.dumps(protodoc_manifest_untyped),
                                 manifest_pb2.Manifest())
    result = {}
    for field_name in manifest.fields:
        field = manifest.fields[field_name]
        example = json_format.MessageToDict(field.edge_config.example)
        parts = field_name.split(".")
        name = ".".join(parts[:-1])
        part = parts[-1]
        validate_fragment.validate_fragment(name, {part: example})
        result[field_name] = dict(note=field.edge_config.note, example=example)
    pathlib.Path(output).write_text(json.dumps(result))