HEX
Server: LiteSpeed
System: Linux s787.bom1.mysecurecloudhost.com 4.18.0-477.13.1.lve.el8.x86_64 #1 SMP Thu Jun 1 16:40:47 EDT 2023 x86_64
User: mobilech (5348)
PHP: 8.1.34
Disabled: NONE
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/netapi/__pycache__/__init__.cpython-310.pyc
o

;j2.�@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
dd�Zdd�Zdd�Zd&dd�Zd d!�Zd"d#�Zd$d%�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�||_d|_d|_d|_t�|j�}d|d<tj�|dd�|d<tj�	|d�s0t�
|d�tj�
|�|_tj�|�|_tjj�|�|_tjj�|�|_dS)NTZenable_ssh_minionsZcachedirZsaltapi)�opts�resolver�loadauth�	ckminions�copy�deepcopy�os�path�join�exists�makedirs�salt�authZResolverZLoadAuthZdaemonsZ	masterapiZaccess_keysr�utils�minionsZ	CkMinions)�selfr!Zapioptsrrr
�__init__FszNetapiClient.__init__cCs�|jdurt|jd�rt|jjd�r|jj��i|j_d|_|jdur2t|jd�r/|j��d|_|jdurYt|jd�rT|jjdurTt|jjd�rP|jj��d|j_d|_dSdS)z$
        Clean up resources
        Nr-�destroy�cache)r"�hasattrr-r2r#r$r3�r0rrr
r2Us"




�zNetapiClient.destroycCs|S�Nrr5rrr
�	__enter__jszNetapiClient.__enter__cGs|��dSr6)r2)r0�argsrrr
�__exit__mszNetapiClient.__exit__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))r0Zipc_filerrr
�_is_master_runningps	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,�
exceptionsr<)r0Z
clear_load�sensitive_load_keysr�	auth_type�err_namerrr
�_prep_auth_info�s�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.)rDr#Zcheck_authenticationrr,r@r<rr$Z
check_minions�list�
auth_check)r0�lowrBrCrrArNrErFrHZ_resr/rJZ
authorizedrrr
�_authorize_ssh�s2
�

���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.rrr?Z	raw_shellZnetapi_allow_raw_shellzRaw shell option not allowed.�sshr8rrG)r;r,r@ZSaltDaemonNotRunningr�CLIENTSZSaltInvocationError�formatr!r<rP�getattrr.r8Zformat_call)r0rOZl_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,rQ�get_local_clientr!Zrun_job�r0r8rGrQrrr
�local_async��$�zNetapiClient.local_asynccOrW)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
        rXN)r,rQrZr!�cmdr[rrr
�local�s$�zNetapiClient.localcOrW)z�
        Run :ref:`execution modules <all-salt.modules>` against subsets of minions

        .. versionadded:: 2016.3.0

        Wraps :py:meth:`salt.client.LocalClient.cmd_subset`
        rXN)r,rQrZr!Z
cmd_subsetr[rrr
�local_subset�r]zNetapiClient.local_subsetcOrW)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
        rXN)r,rQrZr!Z	cmd_batchr[r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)rYZdisable_custom_rosterN)r,rQrRZ	SSHClientr!�cmd_syncr[rrr
rR
s
�$�zNetapiClient.sshNFcKsZ||d<|durt|�}tj�|j��}|j|||d�Wd�S1s&wYdS)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
        rKN)�timeout�full_return)�floatr,�runner�RunnerClientr!rb)r0rKrcrdrGrfrrr
rfs$�zNetapiClient.runnercK�D||d<tj�|j��
}|�|�Wd�S1swYdS)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.
        rKN)r,rfrgr!�	cmd_async)r0rKrGrfrrr
�runner_async*�$�zNetapiClient.runner_asynccKrh)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
        rKN)r,�wheel�WheelClientr!rb�r0rKrGrlrrr
rl9rkzNetapiClient.wheelcKrh)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
        rKN)r,rlrmr!rirnrrr
�wheel_asyncHrkzNetapiClient.wheel_async)NF)�__name__�
__module__�__qualname__�__doc__r1r2r7r9r;rDrPrVr\r_r`rarRrfrjrlrorrrr
r <s&	(

r cCs&g|]\}}|dks|�d�s|�qS)rV�_)�
startswith)rrrtrrr
�
<listcomp>Xs
�rv)�	predicate)rsr%�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�	getLoggerrp�logrrr �
getmembersrSrrrr
�<module>s4

�