
    VhL                          d dl mZmZmZ eZdZdZdZd dl	Z	d dl
mZmZ d dlmZ 	 d dlZdZdZd
 Zd Zedk(  r e        yy# e$ r  e	j&                         Zd	ZY .w xY w)    )absolute_importdivisionprint_functiona_  
module: etcd3
short_description: Set or delete key value pairs from an etcd3 cluster
requirements:
  - etcd3
description:
  - Sets or deletes values in etcd3 cluster using its v3 API.
  - Needs python etcd3 lib to work.
extends_documentation_fragment:
  - community.general.attributes
attributes:
  check_mode:
    support: full
  diff_mode:
    support: none
options:
  key:
    type: str
    description:
      - The key where the information is stored in the cluster.
    required: true
  value:
    type: str
    description:
      - The information stored.
    required: true
  host:
    type: str
    description:
      - The IP address of the cluster.
    default: 'localhost'
  port:
    type: int
    description:
      - The port number used to connect to the cluster.
    default: 2379
  state:
    type: str
    description:
      - The state of the value for the key.
      - Can be present or absent.
    required: true
    choices: [present, absent]
  user:
    type: str
    description:
      - The etcd user to authenticate with.
  password:
    type: str
    description:
      - The password to use for authentication.
      - Required if O(user) is defined.
  ca_cert:
    type: path
    description:
      - The Certificate Authority to use to verify the etcd host.
      - Required if O(client_cert) and O(client_key) are defined.
  client_cert:
    type: path
    description:
      - PEM formatted certificate chain file to be used for SSL client authentication.
      - Required if O(client_key) is defined.
  client_key:
    type: path
    description:
      - PEM formatted file that contains your private key to be used for SSL client authentication.
      - Required if O(client_cert) is defined.
  timeout:
    type: int
    description:
      - The socket level timeout in seconds.
author:
  - Jean-Philippe Evrard (@evrardjp)
  - Victor Fauth (@vfauth)
a  
- name: Store a value "bar" under the key "foo" for a cluster located "http://localhost:2379"
  community.general.etcd3:
    key: "foo"
    value: "baz3"
    host: "localhost"
    port: 2379
    state: "present"

- name: Authenticate using user/password combination with a timeout of 10 seconds
  community.general.etcd3:
    key: "foo"
    value: "baz3"
    state: "present"
    user: "someone"
    password: "password123"
    timeout: 10

- name: Authenticate using TLS certificates
  community.general.etcd3:
    key: "foo"
    value: "baz3"
    state: "present"
    ca_cert: "/etc/ssl/certs/CA_CERT.pem"
    client_cert: "/etc/ssl/certs/cert.crt"
    client_key: "/etc/ssl/private/key.pem"
z
key:
  description: The key that was queried.
  returned: always
  type: str
old_value:
  description: The previous value in the cluster.
  returned: always
  type: str
N)AnsibleModulemissing_required_lib)	to_nativeTFc                  &   t        t        ddd      t        dd      t        dd      t        dd	      t        ddd
dg      t        d      t        dd      t        d      t        d      t        d      t        d            } t        d      }t        | dddgddgg      }|j                  d   !|j                  d   |j                  d       |j                  j	                  d      |d<   |j                  j                  d      |j                  d<   |j                  j                  d      |j                  d<   t        s |j                  t        d      t               g d}|j                  j                         D ci c]  \  }}||v s|| }}}	 t        j                  d+i |}	 j	                  |j                  d         }	t        	d"         |d#<   |j                  d$   dk(  r<|	d"   |j                   rd|d%<   n	 j#                  |j                  d          d|d%<   n~|j                  d$   d
k(  rZ|d#   |j                  d(   k7  rW|j                   rd|d%<   nE	 j%                  |j                  d   |j                  d(          d|d%<   n|j                  d*        |j&                  d+i | y c c}}w # t        $ r<}|j                  d t        |      z  t        j                                Y d }~Ud }~ww xY w# t        $ r<}|j                  d!t        |      z  t        j                                Y d }~~d }~ww xY w# t        $ rK}|j                  d&|j                  d   d't        |      t        j                                Y d }~d }~ww xY w# t        $ rL}|j                  d)|j                  d   d't        |      t        j                                Y d }~Pd }~ww xY w),NstrTF)typerequiredno_log)r   r   	localhost)r   defaultintiK	  presentabsent)r   r   choices)r   )r   r   path)keyvaluehostportstateuserpasswordca_certclient_cert
client_keytimeout)changedr   r   r   r   )argument_specsupports_check_moderequired_togetherr   zXThe 'ca_cert' parameter must be defined when 'client_cert' and 'client_key' are present.)msgr   	cert_certcert_keyetcd3)r$   	exception)r   r   r   r%   r&   r   r   r   z"Cannot connect to etcd cluster: %szCannot reach data: %sr   	old_valuer   r    zCannot delete z: r   zCannot add or edit key zState not recognized )dictr   params	fail_jsongetpopHAS_ETCDr   ETCD_IMP_ERRitemsr'   client	Exceptionr   	traceback
format_exc
check_modedeleteput	exit_json)
module_argsresultmoduleallowed_keysr   r   client_paramsetcdexpcluster_values
             k/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/etcd3.py
run_modulerD      s    ed59-uk2ud+y(6KLu5.&!f%V$% K& F ! )<86::NOF }}Y'FMM-,H,TwxMM%%e,F5M!'!2!2=!AFMM+ & 1 1, ?FMM*1':lS3L 39--2E2E2G_JC3R^K^S%Z_M_;||,m,;u!56 $M!$45F;}}W)'  $(y!-KKe 45
 )-F9%	w	9	,+&--"88  $(y!-HHV]]516==3IJ
 )-F9%34 Fvg `  ;AYs^T#,#7#7#9 	 	; 	;;
  ;4	#G#,#7#7#9 	 	; 	;; ! G$$6==QVCWYbcfYg)h/8/C/C/E % G GG ! G$$FMMZ_L`bklobp)q/8/C/C/E % G GGsn   K!K*K  L M$ 7,N; 	L1LL	M!%1MM!$	N8-AN33N8;	PAPPc                      t                y )N)rD   r*       rC   mainrG      s    LrF   __main__)
__future__r   r   r   r   __metaclass__DOCUMENTATIONEXAMPLESRETURNr5   ansible.module_utils.basicr   r   +ansible.module_utils.common.text.convertersr   r'   r0   r1   ImportErrorr6   rD   rG   __name__r*   rF   rC   <module>rR      s    A @JX8	
  J AHLiX zF k  '9'')LHs   A AA