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/utils/__pycache__/boto3mod.cpython-310.pyc
o

�N�g?!�@sbdZddlZddlZddlZddlmZddlZddlZddl	Zddl
mZzddlZddl
ZddlZddlZe�d��ej�dZWneyNdZYnwe�e�ZdZejj��Ze�di�Zd	d
�Zdd�Zd
d�Z 							d+dd�Z!dd�Z"	d,dd�Z#d-dd�Z$dd�Z%dd�Z&d.dd�Z'dd�Z(		 	!	"d/d#d$�Z)d%d&�Z*d'd(�Z+d)d*�Z,dS)0a�
Boto3 Common Utils
=================

Note: This module depends on the dicts packed by the loader and,
therefore, must be accessed via the loader or from the __utils__ dict.

This module provides common functionality for the boto execution modules.
The expected usage is to call `apply_funcs` from the `__virtual__` function
of the module. This will bring properly initilized partials of  `_get_conn`
and `_cache_id` into the module's namespace.

Example Usage:

    .. code-block:: python

        def __virtual__():
            __utils__['boto.apply_funcs'](__name__, 'vpc')

        def test():
            conn = _get_conn()
            vpc_id = _cache_id('test-vpc')

.. versionadded:: 2015.8.0
�N)�partial)�SaltInvocationError�boto3TF�__context__cCstjj��}|durtS|S)zg
    Only load if boto libraries exist and if boto libraries are greater than
    a given version.
    T)�salt�utilsZversionsZcheck_boto_reqs�__virtualname__)Zhas_boto�r	�G/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/boto3mod.py�__virtual__<srcCs@|tvrt|St�di�}||vr||S|tvrt|SdS)z*
    Look up the value for an option.
    ZmasterN)Z__opts__Z
__pillar__�get)�valueZmaster_optsr	r	r
�_optionGs�rc	Cs|r%t|t�rt|�}nt|t�r|}|�dd�}|�dd�}|�dd�}|s3t|d�r3t|d�}|s=d}t�d|�|sKt|d�rKt|d�}|sYt|d�rYt|d�}d	|�d
�}|rx|||}tjj	�
|�}|t�|��
�}n||}||||fS)N�key�keyid�regionz.regionz	us-east-1zAssuming default region %sz.keyz.keyidZboto_�:)�
isinstance�strr�dictr�log�inforrZstringutils�to_bytes�hashlib�md5�	hexdigest)	�servicerrr�profileZ_profileZlabelZhash_string�cxkeyr	r	r
�_get_profileTs0


rc	s�t|||||�\}	}
}
}
|r|	�d|�d|�d�}	n|	�d|�d�}	|rK|	tvr-t|	=dS�t��vrI�fdd�t��D�}t��t�|�dSdS�rS�t|	<dSt�|	�S)a
    Cache, invalidate, or retrieve an AWS resource id keyed by name.

    .. code-block:: python

        __utils__['boto.cache_id']('ec2', 'myinstance',
                                   'i-a1b2c3',
                                   profile='custom_profile')
    rz:idTcsi|]\}}|�kr||�qSr	r	��.0�k�v��resource_idr	r
�
<dictcomp>�szcache_id.<locals>.<dictcomp>F)rr�values�items�clear�updater)r�nameZsub_resourcer%Z
invalidaterrrrr�_�ctxr	r$r
�cache_idus$

r.cCs
tt|�S)z�
    Returns a partial `cache_id` function for the provided service.

    .. code-block:: python

        cache_id = __utils__['boto.cache_id_func']('ec2')
        cache_id('myinstance', 'i-a1b2c3')
        instance_id = cache_id('myinstance')
    )rr.)rr	r	r
�
cache_id_func�s

r/c	Cs�|p|}t|||||�\}}}}|d}|tvrt|Sz(tjj|||d�}|dur2td|�d���|�|�}|durCtd|�d���Wntjj	yUtd�
||���w|t|<|S)z�
    Return a boto connection for the service.

    .. code-block:: python

        conn = __utils__['boto.get_connection']('ec2', profile='custom_profile')
    z:conn3)Zaws_access_key_idZaws_secret_access_keyZregion_nameNzRegion "z" is not valid.z^No authentication credentials found when attempting to make boto {} connection to region "{}".)rrr�sessionZSessionr�client�botocore�
exceptionsZNoCredentialsError�format)	r�modulerrrrrr0�connr	r	r
�get_connection�s.�
���r7cCstt||d�S)z�
    Returns a partial `get_connection` function for the provided service.

    .. code-block:: python

        get_conn = __utils__['boto.get_connection_func']('ec2')
        conn = get_conn()
    �r5)rr7)rr5r	r	r
�get_connection_func�s	r9cCst||dd|�\}}}}|S)ze
    Retrieve the region for a particular AWS service based on configured region and/or profile.
    N)r)rrrr,r	r	r
�
get_region�sr:cCs*i}d}|jd}d|i}|r||d<|S)N�r�message�aws)�args)�er=r<�rr	r	r
�	get_error�s
rA�cs,t|��t�fdd�t|�D��ot��S)zb
    Tests that exactly N items in an iterable are "truthy" (neither None,
    False, nor 0).
    c3s�|]}t��VqdS�N)�any)r!�j��ir	r
�	<genexpr>���zexactly_n.<locals>.<genexpr>)�iter�all�rangerD)�l�nr	rFr
�	exactly_n�s$rOcCst|�SrC)rO)rMr	r	r
�exactly_onesrP�	_get_conn�	_cache_id�_exactly_onecCsJtj|}t||t||d��t||t|��|dur#t||t�dSdS)z�
    Assign _get_conn and _cache_id functions to the named module.

    .. code-block:: python

        _utils__['boto.assign_partials'](__name__, 'ec2')
    r8N)�sys�modules�setattrr9r/rP)�modnamerr5Zget_conn_funcnameZcache_id_funcnameZexactly_one_funcname�modr	r	r
�assign_funcss
�rYcosL�|�dd�}|�dd�}	||i|��}|�|�}|V|s!dS|||<q)zRetrieve full set of values from a boto3 API call that may truncate
    its results, yielding each page as it is obtained.
    �marker_flagZ
NextMarker�
marker_argZMarkerTN)�popr)�functionr>�kwargsrZr[�retZmarkerr	r	r
�
paged_calls�
�r`cCsRt|ttf�rtdd�|D��St|t�rdd�|��D�St|t�r't|�S|S)Ncss�|]}t|�VqdSrC��ordered)r!�xr	r	r
rH/rIzordered.<locals>.<genexpr>cSs,i|]\}}t|t�rt|�n|t|��qSr	)rrrbr r	r	r
r&1s,zordered.<locals>.<dictcomp>)r�list�tuple�sortedrr(r)�objr	r	r
rb-s

rbcCst|�t|�kS)zCCompare two parsed JSON objects, given non-ordering in JSON objectsra)�left�rightr	r	r
�json_objs_equal7srj)NNFNNNN)NNNNNrC)rB)NrQrRrS)-�__doc__r�loggingrT�	functoolsrZsalt.loader.contextrZsalt.utils.stringutilsZsalt.utils.versionsZsalt.exceptionsrrZ
boto3.sessionr2Zbotocore.exceptions�	getLogger�setLevel�CRITICALZHAS_BOTO�ImportError�__name__rr�loader�contextZ
LoaderContextZ__salt_loader__Z
named_contextrrrrr.r/r7r9r:rArOrPrYr`rbrjr	r	r	r
�<module>sd�

$
�-
�
&	
	
�