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

��g�����ddlZddlZddlmZmZddlmZmZmZm	Z	m
Z
ddlmZdZ
dZe
efZdZdZd	Zd
ZdZdZd
ZdZedzZej2e
j4e��ZGd�de�Zy)�N)�Any�Dict)�
exceptions�http�secret_manager�system�util)�PublicCloudAutoAttachInstancez169.254.169.254z[fd00:ec2::254]zhttp://{}/latest/api/tokenz0http://{}/latest/dynamic/instance-identity/pkcs7z3http://{}/latest/dynamic/instance-identity/documentz/sys/hypervisor/uuidz /sys/class/dmi/id/product_serialz/sys/class/dmi/id/product_uuid�21600zX-aws-ec2-metadata-tokenz-ttl-secondsc��eZdZdZdZdefd�Zeeje
jgd���deee
ffd���Zeje
jgd���defd��Zedefd	��Zd
�Zeje
jgd���d��Zedefd
��Zedefd��Zdefd�Zdedefd�Zy)�AWSAutoAttachInstanceN�urlc��tj||d��}|jdk(r|jSt	j
|j|j���)N�)�headers�timeout����code�body)r�readurlrrr�CloudMetadataError)�selfrr�responses    �5/usr/lib/python3/dist-packages/uaclient/clouds/aws.py�_get_imds_url_responsez,AWSAutoAttachInstance._get_imds_url_responsesJ���<�<��W�a�@���=�=�C���=�=� ��/�/��]�]�����
�)g�?rr)�retry_sleeps�returnc���|j�}tj|j�}|j	||��}t
jj|�d|iS)N�r�pkcs7)�_request_imds_v2_token_headers�IMDS_URL�format�_ip_addressrr�secrets�
add_secret)rrr�imds_url_responses    r�identity_docz"AWSAutoAttachInstance.identity_doc*s]���5�5�7���o�o�d�.�.�/�� �7�7��W�7�M�����)�)�*;�<��*�+�+rc�"�|j�}tj|j�}	t	j
|j
||���}|S#tj$r"}tjd|�icYd}~Sd}~wwxYw)a
        Get the instance identity doc associated with the current instance.

        See
        https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/retrieve-iid.html
        for more context.

        @return: Dict containing the instance identity document.
        r!z-Error decoding instance identity document: %sN)
r#�
_IMDS_IID_URLr%r&�json�loadsr�JSONDecodeError�LOG�debug)rrr�ii_doc�es     r�_get_ii_docz!AWSAutoAttachInstance._get_ii_doc3s����5�5�7���"�"�4�#3�#3�4��	��Z�Z��+�+�C��+�A��F��
���#�#�	��I�I�E�q�I��I��	�s�&A�B�,B	�B�	Bc��|j�}|jdd�}|jdd�}t|�xst|�S)a
        Determines if the instance is likely Ubuntu Pro.

        Criteria: if any billing-product or marketplace-product-code is
        present, then is likely a Pro instance.

        @return: Boolean indicating if the instance is likely pro or not.
        �billingProductsN�marketplaceProductCodes)r4�get�bool)rr2�billing_products�marketplace_product_codess    r�
is_likely_proz#AWSAutoAttachInstance.is_likely_proIsM���!�!�#��!�:�:�&7��>��$*�J�J�/H�$�$O�!��$�%�H��.G�)H�Hrc�,�tD]}	|j|��}||_n|j�)tjdjt����S#t$r,}tjd|t
|dd��Yd}~��d}~wwxYw)N)�
ip_addressz*Could not reach AWS IMDS at http://%s: %s
�reason�z, )�	addresses)
�IMDS_IP_ADDRESS�_get_imds_v2_token_headersr&�	Exceptionr0�warning�getattrr�AWSNoValidIMDS�join)r�addressrr3s    rr#z4AWSAutoAttachInstance._request_imds_v2_token_headersXs���&�	�G�

��9�9�W�9�M��$+�� ��	����#��+�+��)�)�O�4��
�����
����A���A�x��,����
�s�A�	B�'"B�B)r��c��|jdk(ry|jrt|jiStjtj|�dttid��}|jdk(rL|j|_tjj|j�t|jiS|jdk(rd|_ytj|j|j���)N�IMDSv1�PUTr)�methodrrri�r)�
_api_token�AWS_TOKEN_PUT_HEADERrr�IMDS_V2_TOKEN_URLr%�AWS_TOKEN_REQ_HEADER�AWS_TOKEN_TTL_SECONDSrrrr'r(rr)rr>rs   rrCz0AWSAutoAttachInstance._get_imds_v2_token_headersks����?�?�h�&��
�_�_�(�$�/�/�:�:��<�<��$�$�Z�0��)�+@�A��	
���=�=�C��&�m�m�D�O��"�"�-�-�d�o�o�>�(�$�/�/�:�:��=�=�C��&�D�O���+�+����X�]�]�
�	
rc��y)N�aws��rs r�
cloud_typez AWSAutoAttachInstance.cloud_type����rc�.�	tjt�}d|ddk(ry	tjt�j�}tjt�j�}d|ddcxk(r|ddk(ryyy#t$rY�nwxYw)z$This machine is a viable AWSInstance�ec2r�TF)r�	load_file�SYS_HYPERVISOR_PRODUCT_UUID�FileNotFoundError�DMI_PRODUCT_UUID�lower�DMI_PRODUCT_SERIAL)r�hypervisor_uuid�dmi_uuid�
dmi_serials    r�	is_viablezAWSAutoAttachInstance.is_viable�s���	�$�.�.�/J�K�O����!�,�,��-��#�#�$4�5�;�;�=���%�%�&8�9�?�?�A�
��H�Q�q�M�4�Z��!�_�4��5���!�	�
�	�s�!B�	B�Bc��y)�UnsupportedFrWrXs r�should_poll_for_pro_licensez1AWSAutoAttachInstance.should_poll_for_pro_license�rZr�wait_for_changec�*�tj��)N)r�InPlaceUpgradeNotSupportedError)rrks  r�is_pro_license_presentz,AWSAutoAttachInstance.is_pro_license_present�s���8�8�:�:r)�__name__�
__module__�__qualname__rPr&�strr�propertyr	�retryrrrrr*r4r9r<r#rCrYrgrjrnrWrrr
r
s&���J��K��#����T�Z�Z�
�-�-�K�H�,�d�3��8�n�,�I��,��T�Z�Z�
�-�-�K�H��T��I��*�I�t�I��I��&�T�Z�Z�
�-�-�I�F�
�G�
�0��C������4����"�T��;��;�$�;rr
)r-�logging�typingrr�uaclientrrrrr	�uaclient.cloudsr
�IMDS_IPV4_ADDRESS�IMDS_IPV6_ADDRESSrBrRr$r,r_rcrarTrQrS�	getLogger�replace_top_level_logger_nameror0r
rWrr�<module>r}s������C�C�9�%��%��$�&7�8��0��=��E�
�4��7��3����1��+�n�<���g���:��:�:�8�D�E��D;�9�D;r