diff --git a/scripts/src/owners/owners_file.py b/scripts/src/owners/owners_file.py index fe3807b2..c348922a 100644 --- a/scripts/src/owners/owners_file.py +++ b/scripts/src/owners/owners_file.py @@ -13,6 +13,10 @@ class OwnersFileError(Exception): pass +class ConfigKeyMissing(Exception): + pass + + def get_owner_data(category, organization, chart): path = os.path.join("charts", category, organization, chart, "OWNERS") success = False @@ -61,7 +65,28 @@ def get_chart(owner_data): return chart -def get_web_catalog_only(owner_data): +def get_web_catalog_only(owner_data, raise_if_missing=False): + """Check the delivery method set in the OWNERS file data + + Args: + owner_data (dict): Content of the OWNERS file. Typically this is the return value of the + get_owner_data or get_owner_data_from_file function. + raise_if_missing (bool, optional): Whether to raise an Exception if the delivery method is + not set in the OWNERS data. If set to False, the function returns False. + + Raises: + ConfigKeyMissing: if the key is not found in OWNERS and raise_if_missing is set to True + + """ + if ( + "web_catalog_only" not in owner_data + and "providerDelivery" not in owner_data + and raise_if_missing + ): + raise ConfigKeyMissing( + "Neither web_catalog_only nor providerDelivery keys were set" + ) + return owner_data.get("web_catalog_only", False) or owner_data.get( "providerDelivery", False ) diff --git a/scripts/src/report/verifier_report.py b/scripts/src/report/verifier_report.py index 875444e6..cd3a7a86 100644 --- a/scripts/src/report/verifier_report.py +++ b/scripts/src/report/verifier_report.py @@ -43,6 +43,10 @@ KUBE_VERSION_ATTRIBUTE = "kubeVersion" +class ConfigKeyMissing(Exception): + pass + + def get_report_data(report_path): """Load and returns the report data contained in report.yaml @@ -105,20 +109,41 @@ def get_profile_version(report_data): return profile_version -def get_web_catalog_only(report_data): +def get_web_catalog_only(report_data, raise_if_missing=False): + """Check the delivery method set in the report data. + + Args: + report_data (dict): Content of the report file. Typically this is the return value of the + get_report_data function. + raise_if_missing (bool, optional): Whether to raise an Exception if the delivery method is + not set in the report data. If set to False, the function returns False. + + Raises: + ConfigKeyMissing: if the key is not found in OWNERS and raise_if_missing is set to True + + """ + keyFound = False web_catalog_only = False try: if "webCatalogOnly" in report_data["metadata"]["tool"]: web_catalog_only = report_data["metadata"]["tool"]["webCatalogOnly"] + keyFound = True if "providerControlledDelivery" in report_data["metadata"]["tool"]: web_catalog_only = report_data["metadata"]["tool"][ "providerControlledDelivery" ] + keyFound = True except Exception as err: print( f"Exception getting webCatalogOnly/providerControlledDelivery {err=}, {type(err)=}" ) pass + + if not keyFound and raise_if_missing: + raise ConfigKeyMissing( + "Neither webCatalogOnly nor providerControlledDelivery keys were set" + ) + return web_catalog_only