File manager - Edit - /opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/__pycache__/boto_s3.cpython-310.pyc
Back
o ;j� � @ s� d Z ddlZddlZe�e�ZzddlZddlZe�d�� ej � dZW n ey/ dZY nw dd� Z dd � Z dd d�Z ddd �ZdS )a� Connection module for Amazon S3 using boto3 .. versionadded:: 2018.3.0 :configuration: This module accepts explicit AWS credentials but can also utilize IAM roles assigned to the instance through Instance Profiles or it can read them from the ~/.aws/credentials file or from these environment variables: AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY. Dynamic credentials are then automatically obtained from AWS API and no further configuration is necessary. More information available at: .. code-block:: text http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ iam-roles-for-amazon-ec2.html http://boto3.readthedocs.io/en/latest/guide/ configuration.html#guide-configuration If IAM roles are not used you need to specify them either in a pillar or in the minion's config file: .. code-block:: yaml s3.keyid: GKTADJGHEIQSXMKKRBJ08H s3.key: askdjghsdfjkghWupUjasdflkdfklgjsdfjajkghs A region may also be specified in the configuration: .. code-block:: yaml s3.region: us-east-1 If a region is not specified, the default is us-east-1. It's also possible to specify key, keyid and region via a profile, either as a passed in dict, or as a string to pull from pillars or minion config: .. code-block:: yaml myprofile: keyid: GKTADJGHEIQSXMKKRBJ08H key: askdjghsdfjkghWupUjasdflkdfklgjsdfjajkghs region: us-east-1 :depends: boto3 � N�boto3TFc C s t jjjdd�S )zg Only load if boto libraries exist and if boto libraries are greater than a given version. z1.2.1)Z boto3_ver)�salt�utilsZversionsZcheck_boto_reqs� r r �H/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/boto_s3.py�__virtual__K s r c C s t rtd td� d S d S )Nzboto3.assign_funcsZs3)�HAS_BOTO� __utils__�__name__)�optsr r r �__init__S s �r c C s� | � d�\}}}|du ri }t||||d�} z| jd||d�|��} W d| iS tjjyU } z!|jd d dkrCddiW Y d}~S d td |�iW Y d}~S d}~ww )a� Get metadata about an S3 object. Returns None if the object does not exist. You can pass AWS SSE-C related args and/or RequestPayer in extra_args. CLI Example: .. code-block:: bash salt myminion boto_s3.get_object_metadata \ my_bucket/path/to/object \ region=us-east-1 \ key=key \ keyid=keyid \ profile=profile \ �/N��region�key�keyid�profile)ZBucketZKey�Error�Messagez Not Found�result�error�boto3.get_errorr )� partition� _get_connZhead_object�botocore� exceptionsZClientError�responser )�name� extra_argsr r r r �bucket�_�s3_key�conn�metadata�er r r �get_object_metadataX s ���r% c C s� |� d�\}}} t||||d�} z| j| || |d� W n tjjy7 } zdtd |�iW Y d}~S d}~ww t�d|� dd iS ) a� Upload a local file as an S3 object. CLI Example: .. code-block:: bash salt myminion boto_s3.upload_file \ /path/to/local/file \ my_bucket/path/to/object \ region=us-east-1 \ key=key \ keyid=keyid \ profile=profile \ r r )Z ExtraArgsr r NzS3 object uploaded to %sr T) r r �upload_filer r ZS3UploadFailedErrorr �log�info)�sourcer r r r r r r r r! r"