-
Notifications
You must be signed in to change notification settings - Fork 5.3k
[WIP] bazel: Add python data providers #17998
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| security_postures: | ||
| robust_to_untrusted_downstream: > | ||
| This extension is intended to be robust against untrusted downstream | ||
| traffic. It assumes that the upstream is trusted. | ||
| robust_to_untrusted_downstream_and_upstream: > | ||
| This extension is intended to be robust against both untrusted | ||
| downstream and upstream traffic. | ||
| requires_trusted_downstream_and_upstream: > | ||
| This extension is not hardened and should only be used in | ||
| deployments where both the downstream and upstream are trusted. | ||
| unknown: > | ||
| This extension has an unknown security posture and should only be | ||
| used in deployments where both the downstream and upstream are | ||
| trusted. | ||
| data_plane_agnostic: > | ||
| This extension does not operate on the data plane and hence is | ||
| intended to be robust against untrusted traffic. | ||
|
|
||
| status_types: | ||
| alpha: > | ||
| This extension is functional but has not had substantial production | ||
| burn time, use only with this caveat. | ||
| wip: > | ||
| This extension is work-in-progress. Functionality is incomplete and | ||
| it is not intended for production use. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| load("@envoy_repo//:utils.bzl", "py_data") | ||
|
|
||
| licenses(["notice"]) # Apache 2 | ||
|
|
||
| py_data( | ||
| name = "v3_proto_rst", | ||
| filters = ["//filters:proto_rst_srcs"], | ||
| source = "@envoy_api//:v3_proto_srcs", | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| load("@envoy_repo//:utils.bzl", "py_data") | ||
|
|
||
| licenses(["notice"]) # Apache 2 | ||
|
|
||
| py_data( | ||
| name = "repository_locations", | ||
| filters = ["//filters:interpolate_repository_locations"], | ||
| source = "@envoy_api//bazel:repository_locations.json", | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| load("@envoy_repo//:utils.bzl", "py_data") | ||
|
|
||
| licenses(["notice"]) # Apache 2 | ||
|
|
||
| py_data( | ||
| name = "repository_locations", | ||
| filters = ["//filters:interpolate_repository_locations"], | ||
| source = "@envoy//bazel:repository_locations.json", | ||
| ) | ||
|
|
||
| py_data( | ||
| name = "all_repository_locations", | ||
| filters = ["//filters:add_api_repository_locations"], | ||
| source = "@envoy//bazel:repository_locations.json", | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| load("@envoy_repo//:utils.bzl", "py_data") | ||
|
|
||
| licenses(["notice"]) # Apache 2 | ||
|
|
||
| py_data( | ||
| name = "extensions_metadata", | ||
| source = "@envoy//contrib:extensions_metadata.yaml", | ||
| ) | ||
|
|
||
| py_data( | ||
| name = "extensions_categories", | ||
| filters = ["//filters:build_categories"], | ||
| source = "@envoy//contrib:extensions_metadata.yaml", | ||
| ) | ||
|
|
||
| py_data( | ||
| name = "extensions_build_config", | ||
| source = "@envoy//contrib:contrib_extensions_build_config.json", | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| load("@envoy_repo//:utils.bzl", "py_data") | ||
|
|
||
| licenses(["notice"]) # Apache 2 | ||
|
|
||
| py_data( | ||
| name = "protodoc_manifest", | ||
| source = "@envoy//docs:protodoc_manifest.yaml", | ||
| ) | ||
|
|
||
| py_data( | ||
| name = "v2_mapping", | ||
| source = "@envoy//docs:v2_mapping.json", | ||
| ) | ||
|
|
||
| py_data( | ||
| name = "empty_extensions", | ||
| filters = ["//filters:empty_extensions"], | ||
| source = "@envoy//docs:empty_extensions.json", | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| load("@dev_pip3//:requirements.bzl", dev_requirement = "requirement") | ||
| load("@rules_python//python:defs.bzl", "py_library") | ||
|
|
||
| py_library( | ||
| name = "proto_rst_srcs", | ||
| srcs = ["proto_rst_srcs.py"], | ||
| visibility = ["//visibility:public"], | ||
| ) | ||
|
|
||
| py_library( | ||
| name = "empty_extensions", | ||
| srcs = ["empty_extensions.py"], | ||
| visibility = ["//visibility:public"], | ||
| ) | ||
|
|
||
| py_library( | ||
| name = "interpolate_repository_locations", | ||
| srcs = ["interpolate_repository_locations.py"], | ||
| visibility = ["//visibility:public"], | ||
| ) | ||
|
|
||
| py_library( | ||
| name = "add_api_repository_locations", | ||
| srcs = ["add_api_repository_locations.py"], | ||
| deps = ["//api/bazel:repository_locations_py"], | ||
| visibility = ["//visibility:public"], | ||
| ) | ||
|
|
||
| py_library( | ||
| name = "build_categories", | ||
| srcs = ["build_categories.py"], | ||
| visibility = ["//visibility:public"], | ||
| ) | ||
|
|
||
| py_library( | ||
| name = "add_contrib_extensions_metadata", | ||
| srcs = ["add_contrib_extensions_metadata.py"], | ||
| deps = ["//contrib:extensions_metadata_py"], | ||
| visibility = ["//visibility:public"], | ||
| ) | ||
|
|
||
| py_library( | ||
| name = "extension_security_postures", | ||
| srcs = ["extension_security_postures.py"], | ||
| visibility = ["//visibility:public"], | ||
| deps = [dev_requirement("envoy.docs.abstract")], | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| from envoy_repo.api.bazel import repository_locations | ||
|
|
||
|
|
||
| def main(data): | ||
| data.update(repository_locations.data.copy()) | ||
| return data |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| from envoy_repo.contrib import extensions_metadata | ||
|
|
||
|
|
||
| def main(data): | ||
| contrib_extensions = extensions_metadata.data.copy() | ||
| for v in contrib_extensions.values(): | ||
| v['contrib'] = True | ||
| data.update(contrib_extensions) | ||
| return data |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| # create an index of extension categories from extension dbs | ||
| def main(data): | ||
| ret = {} | ||
| for _k, _v in data.items(): | ||
| for _cat in _v['categories']: | ||
| ret.setdefault(_cat, []).append(_k) | ||
| return ret |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| import pathlib | ||
|
|
||
|
|
||
| def main(data): | ||
| for k, v in data.items(): | ||
| v["docs_path"] = str(pathlib.Path(v['path'], 'empty', f"{v['path'].split('/').pop()}.rst")) | ||
| return data |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| """Transform the extensions metadata dict into the security postures dict""" | ||
|
|
||
| from collections import defaultdict | ||
|
|
||
| from envoy.docs import abstract | ||
|
|
||
|
|
||
| def main(data: abstract.ExtensionsMetadataDict) -> abstract.ExtensionSecurityPosturesDict: | ||
| security_postures = defaultdict(list) | ||
| for extension, metadata in data.items(): | ||
| security_postures[metadata['security_posture']].append(extension) | ||
| return security_postures |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| def format_data(s, data): | ||
| return s.format( | ||
| version=data["version"], | ||
| underscore_version=data["version"].replace(".", "_"), | ||
| dash_version=data["version"].replace(".", "-")) | ||
|
|
||
|
|
||
| def main(data): | ||
| for k, v in data.items(): | ||
| # this should reflect any transformations in `api/bazel/repository_locations_utils.bzl` | ||
| if not v.get("version"): | ||
| data[k] = v | ||
| continue | ||
| v["strip_prefix"] = format_data(v.get("strip_prefix", ""), v) | ||
| v["urls"] = [format_data(url, v) for url in v.get("urls", [])] | ||
| data[k] = v | ||
| return data |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| """Transform bazel api labels into rst paths in the docs""" | ||
|
|
||
| from typing import Tuple | ||
|
|
||
|
|
||
| def format_proto_src(src: str) -> str: | ||
| """Transform api bazel Label -> rst path in docs | ||
|
|
||
| eg: | ||
| @envoy_api//envoy/watchdog/v3alpha:abort_action.proto | ||
|
|
||
| -> envoy/watchdog/v3alpha/abort_action.proto.rst | ||
| """ | ||
| return f"{src.replace(':', '/').strip('@').replace('//', '/')[10:]}.rst" | ||
|
|
||
|
|
||
| def main(data) -> Tuple[str]: | ||
| return tuple(format_proto_src(src) for src in data if src) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| load("@rules_python//python:defs.bzl", "py_binary") | ||
|
|
||
| licenses(["notice"]) # Apache 2 | ||
|
|
||
| exports_files([ | ||
| "load_data.py", | ||
| "print_data.py", | ||
| ]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import os | ||
| import pathlib | ||
| from rules_python.python.runfiles import runfiles | ||
|
|
||
| __IMPORTS__ # noqa: F821 | ||
|
|
||
| _loader = __LOADER__ # noqa: F821 | ||
|
|
||
|
|
||
| def _resolve(provided_path): | ||
| # Resolve the path, to the data file | ||
| # Adapts the filepath to work in different invokations | ||
| # ie - run, build, genrules, etc | ||
| path = pathlib.Path(provided_path) | ||
| if path.exists(): | ||
| return path | ||
| run = runfiles.Create() | ||
| location = run.Rlocation(str(path).strip(".").strip("/")) | ||
| if location: | ||
| path = pathlib.Path(location) | ||
| if not path.exists(): | ||
| # If the build is invoked from the envoy workspace it has no prefix, | ||
| # so search in the runfiles with `envoy/` prefix to path. | ||
| path = pathlib.Path(run.Rlocation(os.path.join("envoy", provided_path))) | ||
| return path | ||
| raise Exception(f"Unable to find data file {provided_path}") | ||
|
|
||
|
|
||
| data = _loader(_resolve("__DATA_FILE__").read_text()) | ||
|
|
||
| _filters = __FILTERS__ # noqa: F821 | ||
|
|
||
| _filters = (_filters,) if not isinstance(_filters, tuple) else _filters | ||
|
|
||
| for _filter in _filters: | ||
| data = _filter(data) | ||
|
|
||
| __all__ = ("data",) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tuple[str, ...]