403Webshell
Server IP : 3.96.16.70  /  Your IP : 216.73.216.15
Web Server : Apache
System : Linux ip-172-31-26-103.ca-central-1.compute.internal 6.1.163-186.299.amzn2023.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Feb 24 16:35:42 UTC 2026 x86_64
User : ec2-user ( 1000)
PHP Version : 8.4.18
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /lib/python3.9/site-packages/cfnbootstrap/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /lib/python3.9/site-packages/cfnbootstrap/__pycache__/construction.cpython-39.opt-1.pyc
a

��0i�T�@s�dZddlmZddlZddlZddlZddlZddlZddl	Z	dej
d<ddlmZ
ddlmZddlmZddlmZddlmZdd	lmZmZmZmZdd
lmZddlmZmZddl m!Z!dd
l"m#Z#m$Z$ddl%m&Z&m'Z'ddl(m)Z)ddl*m+Z+ddl,m-Z-m.Z.ddl/m0Z0e�1d�Z2e�1d�Z3Gdd�de4�Z5Gdd�de4�Z6Gdd�de4�Z7Gdd�de4�Z8Gdd�de4�Z9Gdd �d e4�Z:dS)!a�
A library for building an installation from metadata

Classes:
Contractor - orchestrates the build process
Carpenter - does the concrete work of applying metadata to the installation
Tool - performs a specific task on an installation
ToolError - a base exception type for all tools

CloudFormationCarpenter - Orchestrates a non-delegated installation
YumTool - installs packages via yum

�)�
cmp_to_keyNZ_tkinter)�platform_utils)�AptTool)�AuthenticationConfig)�CommandTool)�
BuildError�NoSuchConfigSetError�NoSuchConfigurationError� CircularConfigSetDependencyError)�FileTool)�
PythonTool�GemTool)�MsiTool)�RpmTool�YumTool)�SysVInitTool�WindowsServiceTool)�SystemDTool)�SourcesTool)�	GroupTool�UserTool)�
ZypperToolzcfn.initzcfn.init.cmdc@sneZdZdZddd�Zdd�Zdd�Zd	d
�Zdd�Zddd�Z	dd�Z
dd�Zddd�Zdd�Z
dd�Zd
S)�WorkLogz{
    Keeps track of pending work, and can resume from the last known point
    Useful for commands that cause restarts
    �resume_db.jsoncCs�tjdkrtj�d�|_nd|_tj�|j�sJtj�|j�sJt�|jd�tj�|j�sztd|jt	j
d�t�d|j�||_
t�tg�|_dS)N�ntz${SystemDrive}\cfn\cfn-initz/var/lib/cfn-initi�z)Could not create %s to store the work log)�file)�os�name�path�
expandvars�_json_db_dir�isdir�exists�makedirs�print�sys�stderr�logging�error�_dbname�JsonFileManagerZ	Converter�ConfigDefinition�_jsonConverter)�selfZdbname�r.�=/usr/lib/python3.9/site-packages/cfnbootstrap/construction.py�__init__Cs$
����zWorkLog.__init__cCst�|j|j�dS�N)r*Zcreater r)�r-r.r.r/�clearVsz
WorkLog.clearcCsFt�|j|j�}|�dd�}i}|dkr0||d<t�|j|j|�dS�N�metadata)r*�readr r)�get�write)r-�	json_datar5r.r.r/�clear_except_metadataYszWorkLog.clear_except_metadatacCsJt�|j|j�}|r&|j�|�||<n||vr4||=t�|j|j|�dSr1)r*r6r r)r,�	serializer8)r-�key�datar9r.r.r/�putaszWorkLog.putcCst�|j|j�}||vSr1)r*r6r r)�r-r<r9r.r.r/�has_keyiszWorkLog.has_keyNcCs0t�|j|j�}||vr(|j�||�S|SdSr1)r*r6r r)r,�deserialize)r-r<�defaultr9r.r.r/r7mszWorkLog.getcCs4t�|j|j�}||vr0||=t�|j|j|�dSr1)r*r6r r)r8r?r.r.r/�deletetszWorkLog.deletecCsjt�|j|j�}||vrb|j�||�}|��}|s<||=n|j�|�||<t�|j|j|�|SdSdSr1)	r*r6r r)r,rA�popleftr;r8)r-r<r9�valueZret_valr.r.r/�popzszWorkLog.popFcCs*|�d|�t��t||��||�dSr4)r>r�set_reboot_trigger�
Contractor�build)r-r5�
configSets�strict_moder.r.r/rI�sz
WorkLog.buildc	
CsHt�}|�d�r�|�d�}t�t�}|�|�di��|d}|�|d|i�}|d�	|�|�
d|�|szt�d�qt�
|�}|dkr�t�d�t�d�q|dkrt�d|�t�|�q|�di���D]D\}}|tjv�r
tj|��||�dt�t���q�t�d	|�q�|�d��r.|�d�|�d��rD|�d�dS)
N�commands�changes�rz&Not waiting as command did not executez*Waiting indefinitely for command to rebootzWaiting %s seconds for reboot�services�Unsupported service manager: %s)rr@rF�collections�defaultdict�list�updater7�apply�extendr>�log�infoZget_waitr%�exit�time�sleep�items�CloudFormationCarpenter�
_serviceTools�warnrC)	r-Zcmd_toolZnext_cmdrMZcmd_optionsZcommand_changes�wait�managerrOr.r.r/�run_commands�s<




��
zWorkLog.run_commandscCs�t�d�t��|��t|�d��}|�d�rX|�d�}t�d|j	�|�
||�q(|�d�r�|�d�}t�d|�|�||�n|��t�
�t�d�dS)NzStarting resumer5�configszResuming config: %srJzResuming configSets: %szResume completed)rW�debugrrGrbrHr7r@rFr�
run_configrIr3�clear_reboot_trigger)r-Z
contractorZnext_configZremaining_setsr.r.r/�resume�s




zWorkLog.resume)r)N)F)�__name__�
__module__�__qualname__�__doc__r0r3r:r>r@r7rCrFrIrbrgr.r.r.r/r=s


#rc@sVeZdZdZeeeeee	e
d�Zgd�Ze
eed�Zedd��Zd
dd	�Zd
d�ZdS)r]z9
    Takes a model and uses tools to make it reality
    )�yumZrubygemsZpython�rpm�apt�zypper�msi)rpZdpkgrmrnrlro)ZsysvinitZwindowsZsystemdcCs�tj}|d|vrV|d|vrV|�|d�|�|d�k|�|d�|�|d�kS|d|vrfdS|d|vrvdS|d��|d��k|d��|d��kSdS)Nr���rN)r]�	_pkgOrder�index�lower)�x�y�orderr.r.r/�_pkgsort�s8z CloudFormationCarpenter._pkgsortFcCs||_||_||_dSr1)�_config�_auth_configrK)r-�configZauth_configrKr.r.r/r0�sz CloudFormationCarpenter.__init__c
Cs:t�t�}t�t�|d<|jjr�t|jj��ttj	�d�D]\\}}|tj
vr:|dkrxtj
|��||j|j
�|d|<q:tj
|��||j�|d|<q:n
t�d�|jjr�t��|jj�|d<n
t�d�|jjr�t��|jj�|d<n
t�d�|jj�rt��|jj|j�|d	<n
t�d
�|jj�rFt��|jj|j�|d<n
t�d�|jj�r�tjd
k�r�|�d|�|�dt�t|jj��t�d�d���nt��|jj�|d<n
t�d�|jj �r,tjd
k�r�|�d|jj �nF|jj ��D]8\}}|tj!v�rtj!|��||�nt�"d|��q�n
t�d�dS)N�packages)r<rmzNo packages specified�groupszNo groups specified�userszNo users specified�sourceszNo sources specified�fileszNo files specifiedrrMrLrzNo commands specifiedrOrPzNo services specified)#rQrRrSryr|�sortedr\rr]rx�
_packageToolsrUrzrKrWrdr}rr~rrrr�rrLrrr>�deque�operator�
itemgetterrrOr^r_)r-�worklogrMrar|rOr.r.r/rI�s^
"
$�




�



�


��


�zCloudFormationCarpenter.buildN)F)rhrirjrkrr
rrrrrr�rrrrrr^�staticmethodrxr0rIr.r.r.r/r]�s�

r]c@s�eZdZdZdd�Zedd��Zedd��Zedd	��Zed
d��Z	edd
��Z
edd��Zedd��Zedd��Z
dd�Zdd�Zedd��ZdS)r+z,
    Encapsulates one config definition
    cCs^||_|�d�|_|�d�|_|�d�|_|�d�|_|�d�|_|�d�|_|�d�|_dS)Nr�r|rOrrLr~r})	�_namer7�_files�	_packages�	_services�_sources�	_commands�_users�_groups)r-r�modelr.r.r/r0/szConfigDefinition.__init__cCs|jSr1�r�r2r.r.r/r9szConfigDefinition.namecCs|jSr1)r�r2r.r.r/r�=szConfigDefinition.filescCs|jSr1)r�r2r.r.r/r|AszConfigDefinition.packagescCs|jSr1)r�r2r.r.r/rOEszConfigDefinition.servicescCs|jSr1)r�r2r.r.r/rIszConfigDefinition.sourcescCs|jSr1)r�r2r.r.r/rLMszConfigDefinition.commandscCs|jSr1)r�r2r.r.r/r~QszConfigDefinition.userscCs|jSr1)r�r2r.r.r/r}UszConfigDefinition.groupscCs
d|jS)Nz
Config(%s)r�r2r.r.r/�__str__YszConfigDefinition.__str__cCs
||jiSr1)�__dict__)r-Zmarkerr.r.r/r;\szConfigDefinition.serializecCsBi}|D].}|dd�}|dkr*||}q||||<q|||�S)NrNr�r.)�clsr9r�ZfieldZproprr.r.r/�	from_json_s
zConfigDefinition.from_jsonN)rhrirjrkr0�propertyrr�r|rOrrLr~r}r�r;�classmethodr�r.r.r.r/r+*s,








r+c@s,eZdZdZdd�Zedd��Zdd�ZdS)	�ConfigSetRefz+
    Encapsulates a ref to a ConfigSet
    cCs
||_dSr1r�)r-rr.r.r/r0pszConfigSetRef.__init__cCs|jSr1r�r2r.r.r/rsszConfigSetRef.namecCs
d|jS)Nz
ConfigSet(%s)r�r2r.r.r/r�wszConfigSetRef.__str__N)rhrirjrkr0r�rr�r.r.r.r/r�ks

r�c@sJeZdZdZddd�Zdd�Zdd�Zed	d
��Zedd��Z	d
d�Z
dS)�	ConfigSetzT
    A list of ConfigDefinition or ConfigSetRef objects with their dependencies
    NcCs6|sgn|g|_|rt|t�r$t�n
t|jg�|_dS)z�
        Arguments:
        configDef - optional ConfigDefinition|ConfigSetRef to initialize this list with (handy for 1-member lists)
        N)�_defs�
isinstancer+�setr�
_dependencies�r-�	configDefr.r.r/r0�s�zConfigSet.__init__cCs(t|t�r|j�|j�|j�|�dSr1)r�r�r��addrr��appendr�r.r.r/�addConfigDef�s
zConfigSet.addConfigDefcCs|jD]}|�|�qdSr1)�
configDefsr�)r-Z
configDefListZcdr.r.r/rV�s
zConfigSet.extendcCs|jSr1)r�r2r.r.r/�dependencies�szConfigSet.dependenciescCs|jSr1)r�r2r.r.r/r��szConfigSet.configDefscCsdd�|j�S)NzConfigSet of: %s�,)�joinr�r2r.r.r/r��szConfigSet.__str__)N)rhrirjrkr0r�rVr�r�r�r�r.r.r.r/r�{s
	

r�c@sfeZdZdZdZdZdZddd�Zdd	�Zd
d�Z	dd
�Z
dd�Zdd�Ze
dd��Zedd��ZdS)rHz�
    Take in a metadata model and force the environment to match it, returning nothing.

    Processes configSets if they exist; otherwise, invents a virtual configSet named
    "default" with one config of "config"

    zAWS::CloudFormation::Initz#AWS::CloudFormation::AuthenticationrJFcCs�|�tj�}||_|s$tdtj��tj|vrLdtd|�dt���gi|_n.|tj}t	|t�sntdtj��|�
||�t|�tji��|_
dS)NzMetadata does not contain '%s'rBr{z&%s should be a mapping of name to list)r7rH�
_configKeyrK�
ValueError�_configSetsKeyr+�dict�_configSetsr��_processConfigSetsDefinitionr�_authKeyrz)r-r�rKZ	initModel�
configSetsDefr.r.r/r0�s&�
�

��zContractor.__init__c
Csi}i}t�t�}t�}|��D]\\}}|�||�}	|	jrdt|	j�||<|	jD]}
||
�|�qNn
|�|�t|	j�||<q |s�t	d��i|_
|r�|��}|�|||�|j
|<|�|g�D]*}||�
|�||s�|�|�||=q�q�|�rt	dd�|�����dS)z�
        Parse a set of configSets from the model and collapse them, validating there are no cycles
        and that all references are valid.
        z]No configSets exist without references; this creates a circular dependency and is not allowedzJAt least one circular dependency detected; this is not allowed. Culprits: �, N)rQrRr�r\�_processConfigListr�r�rSr�r
r�rF�	_collapse�remover��keys)
r-r�r�Z
rawConfigSetsZdependencyTreeZreverseDependencyTree�roots�
configSetName�
configListZ
processedListZ
dependency�	configSetZ	dependentr.r.r/r��sB


��


��z'Contractor._processConfigSetsDefinitioncCsXg}|D]J}t|t�r"|�|�q|j|jvr@td||jf��|�|j|j�q|S)z�
        Transform ConfigSetRefs into the contents of the ConfigSets they reference, returning a list of only ConfigDefinition objects
        z:ConfigSet %s referenced ConfigSet %s but it is not defined)r�r+r�rr�r�rV)r-r�r�Z
returnListr{r.r.r/r��s
�zContractor._collapsecCs�t|t�r0||vrtd|��tt|||��St|t�rxd|vrJtd��|d}||tjvrltd|��tt	|��St�}|D]}|�
|�||��q�|S)a
        Processes a parsed-JSON list of config definitions, returning a ConfigSet

        Handles both references ({"ConfigSet" : "name"}) and plain config names
        so users can define simple ConfigSets without using lists, and so we can recurse simply
        z$No configuration found with name: %sr�zlConfig definitions must be either a config name or a reference in the format {'ConfigSet':<config set name>}z3Configuration set %s was referenced but not defined)r��strr	r�r+r�r�rHr�r�rVr�)r-r�r�ZsetNameZ	returnSetr�r.r.r/r�s*
�
��zContractor._processConfigListcCs�|��t�|�}t�dd�|��|r�|��}||jvrFtd|��|�	d|�t�|j|�}t�d|�t
�d�t
�d|�|r$|��}|�	d|�|�||�q�q$t�d	�|��t
��d
S)zFDoes the work described by each configSet, in order, returning nothingzRunning configSets: %sr�z#Error: no ConfigSet named %s existsrJzRunning configSet %sz<************************************************************zConfigSet %srczConfigSets completedN)r:rQr�rWrXr�rDr�rr>�cmd_logrer3rrf)r-rJr�r�r�r{r.r.r/rI s*

�

zContractor.buildc
Cs�t�d|j�t�d�t�d|j�z"t||j|j��|�|��Wn:t	y�}z"t�
d|jt|���WYd}~n
d}~00dS)NzRunning config %sz<++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++z	Config %sz(Error encountered during build of %s: %s)rWrXrr�r]rzrKrIrbr�	exceptionr�)r-r{r��er.r.r/re?s
�zContractor.run_configcCs|o|j|vo||jSr1)r�)r�r5r.r.r/�
metadataValidMszContractor.metadataValidcCs
t|j�Sr1)r�r�r2r.r.r/rcQszContractor.configsN)F)rhrirjrkr�r�r�r0r�r�r�rIrer�r�r�rcr.r.r.r/rH�s
1
rH);rk�	functoolsrrQr'r�Zos.pathrr%rZ�modulesZcfnbootstrap.json_file_managerZjson_file_managerr*ZcfnbootstraprZcfnbootstrap.apt_toolrZcfnbootstrap.authrZcfnbootstrap.command_toolrZ cfnbootstrap.construction_errorsrrr	r
Zcfnbootstrap.file_toolrZcfnbootstrap.lang_package_toolsrr
Zcfnbootstrap.msi_toolrZcfnbootstrap.rpm_toolsrrZcfnbootstrap.service_toolsrrZcfnbootstrap.systemd_toolrZcfnbootstrap.sources_toolrZcfnbootstrap.user_group_toolsrrZcfnbootstrap.zypper_toolrZ	getLoggerrWr��objectrr]r+r�r�rHr.r.r.r/�<module>s@


`A#

Youez - 2016 - github.com/yon3zu
LinuXploit