File manager - Edit - /opt/saltstack/salt/lib/python3.10/site-packages/salt/fileserver/__pycache__/s3fs.cpython-310.pyc
Back
o ;j�j � @ s> d Z ddlZddlZddlZddlZddlZddlZddlm Z ddlZddl ZddlZddlZddlZe�e�ZdZdd� Zdd� Zd6d d �Zdd� Zd d� Zdd� Zdd� Zdd� Zdd� Zdd� Zdd� Zdd� Z dd� Z!dd � Z"d!d"� Z#d#d$� Z$d%d&� Z%d'd(� Z&d)d*� Z'd+d,� Z(d-d.� Z)d/d0� Z*d7d2d3�Z+d4d5� Z,dS )8aj Amazon S3 Fileserver Backend .. versionadded:: 0.16.0 This backend exposes directories in S3 buckets as Salt environments. To enable this backend, add ``s3fs`` to the :conf_master:`fileserver_backend` option in the Master config file. .. code-block:: yaml fileserver_backend: - s3fs S3 credentials must also be set in the master config file: .. code-block:: yaml s3.keyid: GKTADJGHEIQSXMKKRBJ08H s3.key: askdjghsdfjkghWupUjasdflkdfklgjsdfjajkghs Alternatively, if on EC2 these credentials can be automatically loaded from instance metadata. This fileserver supports two modes of operation for the buckets: 1. :strong:`A single bucket per environment` .. code-block:: yaml s3.buckets: production: - bucket1 - bucket2 staging: - bucket3 - bucket4 2. :strong:`Multiple environments per bucket` .. code-block:: yaml s3.buckets: - bucket1 - bucket2 - bucket3 - bucket4 Note that bucket names must be all lowercase both in the AWS console and in Salt, otherwise you may encounter ``SignatureDoesNotMatch`` errors. A multiple-environment bucket must adhere to the following root directory structure:: s3://<bucket name>/<environment>/<files> .. note:: This fileserver back-end requires the use of the MD5 hashing algorithm. MD5 may not be compliant with all security policies. .. note:: This fileserver back-end is only compatible with MD5 ETag hashes in the S3 metadata. This means that you must use SSE-S3 or plaintext for bucket encryption, and that you must not use multipart upload when uploading to your bucket. More information here: https://docs.aws.amazon.com/AmazonS3/latest/API/RESTCommonResponseHeaders.html Objects without an MD5 ETag will be fetched on every fileserver update. If you deal with objects greater than 8MB, then you should use the following AWS CLI config to avoid mutipart upload: .. code-block:: text s3 = multipart_threshold = 1024MB More info here: https://docs.aws.amazon.com/cli/latest/topic/s3-config.html .. note:: This fileserver back-end will by default sync all buckets on every fileserver update. If you want files to be only populated in the cache when requested, you can disable this in the master config: .. code-block:: yaml s3.s3_sync_on_update: False � N�md5c C s t � } t| �� �S )z^ Return a list of directories within the bucket that can be used as environments. )�_init�list�keys)�metadata� r �H/opt/saltstack/salt/lib/python3.10/site-packages/salt/fileserver/s3fs.py�envsm s r c C s� t � } t�dd�rIt�d� | �� D ]/\}}t|�D ]&}|�� D ]\}}|D ]}t|||�}t�d|||� t | ||||� q&q qqt�d� dS dS )z/ Update the cache file for the bucket. zs3.s3_sync_on_updateTzSyncing local cache from S3...z%s - %s : %sz#Sync local cache from S3 completed.N) r �__opts__�get�log�info�items�_find_files�_get_cached_file_name�debug�_get_file_from_s3)r �saltenv�env_meta�bucket_files�bucket�filesZ file_path�cached_file_pathr r r �updatex s&