Skip to content

Commit

Permalink
Changes as per PR review
Browse files Browse the repository at this point in the history
  • Loading branch information
amendelzon committed Dec 18, 2024
1 parent 93dec15 commit 37e12db
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions middleware/admin/certificate_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,13 @@ def from_jsonfile(kls, path):
raise ValueError(
"Certificate file must contain an object as a top level element")

if certificate_map.get("version") not in kls.VERSION_MAPPING:
version = certificate_map.get("version")
if version not in kls.VERSION_MAPPING:
raise ValueError("Invalid or unsupported HSM certificate "
"version (supported versions are "
f"version {version} (supported versions are "
f"{", ".join(kls.VERSION_MAPPING.keys())})")

return kls.VERSION_MAPPING[certificate_map["version"]](certificate_map)
return kls.VERSION_MAPPING[version](certificate_map)
except (ValueError, json.JSONDecodeError) as e:
raise ValueError('Unable to read HSM certificate from "%s": %s' %
(path, str(e)))
Expand Down Expand Up @@ -220,9 +221,10 @@ def save_to_jsonfile(self, path):
file.write("%s\n" % json.dumps(self.to_dict(), indent=2))

def _parse(self, certificate_map):
if certificate_map.get("version") != self.VERSION:
version = certificate_map.get("version")
if version != self.VERSION:
raise ValueError("Invalid or unexpected HSM certificate version "
f"(expected {self.VERSION})")
f"{version} (expected {self.VERSION})")

if "targets" not in certificate_map or type(certificate_map["targets"]) != list:
raise ValueError("Missing or invalid targets")
Expand Down

0 comments on commit 37e12db

Please sign in to comment.