HEX
Server: Apache
System: Linux zacp120.webway.host 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64
User: govancoz (1003)
PHP: 8.3.26
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: //lib/python3.6/site-packages/cloudinit/config/__pycache__/cc_write_files.cpython-36.pyc
3

\�me��@sUdZddlZddlZddlZddlmZddlmZddlm	Z	ddl
mZddlm
Z
mZddlmZd	Zd
ZdZeje�Zdd
ded�dged�ed�ed�ed�ed�gedgd�Ze
ee�Zeee	edd�dd�Zdd�Zed�dd�Zdd �Zd!d"�ZdS)#z"Write Files: write arbitrary files�N)�dedent)�util)�Cloud)�Config)�
MetaSchema�get_meta_doc)�PER_INSTANCEi�Fz
text/plainZcc_write_fileszWrite Fileszwrite arbitrary filesax        Write out arbitrary content to files, optionally setting permissions.
        Parent folders in the path are created if absent.
        Content can be specified in plain text or binary. Data encoded with
        either base64 or binary gzip data can be specified and will be decoded
        before being written. For empty file creation, content can be omitted.

    .. note::
        If multiline data is provided, care should be taken to ensure that it
        follows yaml formatting standards. To specify binary data, use the yaml
        option ``!!binary``

    .. note::
        Do not write files under /tmp during boot because of a race with
        systemd-tmpfiles-clean that can cause temp files to get cleaned during
        the early boot process. Use /run/somedir instead to avoid race
        LP:1707222.

    .. warning::
       Existing files will be overridden.�alla)        # Write out base64 encoded content to /etc/sysconfig/selinux
        write_files:
        - encoding: b64
          content: CiMgVGhpcyBmaWxlIGNvbnRyb2xzIHRoZSBzdGF0ZSBvZiBTRUxpbnV4...
          owner: root:root
          path: /etc/sysconfig/selinux
          permissions: '0644'
        z�        # Appending content to an existing file
        write_files:
        - content: |
            15 * * * * root ship_logs
          path: /etc/crontab
          append: true
        a        # Provide gziped binary content
        write_files:
        - encoding: gzip
          content: !!binary |
              H4sIAIDb/U8C/1NW1E/KzNMvzuBKTc7IV8hIzcnJVyjPL8pJ4QIA6N+MVxsAAAA=
          path: /usr/bin/hello
          permissions: '0755'
        zt        # Create an empty file on the system
        write_files:
        - path: /root/CLOUD_INIT_WAS_HERE
        a         # Defer writing the file until after the package (Nginx) is
        # installed and its user is created alongside
        write_files:
        - path: /etc/nginx/conf.d/example.com.conf
          content: |
            server {
                server_name example.com;
                listen 80;
                root /var/www;
                location / {
                    try_files $uri $uri/ $uri.html =404;
                }
            }
          owner: 'nginx:nginx'
          permissions: '0640'
          defer: true
        �write_files)�id�name�title�descriptionZdistrosZexamplesZ	frequencyZactivate_by_schema_keys)r�cfg�cloud�args�returncCsB|jdg�}dd�|D�}|s.tjd|�dSt|||jj�dS)Nr
cSsg|]}tj|dt�s|�qS)Zdefer)r�get_cfg_option_bool�
DEFAULT_DEFER)�.0�f�r�$/usr/lib/python3.6/cc_write_files.py�
<listcomp>|szhandle.<locals>.<listcomp>zESkipping module named %s, no/empty 'write_files' key in configuration)�get�LOG�debugr
ZdistroZ
default_owner)rrrrZ	file_listZfiltered_filesrrr�handleysrcCsf|sd}|j�j�}|d
kr"dgS|dkr2d	dgS|dkr@d	gS|tkrNtgS|r`tjd|t�tgS)N��gz�gzipzapplication/x-gzip�	gz+base64�gzip+base64�gz+b64�gzip+b64zapplication/base64�b64�base64z%Unknown encoding type %s, assuming %s)rr )r!r"r#r$)r%r&)�lower�strip�TEXT_PLAIN_ENCr�warning)Z
encoding_typerrr�canonicalize_extraction�s"r+)�ownerc	Cs�|sdSx�t|�D]�\}}|jd�}|s<tjd|d|�qtjj|�}t|jd��}t|jdd�|�}t	j
|jd|��\}}	t|jd�t�}
t	j
|d	�r�d
nd}t	j||||
||	d�t	j|||	�qWdS)
N�pathz3No path provided to write for entry %s in module %s��encodingZcontentrr,Zpermissions�appendZab�wb)�omode�mode�user�group)�	enumeraterrr*�osr-�abspathr+�extract_contentsrZextract_usergroup�decode_perms�
DEFAULT_PERMSrZ
write_fileZchownbyname)r�filesr,�iZf_infor-Zextractions�contents�u�gZpermsr2rrrr
�s&
cCs�|dkr|Sy(t|ttf�r$t|�Stt|�d�SWnrttfk
r�g}xF||fD]:}y|jd|�WqVtk
r�|jd|�YqVXqVWtjd|��|SXdS)N�z%oz%r�0Undecodable permissions %s, returning default %s)rB)	�
isinstance�int�float�str�	TypeError�
ValueErrorr0rr*)Zperm�defaultZreps�rrrrr:�sr:cCsL|}xB|D]:}|dkr(tj|ddd�}q
|dkr<tj|�}q
|tkr
q
W|S)Nzapplication/x-gzipF)�quiet�decodezapplication/base64)rZdecomp_gzipr&Z	b64decoder))r>Zextraction_types�result�trrrr9�s
r9)�__doc__r&Zloggingr7�textwraprZ	cloudinitrZcloudinit.cloudrZcloudinit.configrZcloudinit.config.schemarrZcloudinit.settingsrr;rr)Z	getLogger�__name__r�metarF�listrr+r
r:r9rrrr�<module>sJ