
    Vhj                     ^    d Z dZdZddlmZ ddlmZ  G d de      Zd Ze	d	k(  r e        y
y
)a  
---
module: identity_user
short_description: Manage a OpenStack identity (Keystone) user
author: OpenStack Ansible SIG
description:
  - Create, update or delete a OpenStack identity (Keystone) user.
options:
  default_project:
    description:
      - Name or ID of the project, the user should be created in.
    type: str
  description:
    description:
      - Description about the user.
    type: str
  domain:
    description:
      - Domain to create the user in if the cloud supports domains.
    type: str
  email:
    description:
      - Email address for the user.
    type: str
  is_enabled:
    description:
      - Whether the user is enabled or not.
    type: bool
    default: 'true'
    aliases: ['enabled']
  name:
    description:
      - Name of the user.
      - I(name) cannot be updated without deleting and re-creating the user.
    required: true
    type: str
  password:
    description:
      - Password for the user.
    type: str
  state:
    description:
      - Should the resource be present or absent.
    choices: [present, absent]
    default: present
    type: str
  update_password:
    choices: ['always', 'on_create']
    default: on_create
    description:
      - When I(update_password) is C(always), then the password will always be
        updated.
      - When I(update_password) is C(on_create), then the password is only set
        when creating a user.
    type: str
extends_documentation_fragment:
  - openstack.cloud.openstack
a$  
- name: Create a user
  openstack.cloud.identity_user:
    cloud: mycloud
    state: present
    name: demouser
    password: secret
    email: demo@example.com
    domain: default
    default_project: demo

- name: Delete a user
  openstack.cloud.identity_user:
    cloud: mycloud
    state: absent
    name: demouser

- name: Create a user but don't update password if user exists
  openstack.cloud.identity_user:
    cloud: mycloud
    state: present
    name: demouser
    password: secret
    update_password: on_create
    email: demo@example.com
    domain: default
    default_project: demo

- name: Create a user without password
  openstack.cloud.identity_user:
    cloud: mycloud
    state: present
    name: demouser
    email: demo@example.com
    domain: default
    default_project: demo
a"  
user:
  description: Dictionary describing the identity user.
  returned: On success when I(state) is C(present).
  type: dict
  contains:
    default_project_id:
      description: User default project ID. Only present with Keystone >= v3.
      type: str
      sample: "4427115787be45f08f0ec22a03bfc735"
    description:
      description: The description of this user
      type: str
      sample: "a user"
    domain_id:
      description: User domain ID. Only present with Keystone >= v3.
      type: str
      sample: "default"
    email:
      description: User email address
      type: str
      sample: "demo@example.com"
    id:
      description: User ID
      type: str
      sample: "f59382db809c43139982ca4189404650"
    is_enabled:
      description: Indicates whether the user is enabled
      type: bool
    links:
      description: The links for the user resource
      type: dict
      elements: str
    name:
      description: Unique user name, within the owning domain
      type: str
      sample: "demouser"
    password:
      description: Credential used during authentication
      type: str
    password_expires_at:
      description: The date and time when the password expires. The time zone
                   is UTC. A none value means the password never expires
      type: str
    )OpenStackModule)StateMachinec                       e Zd Z e e        e        e        e        edddg       ed       ed       edddg	       ed
dd
g	      	      Z e       Z G d de      Zd Zy)IdentityUserModuleTboolenabled)defaulttypealiases)required)no_logpresentabsent)r	   choices	on_createalways)	default_projectdescriptiondomainemail
is_enablednamepasswordstateupdate_passwordc                   (     e Zd Z	 d fd	Zd Z xZS ) IdentityUserModule._StateMachinec                     |dk(  r!d|vr| j                   j                  d       n|dk(  rd|v r|j                  d       t        |   ||||fi |S )Nr   r   z3update_password is 'always' but password is missing)msgr   )ansible	fail_jsonpopsuper_build_update)selfresource
attributesupdateable_attributesnon_updateable_attributesr   kwargs	__class__s          q/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/openstack/cloud/plugins/modules/identity_user.pyr$   z.IdentityUserModule._StateMachine._build_update   sr     (*z/K&& ,F& G K/J*4Lz*7(:)>)BNFLN N    c                 X    t        fddD              } | j                  d   fi |S )Nc              3   >   K   | ]  }|v r|   	||   f  y wN ).0kr'   s     r,   	<genexpr>z9IdentityUserModule._StateMachine._find.<locals>.<genexpr>   s4      P"#!"jZ]5N  !*Q-0 Ps   	domain_idr   )dictfind_function)r%   r'   r*   
query_argss    `  r,   _findz&IdentityUserModule._StateMachine._find   s<     P'4P PJ &4%%j&8GJGGr-   )r   )__name__
__module____qualname__r$   r:   __classcell__)r+   s   @r,   _StateMachiner      s     +6	N	Hr-   r?   c                    	  j                   j                  dd j                   j                        }t	         fddD              	t	         fddD              	d<    j
                  d	   }|9 j                  j                  j                  |d
      }|j                  	d   d<    j
                  d   }|Ot	        	fddD              }  j                  j                  j                  |fdd
i|}|j                  	d   d<    |d j                  j                  d dgd
d	\  }}| j                  |       y  j                  ||j                  d
             y )Nidentityuser)
connectionservice_name	type_namesdkr    c              3   ^   K   | ]$  }j                   |   |j                   |   f & y wr0   paramsr2   r3   r%   s     r,   r4   z)IdentityUserModule.run.<locals>.<genexpr>   s4      5Q3 $++a.) 5   *-)r   timeoutr   c              3   ^   K   | ]$  }j                   |   |j                   |   f & y wr0   rH   rJ   s     r,   r4   z)IdentityUserModule.run.<locals>.<genexpr>   s4      0KKN. T[[^$ 0rK   )r   r   r   r   r   r'   r   F)ignore_missingr6   r   c              3   P   K   | ]  }|d    v rd    |   |d    |   f  yw)r'   Nr1   )r2   r3   r*   s     r,   r4   z)IdentityUserModule.run.<locals>.<genexpr>   sG      G"#!"f\&:!:"("6q"9"E  !&"6q"9: Gs   #&r5   rN   default_project_id)
check_moder(   r)   wait)changed)computed)rS   rB   r1   )r?   connrF   r    r7   rI   rA   find_domainidfind_projectrQ   	exit_jsonto_dict)
r%   smdomain_name_or_idr   default_project_name_or_idr9   projectrB   
is_changedr*   s
   `        @r,   runzIdentityUserModule.run   s   499-7*0$(HH(,	   6  5F5 5
  0'0 0 	| !KK1(YY''334ECH 4 JF06		F< -%)[[1B%C"%1 G'4G GJ 6dii((55*P;@PDNPG9@F< !56 ()@)@489D#(( !'	(j <NN:N.NN: $e <  >r-   N)	r;   r<   r=   r7   argument_specmodule_kwargsr   r?   r`   r1   r-   r,   r   r      s{    Fvf6I;G4 T"9x.CD[&.%<>M FMH H*+>r-   r   c                  &    t               }  |         y r0   )r   )modules    r,   mainre      s    !F
Hr-   __main__N)
DOCUMENTATIONEXAMPLESRETURNBansible_collections.openstack.cloud.plugins.module_utils.openstackr   Aansible_collections.openstack.cloud.plugins.module_utils.resourcer   r   re   r;   r1   r-   r,   <module>rl      sN   9v$L,
\ _ ZP> P>f
 zF r-   