in src/local_gpu_verifier/src/verifier/cc_admin_utils.py [0:0]
def fetch_rim_file_from_url(rim_id, url, max_retries):
""" A static method to fetch the RIM file with the given file id from the given url.
If the fetch fails, it retries for the maximum number of times specified by the max_retries parameter.
If the max_retries is set to 0, it does not retry on failure and return None.
Args:
rim_id (str): the RIM file id which need to be fetched from the given url.
url (str): the url from which the RIM file needs to be fetched.
max_retries (int, optional): the maximum number of retries to be performed in case of any error.
Returns:
[str]: the content of the required RIM file as a string.
"""
# RIM service URL should start with https
if not url.lower().startswith("https"):
info_log.error(f"The RIM service url {url} does not start with https")
return None
# Fetching the RIM file from the given url
try:
with request.urlopen(url + rim_id) as https_response:
data = https_response.read()
json_object = json.loads(data)
base64_data = json_object["rim"]
decoded_str = base64.b64decode(base64_data).decode("utf-8")
event_log.debug(f"Successfully fetched the RIM file from {url + rim_id}")
return decoded_str
except Exception as e:
event_log.error(f"Error while fetching the RIM file from {url + rim_id}")
if isinstance(e, HTTPError):
event_log.error(f"HTTP Error code : {e.code}")
if max_retries > 0:
time.sleep(BaseSettings.RIM_SERVICE_RETRY_DELAY)
return CcAdminUtils.fetch_rim_file_from_url(rim_id, url, max_retries - 1)
else:
return None