Skip to content

Commit

Permalink
Allow to be notified if delivery method is not set (openshift-helm-ch…
Browse files Browse the repository at this point in the history
…arts#345)

Add the option to be notified, via a raised Exception, if the file
(OWNERS or report.yaml) doesn't contain the keys corresponding to the
chart's delivery method.

Signed-off-by: Matthias Goerens <mgoerens@redhat.com>
  • Loading branch information
mgoerens authored May 30, 2024
1 parent eca28fa commit 97f5999
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
27 changes: 26 additions & 1 deletion scripts/src/owners/owners_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
)
Expand Down
27 changes: 26 additions & 1 deletion scripts/src/report/verifier_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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


Expand Down

0 comments on commit 97f5999

Please sign in to comment.