HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //lib/python3/dist-packages/uaclient/clouds/__pycache__/gcp.cpython-38.pyc
U

��Jh(�@s�ddlZddlZddlZddlZddlmZmZmZmZddl	m
Z
mZmZm
Z
mZddlmZe�e�e��ZdZdZdZdZd	Zd
Zdgdd
gddgddgddgd�ZGdd�de�ZdS)�N)�Any�Dict�List�Optional)�
exceptions�http�secret_manager�system�util)�PublicCloudAutoAttachInstancez�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 EngineZ8045211386737108299Z6022427724719891830Z7427070211152946628Z599959289349842382Z7818678586103571931Z2592866803419978320Z160084055690847662Z2176054482269786025Z4168323874790319525)ZxenialZbionicZfocalZjammyZnoblec@s�eZdZdd�Zeejejdddgd�e	e
efd�dd���Zee
d�d	d
��Z
eed�dd��Zee
d�d
d�Zed�dd�Zeed�dd�ZdS)�GCPAutoAttachInstancecCs
d|_dS)N��etag��self�r�5/usr/lib/python3/dist-packages/uaclient/clouds/gcp.py�__init__%szGCPAutoAttachInstance.__init__g�?�)Zretry_sleeps)�returncCsxtjtddidd�}|jdkr6tj�|j�d|jiS|j�	d�}|rbd|�
�krbtj|j|d	��tj
|j|jd
��dS)N�Metadata-Flavor�Googler)�headersZtimeout���
identityTokenZerror_descriptionzservice account)Zstatus_codeZ	error_msg)�code�body)r�readurl�	TOKEN_URLrrZsecretsZ
add_secretrZ	json_dict�get�lowerrZGCPServiceAccountError�CloudMetadataError)r�responseZ
error_descrrr�identity_doc,s$�

��z"GCPAutoAttachInstance.identity_doccCsdS)NZgcprrrrr�
cloud_type?sz GCPAutoAttachInstance.cloud_typecCs*tj�t�r&t�t�}t|��kr&dSdS)z$This machine is a viable GCPInstanceTF)�os�path�exists�DMI_PRODUCT_NAMEr	Z	load_file�GCP_PRODUCT_NAME�strip)rZproduct_namerrr�	is_viableCs

zGCPAutoAttachInstance.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-8ZgoogleZcompute_engineZ
license_id)r#�base64Zurlsafe_b64decode�split�json�loads�decoder)r�tokenZidentityZ
identity_dictrrr�get_licenses_from_identityMs
���z0GCPAutoAttachInstance.get_licenses_from_identitycCs$t��j}|tkr t�d�dSdS)Nz0This series isn't supported for GCP auto-attach.FT)r	�get_release_info�series�GCP_LICENSES�LOG�info)rr5rrr�should_poll_for_pro_license^s


z1GCPAutoAttachInstance.should_poll_for_pro_license)�wait_for_changercCs�t}|r(|t7}|jr(|tj|jd�7}tj|ddid�}|jdkr�dd�|jD�}|j	�
d�|_t��j
}t�
|g�D]}||krxd	Sqxd
St�|j�|jdkr�t���nt���dS)Nr
rr)rrcSsg|]}|d�qS)�idr)�.0�licenserrr�
<listcomp>osz@GCPAutoAttachInstance.is_pro_license_present.<locals>.<listcomp>rTFi�)�LICENSES_URL�WAIT_FOR_CHANGEr�	LAST_ETAG�formatrrrZ	json_listrrr	r4r5r6r7�errorrrZCancelProLicensePollingZDelayProLicensePolling)rr:Zurlr"Zlicense_idsr5Zlicrrr�is_pro_license_presentes$



z,GCPAutoAttachInstance.is_pro_license_presentN)�__name__�
__module__�__qualname__r�propertyr
Zretryrr!r�strrr#r$�boolr+rr3r9rDrrrrr$s	r)r-r/Zloggingr%�typingrrrrZuaclientrrrr	r
Zuaclient.cloudsrZ	getLoggerZreplace_top_level_logger_namerEr7rr?r@rAr(r)r6rrrrr�<module>s,���