
    VhW                         d Z ddlmZmZmZ eZdZdZdZ		 ddl
mZ ddlZddlmZmZ 	 ddlZd	ZdZd Zd Zd Zedk(  r e        yy# e$ r	 ddlmZ Y 9w xY w# e$ r d
Z ej*                         ZY Bw xY w)z1
Ansible Module - community.general.keyring_info
    )absolute_importdivisionprint_functiona  
module: keyring_info
version_added: 5.2.0
author:
  - Alexander Hussey (@ahussey-redhat)
short_description: Get a passphrase using the Operating System's native keyring
description: >-
  This module uses the L(keyring Python library, https://pypi.org/project/keyring/) to retrieve passphrases for a given service
  and username from the OS' native keyring.
requirements:
  - keyring (Python library)
  - gnome-keyring (application - required for headless Linux keyring access)
  - dbus-run-session (application - required for headless Linux keyring access)
extends_documentation_fragment:
  - community.general.attributes
  - community.general.attributes.info_module
options:
  service:
    description: The name of the service.
    required: true
    type: str
  username:
    description: The user belonging to the service.
    required: true
    type: str
  keyring_password:
    description: Password to unlock keyring.
    required: true
    type: str
a$  
- name: Retrieve password for service_name/user_name
  community.general.keyring_info:
    service: test
    username: test1
    keyring_password: "{{ keyring_password }}"
  register: test_password

- name: Display password
  ansible.builtin.debug:
    msg: "{{ test_password.passphrase }}"
z
passphrase:
  description: A string containing the password.
  returned: success and the password exists
  type: str
  sample: Password123
)quoteN)AnsibleModulemissing_required_libTFc           	      4   dt        | j                  d         dt        | j                  d         dt        | j                  d         d}| j                  dd	|d 
      \  }}}	 |j                  d      j	                         d   S # t
        $ r Y y w xY w)Nzecho "keyring_passwordz." | gnome-keyring-daemon --unlock
keyring get service username
zdbus-run-session -- /bin/bashT)use_unsafe_shelldataencodingzUTF-8   )r   paramsrun_commanddecode
splitlines
IndexError)moduleget_argumentdummystdouts       r/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/keyring_info.py_alternate_retrieval_methodr   U   s    fmm./0fmmI&'fmmJ'(L
 "--'	 . E65}}W%002155 s   )!B 	BBc            	         t        dd      } t        t        dd      t        dd      t        ddd            }t        |d	      }t        s |j                  t	        d
      t
               	 t        j                  |j                  d   |j                  d         }t        |      }|*d|j                  d   d|j                  d   | d<   || d<   |&d|j                  d   d|j                  d   d| d<    |j                  di |  y# t        j                  j                  $ r Y t        j                  j                  $ r Y t        $ r Y w xY w)z;
    Attempts to retrieve a passphrase from a keyring.
    F )changedmsgstrT)typerequired)r#   r$   no_log)r   r   r
   )argument_specsupports_check_modekeyring)r!   	exceptionr   r   Nz$Successfully retrieved password for @r!   
passphrasezPassword for z does not exist. )dictr   HAS_KEYRING	fail_jsonr   KEYRING_IMP_ERRr(   get_passwordr   errorsKeyringLocked	InitErrorAttributeErrorr   	exit_json)resultmodule_argsr   r+   s       r   
run_moduler9   g   sS    %R(F%$/54054EK $OF1)<X	))MM)$fmmJ&?

 08
MM)$MM*%
u  *|MM)$MM*%
u Fv+ >>'' >>##  s   20D E5EEEc                      t                y)z
    main module loop
    N)r9   r,       r   mainr<      s	     Lr;   __main__)__doc__
__future__r   r   r   r#   __metaclass__DOCUMENTATIONEXAMPLESRETURNshlexr   ImportErrorpipes	tracebackansible.module_utils.basicr   r   r(   r.   r0   
format_excr   r9   r<   __name__r,   r;   r   <module>rK      s    A @>
  J-KO$)X zF k    -K*i**,O-s"   A A AAA43A4