%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python2.7/site-packages/salt/tokens/
Upload File :
Create Path :
Current File : //lib/python2.7/site-packages/salt/tokens/rediscluster.pyc

�
���^c@@s�dZddlmZmZmZyddlZeZWnek
rQe	ZnXddl
Z
ddlZddlZddl
ZddlmZeje�ZdZd�Zd�Zd�Zd	�Zd
�Zd�ZdS(u�
Provide token storage in Redis cluster.

To get started simply start a redis cluster and assign all hashslots to the connected nodes.
Add the redis hostname and port to master configs as eauth_redis_host and eauth_redis_port.
Default values for these configs are as follow:

.. code-block:: yaml

    eauth_redis_host: localhost
    eauth_redis_port: 6379

:depends:   - redis-py-cluster Python package
i(tabsolute_importtprint_functiontunicode_literalsN(tsixuredisclustercC@ststdfStS(NuLCould not use redis for tokens; rediscluster python client is not installed.(t	HAS_REDIStFalset__virtualname__(((s</usr/lib/python2.7/site-packages/salt/tokens/rediscluster.pyt__virtual__)s
cC@s{|jdd�}|jdd�}y tjd|d|dt�SWn0tjjk
rv}tjd|||�d	SXd	S(
u|
    Connect to the redis host and return a StrictRedisCluster client object.
    If connection fails then return None.
    ueauth_redis_hostu	localhostueauth_redis_porti�thosttporttdecode_responsesu(Failed to connect to redis at %s:%s - %sN(	tgettredisclustertStrictRedisClustertTruet
exceptionstRedisClusterExceptiontlogtwarningtNone(toptst
redis_hostt
redis_portterr((s</usr/lib/python2.7/site-packages/salt/tokens/rediscluster.pyt
_redis_client0s 
cC@s*t|�}|siStt|jdd��}tj|tjd��j��}yDx=|j|�dk	r�tj|tjd��j��}q[WWn't
k
r�}tjd||�iSX||d<t
jj|�}y|j||j|��Wn't
k
r%}tjd||�iSX|S(u�
    Mint a new token using the config option hash_type and store tdata with 'token' attribute set
    to the token.
    This module uses the hash of random 512 bytes as a token.

    :param opts: Salt master config options
    :param tdata: Token data to be stored with 'token' attirbute of this dict set to the token.
    :returns: tdata with token if successful. Empty dict if failed.
    u	hash_typeumd5iu:Authentication failure: cannot get token %s from redis: %sutokenu9Authentication failure: cannot save token %s to redis: %sN(RtgetattrthashlibRRt	text_typetosturandomt	hexdigestRt	ExceptionRRtsalttpayloadtSerialtsettdumps(Rttdatatredis_clientt	hash_typettokRtserial((s</usr/lib/python2.7/site-packages/salt/tokens/rediscluster.pytmk_tokenAs.
$,


cC@svt|�}|siStjj|�}y |j|j|��}|SWn'tk
rq}tjd||�iSXdS(u�
    Fetch the token data from the store.

    :param opts: Salt master config options
    :param tok: Token value to get
    :returns: Token data if successful. Empty dict if failed.
    u:Authentication failure: cannot get token %s from redis: %sN(	RR R!R"tloadsRRRR(RR(R&R)R%R((s</usr/lib/python2.7/site-packages/salt/tokens/rediscluster.pyt	get_tokenfs
cC@sXt|�}|sdSy|j|�iSWn&tk
rS}tjd||�nXdS(u�
    Remove token from the store.

    :param opts: Salt master config options
    :param tok: Token to remove
    :returns: Empty dict if successful. None if failed.
    NuCould not remove token %s: %s(RtdeleteRRR(RR(R&R((s</usr/lib/python2.7/site-packages/salt/tokens/rediscluster.pytrm_token}s
cC@s�g}t|�}|sgStjj|�}y*g|j�D]}|jd�^q>SWn$tk
r~}tjd|�gSXdS(u}
    List all tokens in the store.

    :param opts: Salt master config options
    :returns: List of dicts (token_data)
    uutf8uFailed to list keys: %sN(	RR R!R"tkeystdecodeRRR(RtretR&R)tkR((s</usr/lib/python2.7/site-packages/salt/tokens/rediscluster.pytlist_tokens�s*(t__doc__t
__future__RRRRRRtImportErrorRRtloggingRtsalt.payloadR tsalt.extRt	getLoggert__name__RRRRR*R,R.R3(((s</usr/lib/python2.7/site-packages/salt/tokens/rediscluster.pyt<module>s&


			%		

Zerion Mini Shell 1.0