Anons79 Mini Shell

Directory : /lib/python2.7/site-packages/ansible/modules/clustering/
Upload File :
Current File : //lib/python2.7/site-packages/ansible/modules/clustering/consul_acl.pyc

�
�Udac	@`s�ddlmZmZmZeZidd6dgd6dd6ZdZd	Zd
Z	yddl
Z
eZWne
k
r�eZnXyddlZeZWne
k
r�eZnXyddlmZeZWne
k
r�eZnXdd
lmZddlmZmZdddddddddg	ZdZdZdZdZdZdZdZ dZ!d Z"d!Z#d"Z$d#Z%d$Z&d%Z'd&Z(d'Z)d(Z*d)Z+d*Z,d+Z-d,Z.d-Z/d)Z0d)Z1i
e2d.ed/e�e6e2d0d1�e6e2d.ed0d2�e6e2d.ed3d4d0e�e6e2d.e�e6e2d0d5d3d6�e6e2d0dd.ed3d7�e 6e2d0e$d8e$e%g�e!6e2d.e�e"6e2d.ed8e&e'gd0e&�e#6Z4d9�Z5d:�Z6d;�Z7d<�Z8d=�Z9d>�Z:d?�Z;d@�Z<dA�Z=dB�Z>dC�Z?dD�Z@dE�ZAdFeBfdG��YZCdHdVdI��YZDdJdWdK��YZEdLdXdM��YZFdNdYdO��YZGdPdZdQ��YZHdR�ZIdS�ZJdT�ZKeLdUkr�eK�ndS([i(tabsolute_importtdivisiontprint_functions1.1tmetadata_versiontpreviewtstatust	communitytsupported_bys;
module: consul_acl
short_description: Manipulate Consul ACL keys and rules
description:
 - Allows the addition, modification and deletion of ACL keys and associated
   rules in a consul cluster via the agent. For more details on using and
   configuring ACLs, see https://www.consul.io/docs/guides/acl.html.
version_added: "2.0"
author:
  - Steve Gargan (@sgargan)
  - Colin Nolan (@colin-nolan)
options:
  mgmt_token:
    description:
      - a management token is required to manipulate the acl lists
  state:
    description:
      - whether the ACL pair should be present or absent
    required: false
    choices: ['present', 'absent']
    default: present
  token_type:
    description:
      - the type of token that should be created
    choices: ['client', 'management']
    default: client
  name:
    description:
      - the name that should be associated with the acl key, this is opaque
        to Consul
    required: false
  token:
    description:
      - the token key identifying an ACL rule set. If generated by consul
        this will be a UUID
    required: false
  rules:
    type: list
    description:
      - rules that should be associated with a given token
    required: false
  host:
    description:
      - host of the consul agent defaults to localhost
    required: false
    default: localhost
  port:
    type: int
    description:
      - the port on which the consul agent is running
    required: false
    default: 8500
  scheme:
    description:
      - the protocol scheme on which the consul agent is running
    required: false
    default: http
    version_added: "2.1"
  validate_certs:
    type: bool
    description:
      - whether to verify the tls certificate of the consul agent
    required: false
    default: True
    version_added: "2.1"
requirements:
  - python-consul
  - pyhcl
  - requests
s�
- name: create an ACL with rules
  consul_acl:
    host: consul1.example.com
    mgmt_token: some_management_acl
    name: Foo access
    rules:
      - key: "foo"
        policy: read
      - key: "private/foo"
        policy: deny

- name: create an ACL with a specific token
  consul_acl:
    host: consul1.example.com
    mgmt_token: some_management_acl
    name: Foo access
    token: my-token
    rules:
      - key: "foo"
        policy: read

- name: update the rules associated to an ACL token
  consul_acl:
    host: consul1.example.com
    mgmt_token: some_management_acl
    name: Foo access
    token: some_client_token
    rules:
      - event: "bbq"
        policy: write
      - key: "foo"
        policy: read
      - key: "private"
        policy: deny
      - keyring: write
      - node: "hgs4"
        policy: write
      - operator: read
      - query: ""
        policy: write
      - service: "consul"
        policy: write
      - session: "standup"
        policy: write

- name: remove a token
  consul_acl:
    host: consul1.example.com
    mgmt_token: some_management_acl
    token: 172bd5c8-9fe9-11e4-b1b0-3c15c2c9fd5e
    state: absent
s�
token:
    description: the token associated to the ACL (the ACL's ID)
    returned: success
    type: str
    sample: a2ec332f-04cf-6fba-e8b8-acf62444d3da
rules:
    description: the HCL JSON representation of the rules associated to the ACL, in the format described in the
                 Consul documentation (https://www.consul.io/docs/guides/acl.html#rule-specification).
    returned: I(status) == "present"
    type: str
    sample: {
        "key": {
            "foo": {
                "policy": "write"
            },
            "bar": {
                "policy": "deny"
            }
        }
    }
operation:
    description: the operation performed on the ACL
    returned: changed
    type: str
    sample: update
N(tConnectionError(tdefaultdict(tto_textt
AnsibleModuletagentteventtkeytkeyringtnodetoperatortquerytservicetsessiont
mgmt_tokenthosttschemetvalidate_certstnametporttruleststatettokent
token_typetpresenttabsenttclientt
managementtremovetupdatetcreatetpolicytRulestIDtTypetNametrequiredtno_logtdefaultt	localhostthttpttypetbooli4!tinttlisttchoicescC`s
t|jj��}td�|D��}td�|D��}d|krdtd|d��n|jdkr�|jr�|j|kr�||jj|_n|jr�|j|kr�t||�S|j|kr�t��n|j|kr�t��nt	||�SdS(s�
    Sets an ACL based on the given configuration.
    :param consul_client: the consul client
    :param configuration: the run configuration
    :return: the output of setting the ACL
    cs`s-|]#}|jdk	r|j|fVqdS(N(RtNone(t.0tacl((sI/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul_acl.pys	<genexpr>�scs`s|]}|j|fVqdS(N(R(R6R7((sI/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul_acl.pys	<genexpr>�ss2expecting ACL list to be associated to a token: %sN(
tdecode_acls_as_jsonR7R3tdictR5tAssertionErrorRRt
update_aclt
create_acl(t
consul_clientt
configurationtacls_as_jsontexisting_acls_mapped_by_nametexisting_acls_mapped_by_token((sI/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul_acl.pytset_acl�s'
c	C`s�t||j�}|j|jk}|r�|jdk	rB|jn|j}t|j�}|jj|jd|d|jd|�}||jkr�t	��q�nt
d|d|jd|jdt�S(s�
    Updates an ACL.
    :param consul_client: the consul client
    :param configuration: the run configuration
    :return: the output of the update
    RR0RtchangedRt	operationN(tload_acl_with_tokenRRRR5tencode_rules_as_hcl_stringR7R$RR:tOutputtUPDATE_OPERATION(R=R>texisting_aclRCRtrules_as_hclt
updated_token((sI/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul_acl.pyR;s!	!c	C`s�t|j�dkr$t|j�nd	}|jjd|jd|jd|d|j�}|j}t	dt
d|d|dt�S(
s�
    Creates an ACL.
    :param consul_client: the consul client
    :param configuration: the run configuration
    :return: the output of the creation
    iRR0Rtacl_idRCRRDN(tlenRRFR5R7R%RRRRGtTruetCREATE_OPERATION(R=R>RJRR((sI/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul_acl.pyR<s
*$	cC`sS|j}|jj|�dk	}|r:|jj|�ntd|d|dt�S(s�
    Removes an ACL.
    :param consul: the consul client
    :param configuration: the run configuration
    :return: the output of the removal
    RCRRDN(RR7tinfoR5tdestroyRGtREMOVE_OPERATION(tconsulR>RRC((sI/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul_acl.pyt
remove_acl+s
	cC`s7|jj|�}|dkr-t|��nt|�S(s!
    Loads the ACL with the given token (token == rule ID).
    :param consul: the consul client
    :param token: the ACL "token"/ID (not name)
    :return: the ACL associated to the given token
    :exception ConsulACLTokenNotFoundException: raised if the given token does not exist
    N(R7RPR5tConsulACLNotFoundExceptiontdecode_acl_as_json(RSRtacl_as_json((sI/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul_acl.pyRE9scC`sAt|�dkrdSd}x|D]}|t|�7}q#W|S(s
    Converts the given rules into the equivalent HCL (string) representation.
    :param rules: the rules
    :return: the equivalent HCL (string) representation of the rules. Will be None if there is no rules (see internal
    note for justification)
    itN(RMR5tencode_rule_as_hcl_string(RRJtrule((sI/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul_acl.pyRFGs
cC`sD|jdk	r,d|j|jt|jfSd|j|jfSdS(s�
    Converts the given rule into the equivalent HCL (string) representation.
    :param rule: the rule
    :return: the equivalent HCL (string) representation of the rule
    s%s "%s" {
  %s = "%s"
}
s
%s = "%s"
N(tpatternR5tscopet_POLICY_HCL_PROPERTYR&(RZ((sI/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul_acl.pyRYXscC`s%t|�}tj|�}t|�S(s�
    Converts the given HCL (string) representation of rules into a list of rule domain models.
    :param rules_as_hcl: the HCL (string) representation of a collection of rules
    :return: the equivalent domain model to the given rules
    (R
thcltloadstdecode_rules_as_json(RJt
rules_as_json((sI/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul_acl.pytdecode_rules_as_hcl_stringdscC`s�t�}x||D]t}t||t�sF|jt|||��qx;||j�D])\}}|jt||t|��qWWqW|S(s�
    Converts the given JSON representation of rules into a list of rule domain models.
    :param rules_as_json: the JSON representation of a collection of rules
    :return: the equivalent domain model to the given rules
    (tRuleCollectiont
isinstanceR9taddtRuletitemst_POLICY_JSON_PROPERTY(RaRR\R[R&((sI/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul_acl.pyR`os	
%cC`s�tt�}x�|D]�}|jdk	rk|j||jkrJt��ni|jt6||j|j<q|j|kr�t��n|j||j<qW|S(s�
    Converts the given rules into the equivalent JSON representation according to the documentation:
    https://www.consul.io/docs/guides/acl.html#rule-specification.
    :param rules: the rules
    :return: JSON representation of the given rules
    N(R	R9R[R5R\R:R&Rh(RRaRZ((sI/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul_acl.pytencode_rules_as_jsons
cC`s�t�}|r�x�|D]�}t}x�tD]�}||kr)||dkr^td|��nt|krt|tn||}t|kr�||nd}|jt|||��t}Pq)q)W|stddj	t���qqWn|S(s�
    Converts the given YAML representation of rules into a list of rule domain models.
    :param rules_as_yml: the YAML representation of a collection of rules
    :return: the equivalent domain model to the given rules
    s;Rule for '%s' does not have a value associated to the scopes'A rule requires one of %s and a policy.t/N(
RctFalsetRULE_SCOPESR5t
ValueErrort_POLICY_YML_PROPERTYReRfRNtjoin(trules_as_ymlRtrule_as_ymlt
rule_addedR\R&R[((sI/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul_acl.pytdecode_rules_as_yml�s"	


#c
C`s`|t}|j�dkr,t|t�nt�}td|d|td|td|t�S(s�
    Converts the given JSON representation of an ACL into the equivalent domain model.
    :param acl_as_json: the JSON representation of an ACL
    :return: the equivalent domain model to the given ACL
    RXRRRR(t_RULES_JSON_PROPERTYtstripRbRctACLt_TOKEN_TYPE_JSON_PROPERTYt_TOKEN_JSON_PROPERTYt_NAME_JSON_PROPERTY(RWRJR((sI/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul_acl.pyRV�s
"	

cC`sg|D]}t|�^qS(s

    Converts the given JSON representation of ACLs into a list of ACL domain models.
    :param acls_as_json: the JSON representation of a collection of ACLs
    :return: list of equivalent domain models for the given ACLs (order not guaranteed to be the same)
    (RV(R?RW((sI/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul_acl.pyR8�sRUcB`seZdZRS(s7
    Exception raised if an ACL with is not found.
    (t__name__t
__module__t__doc__(((sI/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul_acl.pyRU�st
ConfigurationcB`s5eZdZddddddddddd�
ZRS(s(
    Configuration for this module.
    cC`s^||_||_||_||_||_||_||_||_|	|_|
|_	dS(N(
tmanagement_tokenRRRRRRRRR(tselfR~RRRRRRRRR((sI/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul_acl.pyt__init__�s									N(RzR{R|R5R�(((sI/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul_acl.pyR}�sRGcB`s#eZdZddddd�ZRS(s-
    Output of an action of this module.
    cC`s(||_||_||_||_dS(N(RCRRRD(RRCRRRD((sI/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul_acl.pyR��s			N(RzR{R|R5R�(((sI/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul_acl.pyRG�sRvcB`s)eZdZd�Zd�Zd�ZRS(sF
    Consul ACL. See: https://www.consul.io/docs/guides/acl.html.
    cC`s(||_||_||_||_dS(N(RRRR(RRRRR((sI/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul_acl.pyR��s			cC`s^|o]t||j�o]|j|jko]|j|jko]|j|jko]|j|jkS(N(Rdt	__class__RRRR(Rtother((sI/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul_acl.pyt__eq__�scC`s4t|j�t|j�At|j�At|j�AS(N(thashRRRR(R((sI/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul_acl.pyt__hash__s(RzR{R|R�R�R�(((sI/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul_acl.pyRv�s		RfcB`s>eZdZdd�Zd�Zd�Zd�Zd�ZRS(sX
    ACL rule. See: https://www.consul.io/docs/guides/acl.html#acl-rules-and-scope.
    cC`s||_||_||_dS(N(R\R&R[(RR\R&R[((sI/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul_acl.pyR�	s		cC`sFt||j�oE|j|jkoE|j|jkoE|j|jkS(N(RdR�R\R&R[(RR�((sI/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul_acl.pyR�scC`s|j|�S(N(R�(RR�((sI/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul_acl.pyt__ne__scC`s't|j�t|j�At|j�AS(N(R�R\R&R[(R((sI/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul_acl.pyR�scC`s
t|�S(N(RY(R((sI/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul_acl.pyt__str__sN(	RzR{R|R5R�R�R�R�R�(((sI/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul_acl.pyRfs			RccB`sMeZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	RS(sB
    Collection of ACL rules, which are part of a Consul ACL.
    cC`s+i|_xtD]}i|j|<qWdS(N(t_rulesRl(RR\((sI/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul_acl.pyR�#s	
cC`sZg}xG|jj�D]6\}}x'|j�D]\}}|j|�q/WqWt|�S(N(R�Rgtappendtiter(Rt	all_rulesR\tpattern_keyed_rulesR[RZ((sI/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul_acl.pyt__iter__(s
cC`s2d}x%tD]}|t|j|�7}q
W|S(Ni(RlRMR�(RtcountR\((sI/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul_acl.pyt__len__/s
cC`s(t||j�o't|�t|�kS(N(RdR�tset(RR�((sI/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul_acl.pyR�5scC`s|j|�S(N(R�(RR�((sI/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul_acl.pyR�9scC`s
t|�S(N(RF(R((sI/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul_acl.pyR�<scC`sr|j|j|jkrW|jdk	r5d|jnd}td|j|f��n||j|j|j<dS(s�
        Adds the given rule to this collection.
        :param rule: model of a rule
        :raises ValueError: raised if there already exists a rule for a given scope and pattern
        s and pattern '%s'RXsDuplicate rule for scope '%s'%sN(R[R�R\R5Rm(RRZtpatten_info((sI/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul_acl.pyRe?s"(
RzR{R|R�R�R�R�R�R�Re(((sI/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul_acl.pyRcs						cC`sp|j}|dkr!|j}n|dkr<td��ntjd|jd|jd|jd|j	d|�S(s�
    Gets a Consul client for the given configuration.

    Does not check if the Consul client can connect.
    :param configuration: the run configuration
    :return: Consul client
    s/Expecting the management token to always be setRRRtverifyRN(
R~R5RR:RStConsulRRRR(R>R((sI/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul_acl.pytget_consul_clientKs	$cC`sCtstd��nts*td��nts?td��ndS(s�
    Checks that the required dependencies have been imported.
    :exception ImportError: if it is detected that any of the required dependencies have not been imported
    sipython-consul required for this module. See: https://python-consul.readthedocs.io/en/latest/#installationsDpyhcl required for this module. See: https://pypi.org/project/pyhcl/sIrequests required for this module. See https://pypi.org/project/requests/N(tpython_consul_installedtImportErrortpyhcl_installedthas_requests(((sI/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul_acl.pytcheck_dependencies\scC`s�ttdt�}yt�Wn)tk
rH}|jdt|��nXtd|jj	t
�d|jj	t�d|jj	t�d|jj	t
�d|jj	t�d|jj	t�d	t|jj	t��d
|jj	t�d|jj	t�d|jj	t��
}t|�}y4|jtkr<t||�}nt||�}Wn?tk
r�}|jdd
|j|jt|�f��nXtd|jd|jd|j �}|j!dk	r�t#|j!�|d	<n|j$|�dS(s
    Main method.
    tsupports_check_modetmsgR~RRRRRRRRRs8Could not connect to consul agent at %s:%s, error was %sRCRDN(%Rt_ARGUMENT_SPECRkR�R�t	fail_jsontstrR}tparamstgettMANAGEMENT_PARAMETER_NAMEtHOST_PARAMETER_NAMEtSCHEME_PARAMETER_NAMEtVALIDATE_CERTS_PARAMETER_NAMEtNAME_PARAMETER_NAMEtPORT_PARAMETER_NAMERstRULES_PARAMETER_NAMEtSTATE_PARAMETER_NAMEtTOKEN_PARAMETER_NAMEtTOKEN_TYPE_PARAMETER_NAMER�RtPRESENT_STATE_VALUERBRTRRRR9RCRRDRR5Rit	exit_json(tmoduleteR>R=toutputt
return_values((sI/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul_acl.pytmainms:$t__main__((((((Mt
__future__RRRR0t
__metaclass__tANSIBLE_METADATAt
DOCUMENTATIONtEXAMPLEStRETURNRSRNR�R�RkR^R�trequests.exceptionsRR�tcollectionsR	tansible.module_utils.basicR
RRlR�R�R�R�R�R�R�R�R�R�R�tABSENT_STATE_VALUEtCLIENT_TOKEN_TYPE_VALUEtMANAGEMENT_TOKEN_TYPE_VALUERRRHRORhRtRxRwRyRnR]R9R5R�RBR;R<RTRERFRYRbR`RiRsRVR8t	ExceptionRUR}RGRvRfRcR�R�R�Rz(((sI/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul_acl.pyt<module>s�


G6








!
														-			)

Anons79 File Manager Version 1.0, Coded By Anons79
Email: [email protected]