U
    ~fh                     @  s4   d Z ddlmZ ddlmZ dddddd	d
ZdS )zGCP helpers.    )annotations)Any   strfloatzdict[str, Any])resourcetimeoutreturnc              
   C  s   ddl m}m} d}|d|  7 }ddi}|||d}z0|||d}|j}| d	}	W 5 Q R X W n4 tk
r }
 zd
|
 }t|d W 5 d }
~
X Y nX |dkrd}t|t|	dS )Nr   )RequesturlopenzMhttp://metadata/computeMetadata/v1/instance/service-accounts/default/identityz
?audience=zMetadata-FlavorZGoogle)headers)r   utf8z'Failed to acquire IMDS access token: %s   z$Failed to acquire IMDS access token.)Zaccess_token)	urllib.requestr
   r   statusreaddecode	Exception
ValueErrordict)r   r   r
   r   urlr   requestresponser   bodyemsg r   8/tmp/pip-unpacked-wheel-36gvocj8/pymongo/_gcp_helpers.py_get_gcp_response   s     r   N)r   )__doc__
__future__r   typingr   r   r   r   r   r   <module>   s   