%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python2.7/site-packages/salt/engines/
Upload File :
Create Path :
Current File : //usr/lib/python2.7/site-packages/salt/engines/hipchat.pyo

�
���^c@@s�dZddlmZmZmZddlZddlZddlZyddlZWne	k
rodZnXddlZddl
ZddlZddlZddlZddlZddlZddlZddlZddlZddlmZeje�ZdZdZdZdZd	�Zd
ddd�Z d
ddd
�Z!d
ddd�Z"dddde#ddddddddd�
Z$dS(uj
An engine that reads messages from Hipchat and sends them to the Salt
event bus.  Alternatively Salt commands can be sent to the Salt master
via Hipchat by setting the control parameter to ``True`` and using command
prefaced with a ``!``. Only token key is required, but room and control
keys make the engine interactive.

.. versionadded: 2016.11.0

:depends: hypchat
:configuration: Example configuration

    .. code-block:: yaml

        engines:
            - hipchat:
                api_url: http://api.hipchat.myteam.com
                token: 'XXXXXX'
                room: 'salt'
                control: True
                valid_users:
                    - SomeUser
                valid_commands:
                    - test.ping
                    - cmd.run
                    - list_jobs
                    - list_commands
                aliases:
                    list_jobs:
                        cmd: jobs.list_jobs
                    list_commands:
                        cmd: pillar.get salt:engines:hipchat:valid_commands target=saltmaster
                max_rooms: 0
                wait_time: 1
i(tabsolute_importtprint_functiontunicode_literalsN(tsixuhttps://api.hipchat.comii�uhipchatcC@stdk	rtStdfS(Nuhypchat is not installed(thypchattNonet__virtualname__tFalse(((s8/usr/lib/python2.7/site-packages/salt/engines/hipchat.pyt__virtual__Fsuc	C@s)tjj|�s*tdj|���nt|�dkrKtd��ndj||�}idd6}d||d<tjjj	i|d	6�}tjj
j|d
��R}	td�j|tjj
tjjj|��tjjj|	j���}
WdQXtjjj|d
dd|d|
�dS(u�
    Send file to a HipChat room via API version 2

    Parameters
    ----------
    token : str
        HipChat API version 2 compatible token - must be token for active user
    room: str
        Name or API ID of the room to notify
    filepath: str
        Full path of file to be sent
    message: str, optional
        Message to send to room
    api_url: str, optional
        Hipchat API URL to use, defaults to http://api.hipchat.com
    uFile '{0}' does not existi�uMessage too longu{0}/v2/room/{1}/share/fileu*multipart/related; boundary=boundary123456uContent-typeuBearer u
Authorizationumessageurbu�--boundary123456
Content-Type: application/json; charset=UTF-8
Content-Disposition: attachment; name="metadata"

{0}

--boundary123456
Content-Disposition: attachment; name="file"; filename="{1}"

{2}

--boundary123456--NtmethoduPOSTtheader_dicttdata(tostpathtisfilet
ValueErrortformattlentsalttutilstjsontdumpstfilestfopentstrtbasenametstringutilstto_strtreadthttptquery(ttokentroomtfilepathtmessaget	outputtertapi_urlturltheaderstmsgtrfhtpayload((s8/usr/lib/python2.7/site-packages/salt/engines/hipchat.pyt
_publish_fileKs

$unestedc
C@s�dj||�}idd6}d||d<tjjj|dd|dtd	td
|dt�d|d<tjj||dt�}tjjj|dd|dtd	td
|dt�d
S(u/
    Publishes the HTML-formatted message.
    u{0}/v2/room/{1}/notificationu
text/plainuContent-typeuBearer u
AuthorizationuPOSTRtdecodetstatusR
toptsu	text/htmlN(	RRRRRtTruet__opts__toutputthtml_format(RR RR"R#R$R%R&((s8/usr/lib/python2.7/site-packages/salt/engines/hipchat.pyt_publish_html_message~s,

c
C@s�dj||�}idd6}d||d<tjjj|dd|dtd	td
|dt�d}|tjj||dt�7}tjjj|dd|dtd	td
|dt�d
S(u.
    Publishes the output format as code.
    u{0}/v2/room/{1}/notificationu
text/plainuContent-typeuBearer u
AuthorizationuPOSTRR+R,R
R-u/code N(	RRRRRR.R/R0t
string_format(RR RR"R#R$R%R&((s8/usr/lib/python2.7/site-packages/salt/engines/hipchat.pyt_publish_code_message�s,
usaltu!usalt/engines/hipchat/incomingufilec*@sd}tjd�dkr=tjjjttd�j�nd��fd����fd�}|pm|}|s�td��nt	tj
jt�j�}|	s�t
}	ntj|d|	�}|s�td��ntjd	�i}|
dkrt}
|
|d
<n|
dkr$|
|d
<n|j|�d}x'|D]}|d
|kr>|}q>q>W|s�tjd|�tjd�tdj|���n|jdd�ddd}xVtry|jd|�d}Wn'tjjk
rtjd�q�nX|dd}x�||d|�D]�\}}|sLtjd�dS|r{||kr{|jdj|��dSng}i}tjjj|�}|d}|rt|t�r||j �kr||jd�}tjjj|�}|d}nt!|�dkrjxS|dD]D}d|krV|j"dd�\}}|||<q|j#|�qWnd|krd} n|d} |d=d|kr�d}!n|d}!|d=d |kr�|d }
|d =nd!|kr�|d!}|d!=n|r%||kr%|jd"j|��dSni}"||krgtj
j$t�}#|#j%|d#|d$|�}"n?tj&j'�}$|$j%d%j| �|||d&d%j|!��}"|r�d'd'j(|�nd(}%|r�d'd'j(d)�t)j*|�D��nd(}&d*j|||%|&| �}'|d+krCt+|||"d,|'d-|
d.|	�q)|d/krtt,|||"d,|'d-|
d.|	�q)tjj-j.�}(tjj-j/|(d0��)})tjj0j1|"|)d1td2d3�WdQXt2|||(d,|'d.|	�tjj-j3|(�q)Wtj|pt4�q�WdS(4u�
    Listen to Hipchat messages and forward them to Salt.

    token
        The HipChat API key. It requires a key for global usgae,
        assigned per user, rather than room.

    room
        The HipChat room name.

    aliases
        Define custom aliases.

    valid_users
        Restrict access only to certain users.

    valid_commands
        Restrict the execution to a limited set of commands.

    control
        Send commands to the master.

    trigger: ``!``
        Special character that triggers the execution of salt commands.

    tag: ``salt/engines/hipchat/incoming``
        The event tag on the Salt bus.

    api_url: ``https://api.hipchat.com``
        The URL to the HipChat API.

        .. versionadded:: 2017.7.0

    max_rooms: ``1000``
        Maximum number of rooms allowed to fetch. If set to 0,
        it is able to retrieve the entire list of rooms.

    wait_time: ``5``
        Maximum wait time, in seconds.

    output_type: ``file``
        The type of the output. Choose bewteen:

            - ``file``: save the output into a temporary file and upload
            - ``html``: send the output as HTML
            - ``code``: send the output as code

        This can be overridden when executing a command, using the ``--out-type`` argument.

        .. versionadded:: 2017.7.0

    outputter: ``nested``
        The format to display the data, using the outputters available on the CLI.
        This argument can also be overridden when executing a command, using the ``--out`` option.

        .. versionadded:: 2017.7.0

    HipChat Example:

    .. code-block:: text

        ! test.ping
        ! test.ping target=minion1
        ! test.ping --out=nested
        ! test.ping --out-type=code --out=table
    u__roleumasterusock_dirc@s+�r�||�ntd||�dS(u(
        fire event to salt bus
        u
event.sendN(t__salt__(ttagR'(tfire_master(s8/usr/lib/python2.7/site-packages/salt/engines/hipchat.pytfiresc3@sixb|D]Z}|d}|j|�r��|�|j|d�j�}|dd|fVqqWdS(u yield partner message umessageuufromumention_nameN(t
startswithtreplacetstrip(tall_messagesttriggerR"tmessage_textttext(R8R6(s8/usr/lib/python2.7/site-packages/salt/engines/hipchat.pyt_eval_bot_mentionss


uHipchat token not foundtendpointuUnable to connect to hipchatuConnected to Hipchatumax_resultsiuitemsunameuUnable to connect to room %siuUnable to connect to room {0}t
maxResultsiuidt
not_beforeii����u!Engine not configured for controlNu'{0} not authorized to run Salt commandsucmdu=utargetu*utgt_typeuglobu--outu
--out-typeuUsing {0} is not allowed.targtkwargu{0}ttgt_typeu ucs@s'|]\}}dj||�VqdS(u{0}={1}N(R(t.0tkeytvalue((s8/usr/lib/python2.7/site-packages/salt/engines/hipchat.pys	<genexpr>�su"@{0} Results for: {1}{2}{3} on {4}uhtmlR"R#R$ucodeuw+t	sort_keystindenti(5RR/tgetRRteventtget_master_eventt
fire_eventtUserWarningtsortedtrunnertRunnert	functionst_DEFAULT_API_URLRtHypChattlogtdebugt_DEFAULT_MAX_ROOMStroomsttimetsleepRtlatestR.trequeststHttpServiceUnavailableR"targstshlex_splitt
isinstancetdicttkeysRtsplittappendtRunnerClienttcmdtclienttLocalClienttjoinRt	iteritemsR2R4RtmkstempRRtdumpR*tsafe_rmt_DEFAULT_SLEEP(*RR taliasestvalid_userstvalid_commandstcontrolR=R6tapi_keyR$t	max_roomst	wait_timetoutput_typeR#ttarget_roomR@trunner_functionsthipctrooms_kwargst	all_roomsta_roomtafter_message_idtnew_messagestpartnerR?R`tkwargstcmdlineRhtitemRHRIttargetRFtretRRtlocalt	nice_argstnice_kwargstmessage_stringttmp_path_fntfp_((R8R7R6s8/usr/lib/python2.7/site-packages/salt/engines/hipchat.pytstart�s�P
		





		
 

'

	
	




02		%%((%t__doc__t
__future__RRRtloggingR[RRtImportErrorRtsalt.utils.argsRtsalt.utils.eventtsalt.utils.filestsalt.utils.httptsalt.utils.jsontsalt.utils.stringutilstsalt.runnertsalt.clienttsalt.loadertsalt.outputtsalt.extRt	getLoggert__name__RWRURpRYRRR*R2R4RR�(((s8/usr/lib/python2.7/site-packages/salt/engines/hipchat.pyt<module>$sR

	3 

Zerion Mini Shell 1.0