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/modules/__pycache__/splunk.cpython-310.pyc
o

�N�g� �@s�dZddlZddlZddlZddlZdZzddlZddlm	Z	ddlm
Z
dZWn	ey1Ynwe�e
�ZdZdZgd�Zgd	�Zd
d�Zdd
�Zdd�Zdd�Zd dd�Zdd�Zd dd�Zd dd�Zd dd�Zd dd�Zd dd�ZdS)!a�
Module for interop with the Splunk API

.. versionadded:: 2016.3.0


:depends:   - splunk-sdk python module
:configuration: Configure this module by specifying the name of a configuration
    profile in the minion config, minion pillar, or master config. The module
    will use the 'splunk' key by default, if defined.

    For example:

    .. code-block:: yaml

        splunk:
            username: alice
            password: abc123
            host: example.splunkcloud.com
            port: 8080
�NF)�	HTTPError)�AuthenticationErrorT�splunk)�realname�roles�
defaultApp�tz�name)rr	rcCstrtSdS)zF
    Only load this module if splunk is installed on this minion.
    )Fz[The splunk execution module failed to load: requires splunk python library to be installed.)�HAS_LIBS�__virtualname__�rr�G/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/splunk.py�__virtual__8srcCstd|�}|�d�S)N�
config.optionZpassword_secret_key)�__salt__�get)�profile�configrrr
�_get_secret_keyEs
rcCs8t�t�td��t|tg��}t�|����	��
dd�S)Nr�=�)�hmac�new�base64�	b64decoder�str�SERVICE_NAME�urlsafe_b64encode�digest�strip�replace)�email�mrrr
�_generate_passwordJs

�r#c	
Cs�tdd�}|�d�}|r[|�d�}|�d�}|�d��||t|�|�}ztjdd|d	||gtjd
�}WntyM}z
t�	d||�WYd}~nd}~ww|�
|�t�d
|�dSdS)z/send a email to inform user of account creationrrr!�cc�subject�messageZmailz-sz-c)�stdinzunable to send email to %s: %sNz!sent account creation email to %s)rr�formatr#�
subprocess�Popen�PIPE�	Exception�log�error�communicate�info)	r	r!rZemail_objectr$r%r&Zmail_process�errr
�_send_emailRs&



�
���
�r2cCsttd|�}d�|�d��}|tvr8t|�}ddd�}|jjd
ddi|��}i}|D]	}|||j��<q*|t|<d	S)Nr�splunk.users.{}�hostrZasc)Zsort_keyZsort_dir�count���Tr)	rr(r�__context__�_get_splunk�users�listr!�lower)rr�key�client�kwargsr9�result�userrrr
�_populate_cacheis
rAcCsttd|�}d�|�d�|�d�|�d�|�d��}|tvr6tjj|�d�|�d�|�d�|�d�d�t|<t|S)zK
    Return the splunk client, cached into __context__ for performance
    rzsplunk.{}:{}:{}:{}r4�port�username�password)r4rBrCrD)rr(rr7�	splunklibr=�connect�rrr<rrr
r8|s�
�r8cCs4td|�}d�|�d��}|tvrt|�t|S)z~
    List all users in the splunk DB

    CLI Example:

    .. code-block:: bash

        salt myminion splunk.list_users
    rr3r4)rr(rr7rArGrrr
�
list_users�s
rHc	Ks�t|�}|��|��v}|�dd�s|rdS|�dd�rE|rE||��}i}dD]}||||<q(g|d<|jD]
}|d�|j�q8|SdS)z�
    Get a splunk user by name/email

    CLI Example:

    .. code-block:: bash

        salt myminion splunk.get_user 'user@example.com' user_details=false
        salt myminion splunk.get_user 'user@example.com' user_details=true
    Zuser_detailsFT)rrr	r!r)rHr;�keysr�
role_entities�appendr	)	r!rr>Zuser_mapZ
user_foundr@�response�field�rolerrr
�get_user�s
rOc
Kst|�}|��}t|��|�}|rt�d|�dSi}tD]}|�|�r+|�|�||<qzFtD]}|�|�sHt�dd�dd�tD���WdSq/|j	j
|dt|�|d||d	d
�}t|j
|j�i}	dD]}|||	|<qgWd
Sty�}
z
t�d|
�WYd
}
~
dSd
}
~
ww)z�
    create a splunk user by name/email

    CLI Example:

    .. code-block:: bash

        salt myminion splunk.create_user user@example.com roles=['user'] realname="Test User" name=testuser
    zUser is already present %sFzMissing required params %sz, cSsg|]}t|��qSr)r)�.0�krrr
�
<listcomp>�szcreate_user.<locals>.<listcomp>r	rr)rCrDrr!r)r!rDrrzCaught exception %sN)r8r;rHrr-r.�ALLOWED_FIELDS_FOR_MODIFICATION�REQUIRED_FIELDS_FOR_CREATE�joinr9�creater#r2r	r!r,)r!rr>r=r@�property_maprMZ	req_fieldZnewuserrLr1rrr
�create_user�sJ
�
������rXcKs(t|�}|��}t|��|�}|st�d|�dSi}tD]}|�|�r+|�|�||<qi}dd�|jD�}|��D]<\}}	||}
|
durv|��dkrMq:|��dkrnt	|	t
�r]|	�d�}	t|�t|	�krmt
t|	��|d<q:|
|	krv|	||<q:|r�|jd
i|����i}tD]}||||<q�dSd	S)z�
    Create a splunk user by email

    CLI Example:

    .. code-block:: bash

        salt myminion splunk.update_user example@domain.com roles=['user'] realname="Test User"
    zFailed to retrieve user %sFcSsg|]}|j�qSr)r	)rPrNrrr
rRszupdate_user.<locals>.<listcomp>Nr	r�,Tr)r8r;rHrr-r.rSrJ�items�
isinstancer�split�setr:�updateZrefresh)r!rr>r=r@rWrMrrQ�vZresource_valueZfields_modifiedrrr
�update_usersD
�

���r`c
Cstt|�}t|��|�}|r2z	|j�|j�Wnttfy1}z
t�	d|�WYd}~dSd}~wwdS|j|jvS)z�
    Delete a splunk user by email

    CLI Example:

    .. code-block:: bash

        salt myminion splunk_user.delete 'user@example.com'
    z
Exception: %sNF)
r8rHrr9�deleter	rrr-r0)r!rr=r@r1rrr
�delete_user;s��rb)r)�__doc__rr�loggingr)r
Zsplunklib.clientrEZsplunklib.bindingrr�ImportError�	getLogger�__name__r-rrrSrTrrr#r2rAr8rHrOrXr`rbrrrr
�<module>s<�
	




"
89