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__/aws.cpython-38.pyc
U

��Jh��@s�ddlZddlZddlmZmZddlmZmZmZm	Z	m
Z
ddlmZdZ
dZe
efZdZdZd	Zd
ZdZdZd
ZdZedZe�e
�e��ZGdd�de�ZdS)�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_uuidZ21600zX-aws-ec2-metadata-tokenz-ttl-secondsc@s�eZdZdZdZed�dd�Zeej	e
jdddgd�eee
fd�d	d
���Zej	e
jdddgd�ed�dd��Zeed�d
d��Zdd�Zej	e
jdddgd�dd��Zeed�dd��Zeed�dd��Zed�dd�Zeed�dd�ZdS)�AWSAutoAttachInstanceN)�urlcCs6tj||dd�}|jdkr |jStj|j|jd��dS)N�)�headers�timeout����code�body)r�readurlrrr�CloudMetadataError)�selfrr
�response�r�5/usr/lib/python3/dist-packages/uaclient/clouds/aws.py�_get_imds_url_responses
�z,AWSAutoAttachInstance._get_imds_url_responseg�?r)Zretry_sleeps)�returncCs6|��}t�|j�}|j||d�}tj�|�d|iS)N�r
Zpkcs7)�_request_imds_v2_token_headers�IMDS_URL�format�_ip_addressrr�secrets�
add_secret)rr
rZimds_url_responserrr�identity_doc*s
z"AWSAutoAttachInstance.identity_docc
Csj|��}t�|j�}zt�|j||d��}Wn8tjk
rd}zt�	d|�iWY�Sd}~XYnX|S)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.
        rz-Error decoding instance identity document: %sN)
r�
_IMDS_IID_URLrr�json�loadsrZJSONDecodeError�LOG�debug)rr
r�ii_doc�errr�_get_ii_doc3s�z!AWSAutoAttachInstance._get_ii_doccCs0|��}|�dd�}|�dd�}t|�p.t|�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.
        ZbillingProductsNZmarketplaceProductCodes)r*�get�bool)rr(Zbilling_productsZmarketplace_product_codesrrr�
is_likely_proIs
z#AWSAutoAttachInstance.is_likely_procCs~tD]X}z|j|d�}Wn8tk
rP}zt�d|t|dd��W5d}~XYqX||_q^q|jdkrztjd�	t�d��|S)N)�
ip_addressz*Could not reach AWS IMDS at http://%s: %s
�reason�z, )Z	addresses)
�IMDS_IP_ADDRESS�_get_imds_v2_token_headers�	Exceptionr&Zwarning�getattrrrZAWSNoValidIMDS�join)rZaddressr
r)rrrrXs 
�
�z4AWSAutoAttachInstance._request_imds_v2_token_headers��cCs�|jdkrdS|jrt|jiStjt�|�dttidd�}|jdkrd|j	|_t
j�|j�t|jiS|jdkrxd|_dSt
j|j|j	d��dS)NZIMDSv1ZPUTr)�methodr
rri�r)�
_api_token�AWS_TOKEN_PUT_HEADERrr�IMDS_V2_TOKEN_URLr�AWS_TOKEN_REQ_HEADER�AWS_TOKEN_TTL_SECONDSrrrr r!rr)rr.rrrrr2ks*

�


�z0AWSAutoAttachInstance._get_imds_v2_token_headerscCsdS)NZawsr�rrrr�
cloud_type�sz AWSAutoAttachInstance.cloud_typecCs�z$t�t�}d|dd�kr"WdSWntk
r8YnXt�t���}t�t���}d|dd�krz|dd�kr�nndSdS)z$This machine is a viable AWSInstanceZec2r�TF)rZ	load_file�SYS_HYPERVISOR_PRODUCT_UUID�FileNotFoundError�DMI_PRODUCT_UUID�lower�DMI_PRODUCT_SERIAL)rZhypervisor_uuidZdmi_uuidZ
dmi_serialrrr�	is_viable�s

(zAWSAutoAttachInstance.is_viablecCsdS)ZUnsupportedFrr>rrr�should_poll_for_pro_license�sz1AWSAutoAttachInstance.should_poll_for_pro_license)�wait_for_changercCst���dS)N)rZInPlaceUpgradeNotSupportedError)rrHrrr�is_pro_license_present�sz,AWSAutoAttachInstance.is_pro_license_present)�__name__�
__module__�__qualname__r9r�strr�propertyrZretryrrrrr"r*r,r-rr2r?rFrGrIrrrrr
s&
r
)r$Zlogging�typingrrZuaclientrrrrrZuaclient.cloudsr	ZIMDS_IPV4_ADDRESSZIMDS_IPV6_ADDRESSr1r;rr#rArErCr=r:r<Z	getLoggerZreplace_top_level_logger_namerJr&r
rrrr�<module>s$