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

�N�gN�@s�dZddlZddlmmZddlZddlZe�	e
�Zdd�Zdd�Z
ddd	�Zdd
d�Zddd
�Zddd�Zdd�Zddd�ZdS)z�
Support for BambooHR

.. versionadded:: 2015.8.0

Requires a ``subdomain`` and an ``apikey`` in ``/etc/salt/minion``:

.. code-block:: yaml

    bamboohr:
      apikey: 012345678901234567890
      subdomain: mycompany
�NcCst�rdSdS)z5
    Only load the module if apache is installed
    T)FzKThe API key was not specified. Please specify it using the "apikey" config.)�_apikey�rr�I/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/bamboohr.py�__virtual__srcCst�di��dd�S)z
    Get the API key
    �bamboohrZapikeyN)�__opts__�getrrrrr$sr�idc
	Cs�i}tddd�\}}t�|�}|D]/}|jdkrq|D]$}tt|����}d|i}|D]
}	|	j|tt|	����<q+||||<qq|S)a
    Show all employees for this company.

    CLI Example:

    .. code-block:: bash

        salt myminion bamboohr.list_employees

    By default, the return data will be keyed by ID. However, it can be ordered
    by any other field. Keep in mind that if the field that is chosen contains
    duplicate values (i.e., location is used, for a company which only has one
    location), then each duplicate value will be overwritten by the previous.
    Therefore, it is advisable to only sort by fields that are guaranteed to be
    unique.

    CLI Examples:

    .. code-block:: bash

        salt myminion bamboohr.list_employees order_by=id
        salt myminion bamboohr.list_employees order_by=displayName
        salt myminion bamboohr.list_employees order_by=workEmail
    �	employees�	directory��action�commandr	)�_query�ET�
fromstring�tag�next�iter�values�text)
�order_by�ret�status�result�root�cat�item�emp_idZemp_ret�detailsrrr�list_employees+s

�r cCsbi}|durd�d�}td|d|id�\}}t�|�}d|i}|D]
}|j|tt|����<q!|S)ah
    Show all employees for this company.

    CLI Example:

    .. code-block:: bash

        salt myminion bamboohr.show_employee 1138

    By default, the fields normally returned from bamboohr.list_employees are
    returned. These fields are:

        - canUploadPhoto
        - department
        - displayName
        - firstName
        - id
        - jobTitle
        - lastName
        - location
        - mobilePhone
        - nickname
        - photoUploaded
        - photoUrl
        - workEmail
        - workPhone
        - workPhoneExtension

    If needed, a different set of fields may be specified, separated by commas:

    CLI Example:

    .. code-block:: bash

        salt myminion bamboohr.show_employee 1138 displayName,dateOfBirth

    A list of available fields can be found at
    http://www.bamboohr.com/api/documentation/employees.php
    N�,)ZcanUploadPhotoZ
departmentZdisplayNameZ	firstNamer	ZjobTitleZlastName�locationZmobilePhoneZnicknameZ
photoUploadedZphotoUrlZ	workEmailZ	workPhoneZworkPhoneExtensionr
�fields)r
r�argsr	)�joinrrrrrrr)rr#rrrrrrrr�
show_employeeSs(�
r&cCs�|dur|dus|durddiS||i}nt|t�r!tjj�|�}d}|D]}|d|�d||�d�7}q%d|�d	�}td
||dd�\}}t|d
�|�	���S)a�
    Update one or more items for this employee. Specifying an empty value will
    clear it for that employee.

    CLI Examples:

    .. code-block:: bash

        salt myminion bamboohr.update_employee 1138 nickname Curly
        salt myminion bamboohr.update_employee 1138 nickname ''
        salt myminion bamboohr.update_employee 1138 items='{"nickname": "Curly"}
        salt myminion bamboohr.update_employee 1138 items='{"nickname": ""}
    N�Errorz'At least one key/value pair is required�z<field id="z">z</field>z
<employee>z</employee>r
�POST)r
r�data�methodr!)
�
isinstance�str�salt�utilsZyamlZ	safe_loadrr&r%�keys)r�key�value�itemsZ	xml_items�pairrrrrr�update_employee�s"


�r5c	Cs�i}tddd�\}}t�|�}|D]0}d}i}|��D]}|d||d<|ddkr/|d}q|D]}|j||j<q2||||<q|S)a�
    Show all users for this company.

    CLI Example:

    .. code-block:: bash

        salt myminion bamboohr.list_users

    By default, the return data will be keyed by ID. However, it can be ordered
    by any other field. Keep in mind that if the field that is chosen contains
    duplicate values (i.e., location is used, for a company which only has one
    location), then each duplicate value will be overwritten by the previous.
    Therefore, it is advisable to only sort by fields that are guaranteed to be
    unique.

    CLI Examples:

    .. code-block:: bash

        salt myminion bamboohr.list_users order_by=id
        salt myminion bamboohr.list_users order_by=email
    �metaZusersrN�rr	)rrrr3rr)	rrrrr�userZuser_idZuser_retrrrr�
list_users�s
�r9cCsti}tddd�\}}t�|�}|D]&}d}d|ji}|��D]}|d||d<|ddkr2|d}q|||<q|S)	z�
    Show all meta data fields for this company.

    CLI Example:

    .. code-block:: bash

        salt myminion bamboohr.list_meta_fields
    r6r#rN�namer7rr	)rrrrr3)rrrr�fieldZfield_idZ	field_retrrrr�list_meta_fields�s


�
r<�GETc	Cs�t�di��dd�}d|�d�}|r||7}|r|d|��7}t�d|�t|t�s,i}d}tjjj	||t
�d||d	d
d
td�
}t�d|d
�|d
|dgS)zg
    Make a web call to BambooHR

    The password can be any random text, so we chose Salty text.
    r�	subdomainNz)https://api.bamboohr.com/api/gateway.php/z/v1/�/zBambooHR URL: %sZ	saltyporkFT)�username�password�paramsr*�decoderr�optsz!BambooHR Response Status Code: %srr)rr�log�debugr,�dictr.r/�http�queryr)	r
rr$r+r*r>�pathZreturn_contentrrrrr�s0
�r)r	)N)NNN)NNNr=N)�__doc__�loggingZxml.etree.ElementTreeZetreeZElementTreerZsalt.utils.httpr.Zsalt.utils.yaml�	getLogger�__name__rErrr r&r5r9r<rrrrr�<module>s


(
H
$(