Skip to content

Commit 040141b

Browse files
author
Jeel Oza
committed
[patch] Catch SSLError and RequestException in validateIBMEntitlementKey, return None instead of raising
1 parent 70787fc commit 040141b

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

‎src/mas/devops/utils.py‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def isVersionEqualOrAfter(_compare_to_version, _current_version):
8282
return current_version.compare(compareToVersion) >= 0
8383

8484

85-
def validateIBMEntitlementKey(entitlementKey: str, repository: str = "cp/mas/coreapi", timeout: int = 30) -> bool:
85+
def validateIBMEntitlementKey(entitlementKey: str, repository: str = "cp/mas/coreapi", timeout: int = 30):
8686
"""Validate IBM entitlement key against cp.icr.io registry.
8787
8888
This function validates an IBM entitlement key by attempting to obtain
@@ -95,10 +95,9 @@ def validateIBMEntitlementKey(entitlementKey: str, repository: str = "cp/mas/cor
9595
timeout (int, optional): Request timeout in seconds. Defaults to 30.
9696
9797
Returns:
98-
bool: True if key is valid and grants access to the repository, False otherwise.
99-
100-
Raises:
101-
requests.exceptions.RequestException: If network request fails.
98+
True if key is valid and grants access to the repository.
99+
False if authentication failed (key is wrong).
100+
None if a network or SSL error prevented validation (key status unknown).
102101
"""
103102
try:
104103
registry_url = f"https://cp.icr.io/v2/{repository}/tags/list"
@@ -166,6 +165,9 @@ def validateIBMEntitlementKey(entitlementKey: str, repository: str = "cp/mas/cor
166165
logger.error(f"Unexpected response (HTTP {response.status_code})")
167166
return False
168167

168+
except requests.exceptions.SSLError as e:
169+
logger.error(f"SSL certificate verification failed — could not reach cp.icr.io: {e}")
170+
return None
169171
except requests.exceptions.RequestException as e:
170172
logger.error(f"Request failed: {e}")
171-
raise
173+
return None

0 commit comments

Comments
 (0)