
    Vh                     v    d dl mZmZmZ eZdZdZd dlm	Z	 d dl
mZmZ  G d de      Zd Zed	k(  r e        y
y
)    )absolute_importdivisionprint_functionaP  
module: ejabberd_user
author: "Peter Sprygada (@privateip)"
short_description: Manages users for ejabberd servers
requirements:
  - ejabberd with mod_admin_extra
description:
  - This module provides user management for ejabberd servers.
extends_documentation_fragment:
  - community.general.attributes
attributes:
  check_mode:
    support: full
  diff_mode:
    support: none
options:
  username:
    type: str
    description:
      - The name of the user to manage.
    required: true
  host:
    type: str
    description:
      - The ejabberd host associated with this username.
    required: true
  password:
    type: str
    description:
      - The password to assign to the username.
    required: false
  state:
    type: str
    description:
      - Describe the desired state of the user to be managed.
    required: false
    default: 'present'
    choices: ['present', 'absent']
notes:
  - Password parameter is required for O(state=present) only.
  - Passwords must be stored in clear text for this release.
  - The ejabberd configuration file must include mod_admin_extra as a module.
aY  
# Example playbook entries using the ejabberd_user module to manage users state.

- name: Create a user if it does not exist
  community.general.ejabberd_user:
    username: test
    host: server
    password: password

- name: Delete a user if it exists
  community.general.ejabberd_user:
    username: test
    host: server
    state: absent
)AnsibleModule)	CmdRunnercmd_runner_fmtc                   V    e Zd ZdZd Zed        Zed        Zd ZddZ	d Z
d	 Zd
 Zy)EjabberdUsera    This object represents a user resource for an ejabberd server.   The
    object manages user creation and deletion using ejabberdctl.  The following
    commands are currently supported:
        * ejabberdctl register
        * ejabberdctl unregister
    c                    || _         |j                  j                  d      | _        |j                  j                  d      | _        |j                  j                  d      | _        |j                  j                  d      | _        t        |dt        t        j                         t        j                         t        j                         t        j                               d      | _        y )	Nstatehostusernamepasswordejabberdctlcmdr   userpwdF)commandarg_formatscheck_rc)moduleparamsgetr   r   r   r   r   dictr   as_listrunner)selfr   s     s/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/ejabberd_user.py__init__zEjabberdUser.__init__S   s    ]]&&w/
MM%%f-	MM%%j1	==$$Z0!"**,#++-#++-"**,	 

    c                 *    | j                  ddd       S )z This method will check the current user and see if the password has
        changed.   It will return True if the user does not match the supplied
        credentials and False if it does not
        check_passworduser host pwdc                     t        |       S Nboolrcouterrs      r   <lambda>z&EjabberdUser.changed.<locals>.<lambda>k   s    Y]^`Ya r!   run_commandr   s    r   changedzEjabberdUser.changede   s      0/Daccr!   c                 *    | j                  ddd       S )z This method will check to see if the supplied username exists for
        host specified.  If the user exists True is returned, otherwise False
        is returned
        check_account	user hostc                     t        |        S r&   r'   r)   s      r   r-   z%EjabberdUser.exists.<locals>.<lambda>s   s    X\]_X`T` r!   r.   r0   s    r   existszEjabberdUser.existsm   s     ?`bbr!   c                      y)z This method does nothing N )r   entrys     r   logzEjabberdUser.logu   s    r!   Nc                 2   d }||}| j                  d|z   |      5 }|j                  || j                  | j                  | j                        }| j                  ddj                  |j                  d         z         ddd       |S # 1 sw Y   S xY w)	zw This method will run the any command specified and return the
        returns using the Ansible common module
        c                      | S r&   r8   )as    r   _procz'EjabberdUser.run_command.<locals>._proc}   s    Hr!   Nzcmd )output_processr   zcommand: %s r   )r   runr   r   r   r:   joinrun_info)r   r   optionsprocessr>   ctxress          r   r/   zEjabberdUser.run_commandy   s    	 ?G[[')'[B 	Dc''c				txx'PCHH]SXXcll5.A%BBC	D 
	D 
s   A$BBc                 &    | j                  dd      S )zM The update method will update the credentials for the user provided
        change_passwordr$   r.   r0   s    r   updatezEjabberdUser.update   s      1?CCr!   c                 &    | j                  dd      S )za The create method will create a new user on the host with the
        password provided
        registerr$   r.   r0   s    r   createzEjabberdUser.create   s     
O<<r!   c                 &    | j                  dd      S )z> The delete method will delete the user from the host
        
unregisterr4   r.   r0   s    r   deletezEjabberdUser.delete   s     k::r!   r&   )__name__
__module____qualname____doc__r    propertyr1   r6   r:   r/   rJ   rM   rP   r8   r!   r   r
   r
   K   sR    
$ d d c cD
=;r!   r
   c                  (   t        t        t        dd      t        dd      t        dd      t        dddg            d	dd
gfgd      } t        |       }d }t        d      }|j                  dk(  rW|j                  r| j
                  r| j                  d       |j                         \  }}}|dk7  r| j                  ||       n|j                  dk(  r|j                  s3| j
                  r| j                  d       |j                         \  }}}n>|j                  r2| j
                  r| j                  d       |j                         \  }}}||dk7  r| j                  |       |d|d<   nd|d<    | j                  di | y )NTstr)requiredtype)rY   no_logpresentabsent)defaultchoices)r   r   r   r   r   r   )argument_specrequired_ifsupports_check_modeF)r1   r   )msgr*   r1   r8   )r   r   r
   r   r6   
check_mode	exit_jsonrP   	fail_jsonrM   r1   rJ   )r   objr*   resultr+   r,   s         r   mainrh      s   t%04e4uT2y9h2GH	
 i*.
 !F v
C	B% F
yyH::     . ZZ\NRcQw  SR 0	i	zz     . ZZ\NRc[[     . ZZ\NRc>bAg,	z!y yFvr!   __main__N)
__future__r   r   r   rY   __metaclass__DOCUMENTATIONEXAMPLESansible.module_utils.basicr   Eansible_collections.community.general.plugins.module_utils.cmd_runnerr   r   objectr
   rh   rQ   r8   r!   r   <module>rq      sS    A @*V  5 kK;6 K;\,^ zF r!   