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__/botomod.cpython-310.pyc
o

�N�g��@s:dZddlZddlZddlZddlmZddlZddlZddl	Zddl
mZddlm
Z
zddlZddlZe�d��ej�dZWneyLdZYnwe�e�ZdadZejj��Ze�d	i�Zd
d�Zdd
�Z 							d!dd�Z!dd�Z"	d"dd�Z#d#dd�Z$dd�Z%d$dd�Z&dd�Z'd%dd�Z(dd �Z)dS)&a�
Boto 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 `assign_funcs` from the `__virtual__` function
of the module. This will bring properly initialized partials of  `_get_conn`
and `_cache_id` into the module's namespace.

Example Usage:

    .. code-block:: python

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

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

.. versionadded:: 2015.8.0
�N)�partial)�SaltInvocationError)�minion_mods�botoTF�__context__cCs,tjjjdd�}|durtstt�atS|S)zg
    Only load if boto libraries exist and if boto libraries are greater than
    a given version.
    F)Zcheck_boto3T)�salt�utilsZversionsZcheck_boto_reqs�__salt__rZ__opts__�__virtualname__)Zhas_boto_requirements�r�F/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/botomod.py�__virtual__<sr
c	Cs|r)t|t�rtd|�}nt|t�r|}|�dd�}|�dd�}|�d|p'd�}|s;td|d�r;td|d�}|s?d}|sQtd|d�rQtd|d�}|sctd|d�rctd|d�}d	|�d
�}|r�|||}tjj�|�}|t	�
|���}n||}||||fS)Nz
config.option�key�keyid�regionz.regionz	us-east-1z.keyz.keyidZboto_�:)�
isinstance�strr	�dict�getrrZstringutils�to_bytes�hashlib�md5�	hexdigest)	�servicerrr�profileZ_profileZlabelZhash_string�cxkeyrrr�_get_profileJs.

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||�qSrr)�.0�k�v��resource_idrr�
<dictcomp>�szcache_id.<locals>.<dictcomp>F)rr�values�items�clear�updater)r�nameZsub_resourcer"Z
invalidaterrrrr�_�ctxrr!r�cache_idhs$

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+)rrrr�
cache_id_func�s

r,c
Cs�t|p|�}d|�dd�\}}tt||gd�|�}t|||||�\}}}}|d}|tvr2t|Sz|j|||d�}	|	durGtd|�d	���Wntj	j
yYtd
�||���w|	t|<|	S)z�
    Return a boto connection for the service.

    .. code-block:: python

        conn = __utils__['boto.get_connection']('ec2', profile='custom_profile')
    zboto.�.�)�fromlistz:conn)Zaws_access_key_idZaws_secret_access_keyNzRegion "z" is not valid.z^No authentication credentials found when attempting to make boto {} connection to region "{}".)r�rsplit�getattr�
__import__rrZconnect_to_regionrr�	exceptionZNoAuthHandlerFound�format)
r�modulerrrrZ	submoduleZsvc_modr�connrrr�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)rr5rrr�get_connection_func�s	r9cCs�i}t|d�r|j|d<t|d�r|j|d<t|d�r%|jdkr%|j|d<t|d�r4|jdur4|j|d<d|vrGd|vrGd�|d|d�}nd|vrP|d}nd|vrY|d}nd}d|i}|re||d<|S)	N�status�reason�message��
error_code�codez{}: {}�aws)�hasattrr:r;r<r>r4)�er@r<�rrrr�	get_error�s(







rDr.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��irr�	<genexpr>�s�zexactly_n.<locals>.<genexpr>)�iter�all�rangerF)�l�nrrHr�	exactly_n�s$rPcCst|�SrE)rP)rNrrr�exactly_one�srQcCsF|r|atj|}t|dt||d��t|dt|��t|dt�dS)z�
    Assign _get_conn and _cache_id functions to the named module.

    .. code-block:: python

        __utils__['boto.assign_partials'](__name__, 'ec2')
    Z	_get_connr8Z	_cache_idZ_exactly_oneN)r	�sys�modules�setattrr9r,rQ)�modnamerr5�pack�modrrr�assign_funcs�s
rXcosL�|�dd�}|�dd�}	||i|��}|�|�}|V|s!dS|||<q)z�
    Retrieve full set of values from a boto API call that may truncate
    its results, yielding each page as it is obtained.
    �marker_flag�markerTN)�popr)�function�args�kwargsrYZ
marker_arg�retrZrrr�
paged_calls�
�r`)NNFNNNN)NNNNNrE)r.)NN)*�__doc__r�loggingrR�	functoolsrZsalt.loader.contextrZsalt.utils.stringutilsZsalt.utils.versionsZsalt.exceptionsrZsalt.loaderrrZboto.exception�	getLogger�setLevel�CRITICALZHAS_BOTO�ImportError�__name__�logr	r
�loader�contextZ
LoaderContextZ__salt_loader__Z
named_contextrr
rr+r,r7r9rDrPrQrXr`rrrr�<module>sT�
!
�-
�
&