Skip to content

Commit

Permalink
fix(registry_handler): Handle no version found and source not available.
Browse files Browse the repository at this point in the history
  • Loading branch information
Noahnc committed Dec 4, 2023
1 parent b449b7f commit 592712d
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion infrapatch/core/utils/terraform/registry_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ def get_newest_version(self, resource: VersionedTerraformResource):
versions = response_data["versions"]
else:
raise Exception(f"Resource type '{type(resource)}' is not supported.")
if len(versions) == 0:
log.warning(f"No versions found for resource '{resource.source}'.")
return None
sorted_versions = sorted(versions, key=lambda k: StrictVersion(k["version"]), reverse=True)
newest_version = sorted_versions[0]["version"]

Expand Down Expand Up @@ -114,7 +117,11 @@ def get_source(self, resource: VersionedTerraformResource):

base_endpoint, registry_base_domain = self._compose_base_url(resource)
version_info_endpoint = f"{base_endpoint}/{resource.newest_version}"
response = self._send_request(version_info_endpoint, registry_base_domain)
try:
response = self._send_request(version_info_endpoint, registry_base_domain)
except TerraformRegistryException as e:
log.debug(f"Could not get source for resource '{resource.source}': {e}")
return None
response_data = json.loads(response.read())
if "source" not in response_data:
log.debug(f"Source not found in response data: {response_data}")
Expand Down

0 comments on commit 592712d

Please # to comment.