HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //lib/python3/dist-packages/uaclient/clouds/__pycache__/gcp.cpython-310.pyc
o

nHJe��@s�ddlZddlZddlZddlZddlmZmZmZmZddl	m
Z
mZmZm
Z
ddlmZe�e
�e��ZdZdZdZdZd	Zd
Zddd
dd�ZGdd�de�ZdS)�N)�Any�Dict�List�Optional)�
exceptions�http�system�util)�AutoAttachCloudInstancez�http://metadata/computeMetadata/v1/instance/service-accounts/default/identity?audience=contracts.canonical.com&format=full&licenses=TRUEzThttp://metadata.google.internal/computeMetadata/v1/instance/licenses/?recursive=truez&wait_for_change=truez&last_etag={etag}z/sys/class/dmi/id/product_namezGoogle Compute Engine�8045211386737108299�6022427724719891830�599959289349842382�2592866803419978320)�xenial�bionic�focal�jammyc@s�eZdZdd�Zeejejgd�d�de	e
effdd���Zede
fdd	��Z
edefd
d��Zdee
fdd
�Zdefdd�Zdedefdd�ZdS)�UAAutoAttachGCPInstancecCs
d|_dS)N��etag��self�r�5/usr/lib/python3/dist-packages/uaclient/clouds/gcp.py�__init__$s
z UAAutoAttachGCPInstance.__init__)g�?�r)�retry_sleeps�returncCsftjtddidd�}|jdkrd|jiS|j�d�}|r*d|��vr*tj	|j|d	��tj
|j|jd
��)N�Metadata-Flavor�Googler)�headers�timeout���
identityToken�error_descriptionzservice account)�status_code�	error_msg)�code�body)r�readurl�	TOKEN_URLr'r(�	json_dict�get�lowerr�GCPServiceAccountError�CloudMetadataError)r�response�
error_descrrr�identity_doc+s
�

��z$UAAutoAttachGCPInstance.identity_doccCsdS)N�gcprrrrr�
cloud_type=sz"UAAutoAttachGCPInstance.cloud_typecCs*tj�t�rt�t�}t|��krdSdS)z$This machine is a viable GCPInstanceTF)�os�path�exists�DMI_PRODUCT_NAMEr�	load_file�GCP_PRODUCT_NAME�strip)r�product_namerrr�	is_viableAs

z!UAAutoAttachGCPInstance.is_viablecCsN|jd}t�|�d�dd�}t�|�d��}|�di��di��dg�S)	z�Get a list of licenses from the GCP metadata.

        Instance identity token (jwt) carries a list of licenses
        associated with the instance itself.

        Returns an empty list if licenses are not present in the metadata.
        r#�.rz===zutf-8�google�compute_engine�
license_id)r2�base64�urlsafe_b64decode�split�json�loads�decoder,)r�token�identity�
identity_dictrrr�get_licenses_from_identityKs

�z2UAAutoAttachGCPInstance.get_licenses_from_identitycCs$t��j}|tvrt�d�dSdS)Nz0This series isn't supported for GCP auto-attach.FT)r�get_release_info�series�GCP_LICENSES�LOG�info)rrMrrr�should_poll_for_pro_license\s


z3UAAutoAttachGCPInstance.should_poll_for_pro_license�wait_for_changecCs�t}|r|t7}|jr|tj|jd�7}tj|ddid�}|jdkr=dd�|jD�}|j	�
d�|_t��j
}t�
|�|vSt�|j�|jd	krLt���t���)
Nrrr)r r"cSsg|]}|d�qS)�idr)�.0�licenserrr�
<listcomp>mszBUAAutoAttachGCPInstance.is_pro_license_present.<locals>.<listcomp>ri�)�LICENSES_URL�WAIT_FOR_CHANGEr�	LAST_ETAG�formatrr)r'�	json_listr r,rrLrMrNrO�errorr(r�CancelProLicensePolling�DelayProLicensePolling)rrR�urlr0�license_idsrMrrr�is_pro_license_presentcs


z.UAAutoAttachGCPInstance.is_pro_license_presentN)�__name__�
__module__�__qualname__r�propertyr	�retryrr/r�strrr2r4�boolr=rrKrQrarrrrr#s	r)rBrE�loggingr5�typingrrrr�uaclientrrrr	�uaclient.cloudsr
�	getLogger�replace_top_level_logger_namerbrOr*rWrXrYr8r:rNrrrrr�<module>s,���