@@ -88,16 +88,23 @@ async def create_gcp_attestation(
8888
8989 If the application isn't running on GCP or no credentials were found, raises an error.
9090 """
91- res = await session_manager .request (
92- method = "GET" ,
93- url = f"http://169.254.169.254/computeMetadata/v1/instance/service-accounts/default/identity?audience={ SNOWFLAKE_AUDIENCE } " ,
94- headers = {
95- "Metadata-Flavor" : "Google" ,
96- },
97- )
91+ try :
92+ res = await session_manager .request (
93+ method = "GET" ,
94+ url = f"http://169.254.169.254/computeMetadata/v1/instance/service-accounts/default/identity?audience={ SNOWFLAKE_AUDIENCE } " ,
95+ headers = {
96+ "Metadata-Flavor" : "Google" ,
97+ },
98+ )
99+
100+ content = await res .content .read ()
101+ jwt_str = content .decode ("utf-8" )
102+ except Exception as e :
103+ raise ProgrammingError (
104+ msg = f"Error fetching GCP metadata: { e } . Ensure the application is running on GCP." ,
105+ errno = ER_WIF_CREDENTIALS_NOT_FOUND ,
106+ )
98107
99- content = await res .content .read ()
100- jwt_str = content .decode ("utf-8" )
101108 _ , subject = extract_iss_and_sub_without_signature_verification (jwt_str )
102109 return WorkloadIdentityAttestation (
103110 AttestationProvider .GCP , jwt_str , {"sub" : subject }
@@ -139,15 +146,22 @@ async def create_azure_attestation(
139146 if managed_identity_client_id :
140147 query_params += f"&client_id={ managed_identity_client_id } "
141148
142- res = await session_manager .request (
143- method = "GET" ,
144- url = f"{ url_without_query_string } ?{ query_params } " ,
145- headers = headers ,
146- )
149+ try :
150+ res = await session_manager .request (
151+ method = "GET" ,
152+ url = f"{ url_without_query_string } ?{ query_params } " ,
153+ headers = headers ,
154+ )
155+
156+ content = await res .content .read ()
157+ response_text = content .decode ("utf-8" )
158+ response_data = json .loads (response_text )
159+ except Exception as e :
160+ raise ProgrammingError (
161+ msg = f"Error fetching Azure metadata: { e } . Ensure the application is running on Azure." ,
162+ errno = ER_WIF_CREDENTIALS_NOT_FOUND ,
163+ )
147164
148- content = await res .content .read ()
149- response_text = content .decode ("utf-8" )
150- response_data = json .loads (response_text )
151165 jwt_str = response_data .get ("access_token" )
152166 if not jwt_str :
153167 raise ProgrammingError (
0 commit comments