Current File : //usr/lib/python3/dist-packages/uaclient/clouds/__pycache__/gcp.cpython-312.pyc
�

��g(���ddlZddlZddlZddlZddlmZmZmZmZddl	m
Z
mZmZm
Z
mZddlmZej"ej$e��ZdZdZdZdZd	Zd
Zdgdd
gddgddgddgd�ZGd�de�Zy)�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 Engine�8045211386737108299�6022427724719891830�7427070211152946628�599959289349842382�7818678586103571931�2592866803419978320�160084055690847662�2176054482269786025�4168323874790319525)�xenial�bionic�focal�jammy�noblec���eZdZd�Zeejejgd���de	e
effd���Zede
fd��Z
edefd��Zdee
fd�Zdefd	�Zd
edefd�Zy)
�GCPAutoAttachInstancec��d|_y)N��etag��selfs �5/usr/lib/python3/dist-packages/uaclient/clouds/gcp.py�__init__zGCPAutoAttachInstance.__init__%s����	�)g�?�r%)�retry_sleeps�returnc��tjtddid��}|jdk(r7tj
j
|j�d|jiS|jjd�}|r3d|j�vr!tj|j|�	��tj|j|j�
��)N�Metadata-Flavor�Googler%)�headers�timeout���
identityToken�error_descriptionzservice account)�status_code�	error_msg)�code�body)r�readurl�	TOKEN_URLr2r	�secrets�
add_secretr3�	json_dict�get�lowerr�GCPServiceAccountError�CloudMetadataError)r!�response�
error_descs   r"�identity_docz"GCPAutoAttachInstance.identity_doc,s����<�<�� 1�8�<�a�
���=�=�C���"�"�-�-�h�m�m�<�#�X�]�]�3�3��'�'�+�+�,?�@�
��+�z�/?�/?�/A�A��3�3�$�M�M�Z��
��+�+����X�]�]�
�	
r$c��y)N�gcp�r s r"�
cloud_typez GCPAutoAttachInstance.cloud_type?s��r$c��tjjt�r1t	j
t�}t|j�k(ryy)z$This machine is a viable GCPInstanceTF)�os�path�exists�DMI_PRODUCT_NAMEr
�	load_file�GCP_PRODUCT_NAME�strip)r!�product_names  r"�	is_viablezGCPAutoAttachInstance.is_viableCs=���7�7�>�>�*�+�!�+�+�,<�=�L��<�#5�#5�#7�7��r$c� �|jd}tj|jd�ddz�}t	j
|j
d��}|jdi�jdi�jdg�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.�.r%z===zutf-8�google�compute_engine�
license_id)r?�base64�urlsafe_b64decode�split�json�loads�decoder9)r!�token�identity�
identity_dicts    r"�get_licenses_from_identityz0GCPAutoAttachInstance.get_licenses_from_identityMs|���!�!�/�2���+�+�E�K�K��,<�Q�,?�%�,G�H���
�
�8�?�?�7�#;�<�
����h��+�
�S�!�2�
&�
�S��r�
"�	
r$c�|�tj�j}|tvrtjd�yy)Nz0This series isn't supported for GCP auto-attach.FT)r
�get_release_info�series�GCP_LICENSES�LOG�info)r!r_s  r"�should_poll_for_pro_licensez1GCPAutoAttachInstance.should_poll_for_pro_license^s1���(�(�*�1�1����%��H�H�G�H��r$�wait_for_changec��t}|r8|tz
}|jr#|tj	|j��z
}tj|ddi��}|jdk(r||jD�cgc]}|d��	}}|jjd�|_tj�j}tj|g�D]}||vs�yy	tj!|j"�|jd
k(rt%j&��t%j(��cc}w)Nrr)r*)r+r-�idrTFi�)�LICENSES_URL�WAIT_FOR_CHANGEr�	LAST_ETAG�formatrr4r2�	json_listr+r9r
r^r_r`ra�errorr3r�CancelProLicensePolling�DelayProLicensePolling)r!rd�urlr=�license�license_idsr_�lics        r"�is_pro_license_presentz,GCPAutoAttachInstance.is_pro_license_presentes������?�"�C��y�y��y�'�'�T�Y�Y�'�7�7���<�<��.?��-J�K���=�=�C��8@�8J�8J�K�W�7�4�=�K�K�K� �(�(�,�,�V�4�D�I��,�,�.�5�5�F�#�'�'���3�
 ���+�%��
 ���	�	�(�-�-� ��=�=�C���4�4�6�6��3�3�5�5��Ls�7D;N)�__name__�
__module__�__qualname__r#�propertyr�retryrr<r�strrr?rC�boolrMrr\rcrsrBr$r"rr$s������T�Z�Z�
�-�-�K�H�
�d�3��8�n�
�I��
�"��C������4����
�D��I�
�"�T��6��6�$�6r$r)rSrV�loggingrE�typingrrrr�uaclientrrr	r
r�uaclient.cloudsr�	getLogger�replace_top_level_logger_namertrar5rgrhrirHrJr`rrBr$r"�<module>r�s���
���	�,�,�C�C�9��g���:��:�:�8�D�E�� �
��
�*���	�3��*��%�%�$�&;�<�"�$9�
:�#�%9�
:�#�%:�
;���W6�9�W6r$