HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/states/__pycache__/boto_s3.cpython-310.pyc
o

�N�g%�@sxdZddlZddlZddlZddlZe�e�Zdd�Z	e
gd��Ze
ddg�Ze
gd��Z
									dd
d�ZdS)
a�
Manage S3 Resources
===================

.. versionadded:: 2018.3.0

Manage S3 resources. Be aware that this interacts with Amazon's services,
and so may incur charges.

This module uses ``boto3``, which can be installed via package, or pip.

This module accepts explicit AWS credentials but can also utilize
IAM roles assigned to the instance through Instance Profiles. Dynamic
credentials are then automatically obtained from AWS API and no further
configuration is necessary. More information available `here
<http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html>`_.

If IAM roles are not used you need to specify them either in a pillar file or
in the minion's config file:

.. code-block:: yaml

    s3.keyid: GKTADJGHEIQSXMKKRBJ08H
    s3.key: askdjghsdfjkghWupUjasdflkdfklgjsdfjajkghs

It's also possible to specify ``key``, ``keyid`` and ``region`` via a profile,
either passed in as a dict, or as a string to pull from pillars or minion
config:

.. code-block:: yaml

    myprofile:
        keyid: GKTADJGHEIQSXMKKRBJ08H
        key: askdjghsdfjkghWupUjasdflkdfklgjsdfjajkghs
            region: us-east-1

.. code-block:: yaml

    Ensure s3 object exists:
        boto_s3.object_present:
            - name: s3-bucket/s3-key
            - source: /path/to/local/file
            - region: us-east-1
            - keyid: GKTADJGHEIQSXMKKRBJ08H
            - key: askdjghsdfjkghWupUjasdflkdfklgjsdfjajkghs
            - profile: my-profile

:depends: boto3
�NcCsdtvrdSdS)z)
    Only load if boto is available.
    �boto_s3.get_object_metadata)Fz"boto_s3 module could not be loadedZboto_s3)�__salt__�rr�G/opt/saltstack/salt/lib/python3.10/site-packages/salt/states/boto_s3.py�__virtual__<sr)
ZCacheControlZContentDispositionZContentEncodingZContentLanguageZContentTypeZExpires�MetadataZServerSideEncryption�SSECustomerAlgorithm�SSECustomerKeyMD5ZSSEKMSKeyIdZStorageClassZWebsiteRedirectLocation�SSECustomerKey�RequestPayer)rr
r	r�boto_s3_object_extra_argsc	
s|did�}	|duri}t�td|i��}
td|
|�|
r9ttB}t|
���}||}
|
r9d|
�d�}d|iS|s?td	}zt	j
jj||d
�}Wn?t
yj}zd|	d<d
�||�|	d<|	WYd}~Sd}~wty�}zd|	d<d�||�|	d<|	WYd}~Sd}~wwd}|
�di�||
dvr�|
d||kr�d|	d<d�|�|	d<|	S||
d|<dd�|
��D��dd�|
��D�}td||||||d��d�vr�d|	d<d��d�|	d<|	S�d�r	��fdd�tD�}|�k�rd|	d<d|�d�|	d<|	Sd}nd}d}dd �}d�t�||��d�|���d���}td!�rKd|	d<d|�d"|�d#�|	d<|	dd$|��7<d%|i|	d&<|	Std'|||
||||d��d�v�rmd|	d<d(�|�d�|	d<|	Sd|	d<d|�d)|�d#�|	d<|	dd$|��7<d%|i|	d&<|	S)*a"
    Ensure object exists in S3.

    name
        The name of the state definition.
        This will be used to determine the location of the object in S3,
        by splitting on the first slash and using the first part
        as the bucket name and the remainder as the S3 key.

    source
        The source file to upload to S3,
        currently this only supports files hosted on the minion's local
        file system (starting with /).

    hash_type
        Hash algorithm to use to check that the object contents are correct.
        Defaults to the value of the `hash_type` config option.

    extra_args
        A dictionary of extra arguments to use when uploading the file.
        Note that these are only enforced if new objects are uploaded,
        and not modified on existing objects.
        The supported args are those in the ALLOWED_UPLOAD_ARGS list at
        http://boto3.readthedocs.io/en/latest/reference/customizations/s3.html.
        However, Note that the 'ACL', 'GrantFullControl', 'GrantRead',
        'GrantReadACP',  and 'GrantWriteACL' keys are currently not supported.

    extra_args_from_pillar
        Name of pillar dict that contains extra arguments.
        Extra arguments defined for this specific state will be
        merged over those from the pillar.

    region
        Region to connect to.

    key
        Secret key to be used.

    keyid
        Access key to be used.

    profile
        A dict with region, key and keyid, or a pillar key (string) that
        contains a dict with region, key and keyid.
    �)�name�comment�changesNz
config.optionzdictupdate.updatezextra_args keys z are not supported�error�	hash_type)ZformF�resultz Could not read local file {}: {}rz Could not hash local file {}: {}Zsalt_managed_content_hashrz\Salt uses the {} metadata key internally,do not pass it to the boto_s3.object_present state.cSsi|]\}}|tvr||�qSr)�UPLOAD_ONLY_EXTRA_ARGS��.0�k�vrrr�
<dictcomp>��z"object_present.<locals>.<dictcomp>cSsi|]\}}|tvr||�qSr)�GET_METADATA_EXTRA_ARGSrrrrr�rr)�
extra_args�region�key�keyid�profilez(Failed to check if S3 object exists: {}.cs.i|]}|�vr|�dvr|�d|�qS)rr)rr�Zdesired_metadata�rrrr�s
�Tz
S3 object z is present.�update�createcSs"d}td|�}td|d|d�S)z>
        Safely dump YAML using a readable flow style
        ZIndentedSafeOrderedDumperzyaml.get_dumperz	yaml.dumpF)Zdefault_flow_styleZDumper)�	__utils__)ZattrsZdumper_nameZdumperrrr�_yaml_safe_dumpsz'object_present.<locals>._yaml_safe_dump�testz set to be zd.z

Changes:
�diffrzboto_s3.upload_filezFailed to {} S3 object: {}.� )�copy�deepcopyrr%�STORED_EXTRA_ARGSr�	frozenset�keysZ__opts__�salt�utilsZ	hashutilsZget_hash�OSError�format�
ValueError�
setdefault�items�join�difflibZunified_diff�
splitlines)r�sourcerrZextra_args_from_pillarrrrr �retZcombined_extra_argsZsupported_argsZcombined_extra_args_keysZ
extra_keys�msg�digest�eZHASH_METADATA_KEYZmetadata_extra_argsZs3_metadata�actionr&Zchanges_diffrr!r�object_presentjs�9�������	������
�
��
�

�r?)NNNrNNNN)�__doc__r*r7�loggingZsalt.utils.hashutilsr/�	getLogger�__name__�logrr-r,rrr?rrrr�<module>s62
���
��