HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.29
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/netapi/__pycache__/__init__.cpython-310.pyc
o

�N�g�)�@s�dZddlZddlZddlZddlZddlZddlZddlZddl	Zddl
ZddlZddlZddl
ZddlZddlZddlZddlmZe�e�Zdd�Zdd�ZGdd	�d	�Zd
d�ejedd�D�ZdS)
z
Make api awesomeness
�N)�DEFAULT_TARGET_DELIMcCsZg}g}|D]}t|t�r||vrq|�|�q||vrq|�|�qt|�t|td�S)zZ
    Return a sorted list of the passed in permissions, de-duplicating in the process
    ��key)�
isinstance�str�append�sorted�repr)�permsZ
_str_permsZ_non_str_perms�entry�r�H/opt/saltstack/salt/lib/python3.10/site-packages/salt/netapi/__init__.py�sorted_permissionss

rcCsv|�|dg�}|�|�dg��d|vr9|dr9t|d�}dd�|��D�}||@D]}|�||�d��q,|S)zN
    Returns the sum of '*', user-specific and group specific permissions
    �name�*�groupscSs h|]}|�d�r|�d��qS)�%)�endswith�rstrip)�.0�irrr
�	<setcomp>5s z"sum_permissions.<locals>.<setcomp>r)�get�extend�set�keys)�token�eauthr
Zuser_groupsZeauth_groups�grouprrr
�sum_permissions,src@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
d dd�Zdd�Zdd�Zdd�ZdS)!�NetapiClienta'
    Provide a uniform method of accessing the various client interfaces in Salt
    in the form of low-data data structures. For example:

    >>> client = NetapiClient(__opts__)
    >>> lowstate = {'client': 'local', 'tgt': '*', 'fun': 'test.ping', 'arg': ''}
    >>> client.run(lowstate)
    cCs�||_t�|j�}d|d<tj�|dd�|d<tj�|d�s't�|d�tj	�
|�|_tj	�|�|_
tjj�|�|_tjj�|�|_dS)NTZenable_ssh_minionsZcachedirZsaltapi)�opts�copy�deepcopy�os�path�join�exists�makedirs�saltZauthZResolverZresolverZLoadAuth�loadauthZdaemonsZ	masterapiZaccess_keysr�utils�minionsZ	CkMinions�	ckminions)�selfr!Zapioptsrrr
�__init__FszNetapiClient.__init__cCsDtjj��rdS|jddkrd}nd}tj�tj�|jd|��S)z�
        Perform a lightweight check to see if the master daemon is running

        Note, this will return an invalid success if the master crashed or was
        not shut down cleanly.
        TZ	transportZtcpzpublish_pull.ipczworkers.ipcZsock_dir)	r)r+�platformZ
is_windowsr!r$r%r'r&)r.Zipc_filerrr
�_is_master_runningRs	zNetapiClient._is_master_runningcCsZg}d}d|vrd}d}dg}||||fSd|vr'd}d}ddg}||||fStj�d��)NrZTokenAuthenticationErrorr�EauthAuthenticationError�username�password�#No authentication credentials given)r)�
exceptionsr2)r.Z
clear_load�sensitive_load_keysr�	auth_type�err_namerrr
�_prep_auth_infods�zNetapiClient._prep_auth_infoc	Cs�|�|�\}}}}|jj|||d�}|�dg�}|�d�}|r%tj�|��|�di��dt�}	|j�	|d|�dd�|	�}
|
�d	t
��}|
�d
t
��}|jj||d|�dg�|d|�dd�|d
�}
|
sktj�d��dS)Nr�	auth_list�error�kwargs�	delimiterZtgtZtgt_type�globr,�missing�fun�arg)r,zAuthorization error occurred.)r:r*Zcheck_authenticationrr)r6r2rr-Z
check_minions�list�
auth_check)r.�lowr8r9rr7rDr;r<r>Z_resr,r@Z
authorizedrrr
�_authorize_sshus2
�

���zNetapiClient._authorize_sshcCs�|��s
tj�d��|�d�tvrtj�d�|�d����|�d�|j�d�vr4tj�d�|�d����d|vsBd|vsBtj�	d��|�d	�rS|j�d
�sStj�	d��|ddkr^|�
|�t||d�}tjj
�||�}||�d
d�i|�di���S)zh
        Execute the specified function in the specified client by passing the
        lowstate
        zSalt Master is not available.�clientzInvalid client specified: '{}'Znetapi_enable_clientszUClient disabled: '{}'. Add to 'netapi_enable_clients' master config option to enable.rrr5Z	raw_shellZnetapi_allow_raw_shellzRaw shell option not allowed.�ssh�argsrr=)r1r)r6ZSaltDaemonNotRunningr�CLIENTSZSaltInvocationError�formatr!r2rF�getattrr+rIZformat_call)r.rEZl_funZf_callrrr
�run�s2�����
zNetapiClient.runcO�Dtjj|jd��}|j|i|��Wd�S1swYdS)z�
        Run :ref:`execution modules <all-salt.modules>` asynchronously

        Wraps :py:meth:`salt.client.LocalClient.run_job`.

        :return: job ID
        ��moptsN)r)rG�get_local_clientr!Zrun_job�r.rIr=rGrrr
�local_async��$�zNetapiClient.local_asynccOrN)a
        Run :ref:`execution modules <all-salt.modules>` synchronously

        See :py:meth:`salt.client.LocalClient.cmd` for all available
        parameters.

        Sends a command from the master to the targeted minions. This is the
        same interface that Salt's own CLI uses. Note the ``arg`` and ``kwarg``
        parameters are sent down to the minion(s) and the given function,
        ``fun``, is called with those parameters.

        :return: Returns the result from the execution module
        rON)r)rGrQr!�cmdrRrrr
�local�s$�zNetapiClient.localcOrN)z�
        Run :ref:`execution modules <all-salt.modules>` against subsets of minions

        .. versionadded:: 2016.3.0

        Wraps :py:meth:`salt.client.LocalClient.cmd_subset`
        rON)r)rGrQr!Z
cmd_subsetrRrrr
�local_subset�rTzNetapiClient.local_subsetcOrN)a
        Run :ref:`execution modules <all-salt.modules>` against batches of minions

        .. versionadded:: 0.8.4

        Wraps :py:meth:`salt.client.LocalClient.cmd_batch`

        :return: Returns the result from the exeuction module for each batch of
            returns
        rON)r)rGrQr!Z	cmd_batchrRrrr
�local_batch�s$�zNetapiClient.local_batchcOsDtjjjj|jdd��
}|�|�Wd�S1swYdS)z�
        Run salt-ssh commands synchronously

        Wraps :py:meth:`salt.client.ssh.client.SSHClient.cmd_sync`.

        :return: Returns the result from the salt-ssh command
        T)rPZdisable_custom_rosterN)r)rGrHZ	SSHClientr!�cmd_syncrRrrr
rH�s
�$�zNetapiClient.sshNFcKs&||d<tj�|j�}|j|||d�S)a<
        Run `runner modules <all-salt.runners>` synchronously

        Wraps :py:meth:`salt.runner.RunnerClient.cmd_sync`.

        Note that runner functions must be called using keyword arguments.
        Positional arguments are not supported.

        :return: Returns the result from the runner module
        rA)�timeout�full_return)r)�runner�RunnerClientr!rY)r.rArZr[r=r\rrr
r\�szNetapiClient.runnercK� ||d<tj�|j�}|�|�S)aG
        Run `runner modules <all-salt.runners>` asynchronously

        Wraps :py:meth:`salt.runner.RunnerClient.cmd_async`.

        Note that runner functions must be called using keyword arguments.
        Positional arguments are not supported.

        :return: event data and a job ID for the executed function.
        rA)r)r\r]r!�	cmd_async)r.rAr=r\rrr
�runner_async�
zNetapiClient.runner_asynccKr^)a=
        Run :ref:`wheel modules <all-salt.wheel>` synchronously

        Wraps :py:meth:`salt.wheel.WheelClient.master_call`.

        Note that wheel functions must be called using keyword arguments.
        Positional arguments are not supported.

        :return: Returns the result from the wheel module
        rA)r)�wheel�WheelClientr!rY�r.rAr=rbrrr
rbrazNetapiClient.wheelcKr^)a>
        Run :ref:`wheel modules <all-salt.wheel>` asynchronously

        Wraps :py:meth:`salt.wheel.WheelClient.master_call`.

        Note that wheel functions must be called using keyword arguments.
        Positional arguments are not supported.

        :return: Returns the result from the wheel module
        rA)r)rbrcr!r_rdrrr
�wheel_async&razNetapiClient.wheel_async)NF)�__name__�
__module__�__qualname__�__doc__r/r1r:rFrMrSrVrWrXrHr\r`rbrerrrr
r <s 	(

r cCs&g|]\}}|dks|�d�s|�qS)rM�_)�
startswith)rrrjrrr
�
<listcomp>6s
�rl)�	predicate)rir"�inspect�loggingr$Z	salt.authr)Zsalt.clientZsalt.client.ssh.clientZsalt.configZsalt.daemons.masterapiZsalt.exceptionsZsalt.runnerZ
salt.syspathsZsalt.utils.argsZsalt.utils.minionsZ
salt.wheelZ
salt.defaultsr�	getLoggerrf�logrrr �
getmembersrJrrrr
�<module>s2
{
�