def metadata(self) -> dict: result = utils.from_yaml(METADATA_PATH) result.update(utils.from_yaml(CONTRIB_METADATA_PATH)) if not isinstance(result, dict): raise ExtensionsConfigurationError( f"Unable to parse metadata: {METADATA_PATH} {CONTRIB_METADATA_PATH}") return result
def main(): metadata_filepath = sys.argv[1] contrib_metadata_filepath = sys.argv[2] output_filename = sys.argv[3] generated_rst_dir = os.path.dirname(output_filename) security_rst_root = os.path.join(generated_rst_dir, "intro/arch_overview/security") extension_db = utils.from_yaml(metadata_filepath) contrib_extension_db = utils.from_yaml(contrib_metadata_filepath) for contrib_extension in contrib_extension_db.keys(): contrib_extension_db[contrib_extension]['contrib'] = True extension_db.update(contrib_extension_db) pathlib.Path(security_rst_root).mkdir(parents=True, exist_ok=True) security_postures = defaultdict(list) for extension, metadata in extension_db.items(): security_postures[metadata['security_posture']].append(extension) for sp, extensions in security_postures.items(): output_path = pathlib.Path(security_rst_root, 'secpos_%s.rst' % sp) content = '\n'.join( format_item(extension, extension_db[extension]) for extension in sorted(extensions) if extension_db[extension].get('status') != 'wip') output_path.write_text(content) with tarfile.open(output_filename, "w") as tar: tar.add(generated_rst_dir, arcname=".")
def config(self) -> dict: """Configuration for test types - eg deb/rpm This contains build information for different types of test image, and some defaults for specific test configuration. """ return utils.from_yaml(self.config_path)
def config(self) -> dict: """Config parsed from the provided path Expects a yaml file with distributions in the following format: ```yaml debian_buster: # Docker image tag name image: debian:buster-slim # File extension of installable packages, for packages signed for # particular distributions, this can be the distribution name and `.changes` # extension. ext: buster.changes ubuntu_foo: image: ubuntu:foo ext: foo.changes redhat_8.1: image: registry.access.redhat.com/ubi8/ubi:8.1 ``` """ config = utils.from_yaml(self.args.config) if not isinstance(config, dict): raise PackagesConfigurationError(f"Unable to parse configuration {self.args.config}") return config
def dependabot_config(self) -> dict: """Parsed dependabot config""" result = utils.from_yaml( self.path.joinpath(self.dependabot_config_path)) if not isinstance(result, dict): raise PipConfigurationError( f"Unable to parse dependabot config: {self.dependabot_config_path}" ) return result
def __init__(self): with open(r.Rlocation('envoy/docs/v2_mapping.json'), 'r') as f: self.v2_mapping = json.load(f) # Load as YAML, emit as JSON and then parse as proto to provide type # checking. protodoc_manifest_untyped = utils.from_yaml( r.Rlocation('envoy/docs/protodoc_manifest.yaml')) self.protodoc_manifest = manifest_pb2.Manifest() json_format.Parse(json.dumps(protodoc_manifest_untyped), self.protodoc_manifest)
def config(self) -> dict: """Configuration for test types - eg deb/rpm This contains build information for different types of test image, and some defaults for specific test configuration. """ result = utils.from_yaml(self.config_path) if not isinstance(result, dict): raise ConfigurationError( f"Unable to parse configuration: {self.config_path}") return result
def test_util_from_yaml(patches): patched = patches("pathlib", "yaml", prefix="tools.base.utils") with patched as (m_plib, m_yaml): assert utils.from_yaml("PATH") == m_yaml.safe_load.return_value assert (list(m_plib.Path.call_args) == [("PATH", ), {}]) assert (list(m_yaml.safe_load.call_args) == [ (m_plib.Path.return_value.read_text.return_value, ), {} ]) assert (list(m_plib.Path.return_value.read_text.call_args) == [(), {}])
def test_util_from_yaml(patches): patched = patches("open", "yaml", prefix="tools.base.utils") with patched as (m_open, m_yaml): assert utils.from_yaml("PATH") == m_yaml.safe_load.return_value assert (list(m_open.call_args) == [("PATH", ), {}]) assert (list(m_yaml.safe_load.call_args) == [ (m_open.return_value.__enter__.return_value.read.return_value, ), {} ]) assert (list( m_open.return_value.__enter__.return_value.read.call_args) == [(), {}])
'data_plane_agnostic': 'This extension does not operate on the data plane and hence is intended to be robust against untrusted traffic.', } # A map from the extension status value to a human readable text for extension # docs. EXTENSION_STATUS_VALUES = { '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.', } r = runfiles.Create() EXTENSION_DB = utils.from_yaml( r.Rlocation("envoy/source/extensions/extensions_metadata.yaml")) CONTRIB_EXTENSION_DB = utils.from_yaml( r.Rlocation("envoy/contrib/extensions_metadata.yaml")) # create an index of extension categories from extension db def build_categories(extensions_db): ret = {} for _k, _v in extensions_db.items(): for _cat in _v['categories']: ret.setdefault(_cat, []).append(_k) return ret EXTENSION_CATEGORIES = build_categories(EXTENSION_DB) CONTRIB_EXTENSION_CATEGORIES = build_categories(CONTRIB_EXTENSION_DB)
def dependabot_config(self) -> dict: """Parsed dependabot config""" return utils.from_yaml( os.path.join(self.path, self.dependabot_config_path))
def metadata(self) -> dict: return utils.from_yaml(METADATA_PATH)