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/client/__pycache__/mixins.cpython-310.pyc
o

�N�g�V�@s4dZddlZddlZddlZddlZddlZddlZddlZddlm	Z	m
Z
ddlZddl
ZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZe�e�Z e!gd��Z"Gdd�de
�Z#Gdd�d�Z$Gd	d
�d
e$�Z%Gdd�de$�Z&dS)
zB
A collection of mixins useful for the various *Client interfaces
�N)�Mapping�MutableMapping)�client�cmdZeauth�fun�kwarg�match�token�__jid__�__tag__�__user__�username�password�full_return�print_eventc@sHeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dS)�ClientFuncsDictzN
    Class to make a read-only dict for accessing runner funcs "directly"
    cCs
||_dS�N)r)�selfr�r�F/opt/saltstack/salt/lib/python3.10/site-packages/salt/client/mixins.py�__init__<s
zClientFuncsDict.__init__cCst|jj|�S)z.
        Provide access eg. to 'pack'
        )�getattrr�	functions)r�attrrrr�__getattr__?szClientFuncsDict.__getattr__cC�t��r��NotImplementedError)r�key�valrrr�__setitem__E�zClientFuncsDict.__setitem__cCrrr)rrrrr�__delitem__Hr!zClientFuncsDict.__delitem__cs"��jjvrt���fdd�}|S)z�
        Return a function that you can call with regular func params, but
        will do all the _proc_function magic
        c
s��||d�}i}t|�}|D]}|�d�r|�|�||<q�j�|�d��}tjj�	�}�jj
�j�jj�|||d|ddd�S)N)r�args�kwargsZ__pub_Z	__pub_jid�tag�jidF)�instance�optsr�low�userr%r&�	daemonize)�list�
startswith�popr�_gen_async_pub�get�salt�utilsr*Zget_specific_user�_proc_functionr()r#r$r)�pub_dataZkwargs_keysZ
kwargs_key�	async_pubr*�rrrr�wrapperSs,�
��z,ClientFuncsDict.__getitem__.<locals>.wrapper)rr�KeyError)rrr7rr6r�__getitem__KszClientFuncsDict.__getitem__cC�t|jj�Sr)�lenrr�rrrr�__len__r�zClientFuncsDict.__len__cCr:r)�iterrrr<rrr�__iter__ur>zClientFuncsDict.__iter__N)�__name__�
__module__�__qualname__�__doc__rrr r"r9r=r@rrrrr7s'rc@s&eZdZddd�Zdd�Zdd�ZdS)	�ClientStateMixinNcCs||_|dur	i}||_dSr�r(�context)rr(rGrrrrzs
zClientStateMixin.__init__cCs|j|jpdd�S)NrFrFr<rrr�__getstate__�s�zClientStateMixin.__getstate__cCs|j|d|dd�dS)Nr(rG)rG)r)r�staterrr�__setstate__�szClientStateMixin.__setstate__r)rArBrCrrHrJrrrrrEys
rEc@sneZdZdZdZdd�Zdd�Zdd	d
�Z					ddd
�Ze	dd��Z
e	dd��Zddd�Zddd�Z
dS)�SyncClientMixinzN
    A mixin for *Client interfaces to abstract common function execution
    rcCst|�S)z�
        Return a dict that will mimic the "functions" dict used all over salt.
        It creates a wrapper around the function allowing **kwargs, and if pub_data
        is passed in as kwargs, will re-use the JID passed in
        )rr<rrr�functions_dict�szSyncClientMixin.functions_dictcKs�|}|j|d<tjjjj|jddd��$}|�|�}t|t�r.d|vr.tj	j
jdi|d��|Wd�S1s:wYdS)zJ
        Execute a function through the master network interface.
        r�clear�master_call)Zcrypt�usage�errorNr)rr1�channelZ
ReqChannel�factoryr(�send�
isinstancerr2rPZraise_error)rr$�loadrQ�retrrrrN�s

�

$�zSyncClientMixin.master_callNFcCs�tjjj|j|jddd��L}|jdi|��}tjjjd|dd�}|dur-|j�dd	�}|j|d|dd
�}|durItj	j
d�|d�|dd
��|rM|n|ddWd�S1s]wYdS)a�
        Execute a runner function synchronously; eauth is respected

        This function requires that :conf_master:`external_auth` is configured
        and the user is authorized to execute runner functions: (``@runner``).

        .. code-block:: python

            runner.eauth_sync({
                'fun': 'jobs.list_jobs',
                'username': 'saltdev',
                'password': 'saltdev',
                'eauth': 'pam',
            })
        �sock_dirT)�listenrVr%)�baseNZrest_timeouti,)r%�full�waitZauto_reconnectzRunnerClient job '{}' timed outr&)r&�data�returnr)r1r2�eventZget_master_eventr(rN�tagifyr0�	get_event�
exceptionsZSaltClientTimeout�format)rr)�timeoutrr^�jobZret_tagrVrrr�cmd_sync�s$���$�zSyncClientMixin.cmd_syncTcCs�|durt�}t|t�st|t�stj�d��|duri}t|t�s(tj�d��|dur.i}t|t�s9tj�d��tjjj	||j
�dg�d�}|rRd|d<|�|�tj
�|j|||�\}}	|||	d	�}
d
|vro|d
|
d<|j||
||d�S)
z$
        Execute a function
        Nz%arg must be formatted as a list/tuplez*pub_data must be formatted as a dictionaryz'kwarg must be formatted as a dictionary�no_parse)rfTZ	__kwarg__)r�argrr*r)rr)�tuplerTr,r1raZSaltInvocationError�dictr2r#Zparse_inputr(r0�append�minionZload_args_and_kwargsrr))rrrgr4rrrZarglistr#r$r)rrrr�s>�
�
��
�zSyncClientMixin.cmdcCs&t|d�stjj|jddd�|_|jS)N�_mminionF)ZstatesZrend)�hasattrr1rkZMasterMinionr(rlr<rrr�mminion�s

�zSyncClientMixin.mminioncCs^z|jj��}Wntytjdtjd�YdSwz	|j|�d�WSt	y.YdSw)z
        Helper that allows us to turn off storing jobs for different classes
        that may incorporate this mixin.
        zUnable to determine class name)Zexc_info_on_loglevelTZ_returns)
�	__class__rA�lower�AttributeError�log�warning�logging�DEBUGr(r8)r�
class_namerrr�	store_jobs���zSyncClientMixin.store_jobcCs�|j|�dtjj�|j��}|�dtjjj||j	d��}|j
�d|��||�dd�d�}|r:t|d�r7|jnd	}nd	}tjjj
tjjjd
|jd|jdd
�||d����}	||d|t�|	�d�}
�zt�|j�}tjj�||�g}|��D]*}
d|
vr~qw|
�dd�\}}||vr�qw|�|�|
��D]\}}||j|
j|<q�qwd|vr�d|vr�|d}|d}ntjjj|j||td�}|�dd�}|�di�}t|�|r�|gng|d<|
d�|d�tjj j!�"|jj#j$��m|j|}z||i|��|d<Wnt%�y}zd�&||j'�|d<WYd	}~nd	}~wwz
|j(�dd�dk|d<Wnt)�y5d |d<Ynwt*|dt+��rRd!|dv�rRtjj,�-|dd!�|d<Wd	�n	1�s]wYWn8t.t/f�y�}z)t*|tj0j1��r}t2|�|d<nd"�&|j
|t3�4��|d<d|d<d|d<WYd	}~nd	}~ww|j5�r�ztjj6j5|j|jd#|jd#|d$|d%�d	|jd&�Wntj0j7�y�t8�9d'�Ynw|	�|d(�t8�:d)|d$�|�r�|n|dWd	�S1�s�wYd	S)*a�
        Execute a function from low data
        Low data includes:
            required:
                - fun: the name of the function to run
            optional:
                - arg: a list of args to pass to fun
                - kwarg: kwargs for fun
                - __user__: user who is running the command
                - __jid__: jid to run under
                - __tag__: tag to run under
        r
r��prefix�.r�UNKNOWN)rr&r*�print_async_eventNZmasterrWF)r(rX)�
print_funcr*)r
rr�
__jid_event__�rgr)Zexpected_extra_kwsr#rr$Zfun_argsr~�newr]z(
Passed invalid arguments: {}

Usage:
{}�retcoder�successTr\zException occurred in {} {}: {}�idr&)r�Ztgtr&r])r^rnzLCould not store job cache info. Job details for this run may be unavailable.rVzRunner completed: %s);rnr0r1r2r&�gen_jidr(r^r_�
tag_prefixrrmr|ZNamespacedEventr`�weakref�proxy�copyrZlazyZ
verify_fun�keys�splitrj�items�__globals__r#Zformat_call�CLIENT_INTERNAL_KEYWORDSr,Z
fire_event�extZtornadoZ
stack_contextZStackContextZcontext_dict�clone�	TypeErrorrbrDrGrqrTrirIZcheck_result�	Exception�
SystemExitra�NotImplemented�str�	traceback�
format_excrwrdZSaltCacheErrorrrrP�info)rrr)rrr&r%r\r}Znamespaced_eventZfunc_globalsZself_functionsZcompleted_funcs�mod_name�mod�_Z
global_key�valuer#r$Zf_call�func�exc�exrrrr)s�
����	�	
�
�
�
�����
��������
���&�zSyncClientMixin.lowcs��r8d�vr��d}n
��d�s�dn��d}|r)�fdd�t��j��D�}n���fdd�t�j�D�}n�fdd�t�j�D�}t|�}tjj�	|�S)	zX
        Return a dictionary of functions and the inline documentation for each
        �*TrzFc�g|]
}|�j|jf�qSr�rrD��.0rr<rr�
<listcomp>�s��z,SyncClientMixin.get_docs.<locals>.<listcomp>cs.g|]}|�ks
|���r|�j|jf�qSr)r-rrDr��rgrZ
target_modrrr��s
�cr�rr�r�r<rrr��s�)
�endswith�fnmatch�filterr�sortedrir1r2�docZ	strip_rst)rrgZ_use_fnmatchZdocsrr�r�get_docs�s$
��
�zSyncClientMixin.get_docs)NF)NNNTF)TFr)rArBrCrDrrLrNrer�propertyrnrwr)r�rrrrrK�s&
&
�/


#rKc@sbeZdZdZdZdZedd�dd��Zeddd�d	d
��Zdd�Z	dd
d�Z
ddd�Zdd�ZdS)�AsyncClientMixinzW
    A mixin for *Client interfaces to enable easy asynchronous function execution
    NT)r+c

Cs�|rtjj��stj��tjj��t�	�tjj
_tj��||d<||d<||d<|dur3||�}z|�
|�WStjjyS}	zt�|	�WYd}	~	dSd}	~	ww)z�
        Run this method in a multiprocess target to execute the function on the
        master and fire the return data on the event bus
        r
rrN)r1r2�platform�spawning_platform�_logging�shutdown_logging�processr+�os�getpid�in_mainprocess�__pid__�
setup_loggingreraZEauthAuthenticationErrorrrrP)
�clsr'r(rr)r*r%r&r+r�rrr�_proc_function_remote�s 

��z&AsyncClientMixin._proc_function_remoteF)r+rc	
Csv|rtjj��stj��tjj��t�	�tjj
_tj��|dur'||�}||d<||d<||d<|j
|||	d�S)z�
        Run this method in a multiprocess target to execute the function
        locally and fire the return data on the event bus
        Nr
rr)r)r1r2r�r�r�r�r�r+r�r�r�r�r�r))
r�r'r(rr)r*r%r&r+rrrrr3s

zAsyncClientMixin._proc_functioncCs|jdi|��S)a
        Execute a function asynchronously; eauth is respected

        This function requires that :conf_master:`external_auth` is configured
        and the user is authorized

        .. code-block:: python

            >>> wheel.cmd_async({
                'fun': 'key.finger',
                'match': 'jerry',
                'eauth': 'auto',
                'username': 'saltdev',
                'password': 'saltdev',
            })
            {'jid': '20131219224744416681', 'tag': 'salt/wheel/20131219224744416681'}
        Nr)rN)rr)rrr�	cmd_async)szAsyncClientMixin.cmd_asynccCs6|durtjj�|j�}tjjj||jd�}||d�S)Nrx)r%r&)r1r2r&r�r(r^r_r�)rr&r%rrrr/=s
zAsyncClientMixin._gen_async_pubr{c

Cs�|r|j}n|j}|dur|n|��}tjj��rd}n|}tjj�t	j
t	j��,tjjj|d�
|j||d�t||j||||d|dd�d�}	|	��Wd�n1sWwY|	��|S)zx
        Execute the function in a multiprocess and return the event tag to use
        to watch for the return
        NzProcessFunc({}, fun={} jid={})r&r%)r'r(rr)r*r%r&)�target�namer$)r3r�r/r1r2r�r�r�Zdefault_signals�signal�SIGINT�SIGTERMZSignalHandlingProcessrbrCrir(�start�join)
rrr)r*Zpub�localZ	proc_funcr5r'�procrrr�asynchronousCs6���
�zAsyncClientMixin.asynchronouscCs�t|t�sdS|j�dd�rdS|dvrdSz|j�d|�dd�p(|�d��d��}Wnty6d}Ynw|dkr_t|�d�t�rZt|d�d	dhkrZ|dd	}|dd}n
|d}n||d
�}tj�|||j�dS)z?
        Print all of the events with the prefix 'tag'
        N�quietF)r��output�	outputterr]rVr\)�suffixr^)	rTrir(r0rq�setr1r�Zdisplay_output)rr�r^r�Z
event_datarrrr|es0
���

z"AsyncClientMixin.print_async_eventr)r{NT)
rArBrCrDrr��classmethodr�r3r�r/r�r|rrrrr��s��&

"r�)'rDr�r�rtr�r�r�r��collections.abcrrZ
salt._loggingr1Zsalt.channel.clientZsalt.exceptionsZsalt.ext.tornado.stack_contextZsalt.minionZsalt.outputZsalt.utils.argsZsalt.utils.docZsalt.utils.errorZsalt.utils.eventZsalt.utils.jidZsalt.utils.jobZsalt.utils.lazyZsalt.utils.platformZsalt.utils.processZsalt.utils.stateZsalt.utils.userZsalt.utils.versions�	getLoggerrArr�	frozensetr�rrErKr�rrrr�<module>sJ
�BP