
    Vh&                         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mZ d dlmZ d dlmZmZmZmZmZmZmZ d	 Zd
 Zd Zedk(  r e        yy)    )absolute_importdivisionprint_functiona>  
module: pritunl_user
author: "Florian Dambrine (@Lowess)"
version_added: 2.3.0
short_description: Manage Pritunl Users using the Pritunl API
description:
  - A module to manage Pritunl users using the Pritunl API.
extends_documentation_fragment:
  - community.general.pritunl
  - community.general.attributes
attributes:
  check_mode:
    support: none
  diff_mode:
    support: none
options:
  organization:
    type: str
    required: true
    aliases:
      - org
    description:
      - The name of the organization the user is part of.
  state:
    type: str
    default: 'present'
    choices:
      - present
      - absent
    description:
      - If V(present), the module adds user O(user_name) to the Pritunl O(organization). If V(absent), removes the user O(user_name)
        from the Pritunl O(organization).
  user_name:
    type: str
    required: true
    default:
    description:
      - Name of the user to create or delete from Pritunl.
  user_email:
    type: str
    required: false
    default:
    description:
      - Email address associated with the user O(user_name).
  user_type:
    type: str
    required: false
    default: client
    choices:
      - client
      - server
    description:
      - Type of the user O(user_name).
  user_groups:
    type: list
    elements: str
    required: false
    default:
    description:
      - List of groups associated with the user O(user_name).
  user_disabled:
    type: bool
    required: false
    default:
    description:
      - Enable/Disable the user O(user_name).
  user_gravatar:
    type: bool
    required: false
    default:
    description:
      - Enable/Disable Gravatar usage for the user O(user_name).
  user_mac_addresses:
    type: list
    elements: str
    description:
      - Allowed MAC addresses for the user O(user_name).
    version_added: 5.0.0
aZ  
- name: Create the user Foo with email address foo@bar.com in MyOrg
  community.general.pritunl_user:
    state: present
    organization: MyOrg
    user_name: Foo
    user_email: foo@bar.com
    user_mac_addresses:
      - "00:00:00:00:00:99"

- name: Disable the user Foo but keep it in Pritunl
  community.general.pritunl_user:
    state: present
    organization: MyOrg
    user_name: Foo
    user_email: foo@bar.com
    user_disabled: true

- name: Make sure the user Foo is not part of MyOrg anymore
  community.general.pritunl_user:
    state: absent
    organization: MyOrg
    user_name: Foo
a  
response:
  description: JSON representation of Pritunl Users.
  returned: success
  type: dict
  sample:
    {
      "audit": false,
      "auth_type": "google",
      "bypass_secondary": false,
      "client_to_client": false,
      "disabled": false,
      "dns_mapping": null,
      "dns_servers": null,
      "dns_suffix": null,
      "email": "foo@bar.com",
      "gravatar": true,
      "groups": [
        "foo",
        "bar"
      ],
      "id": "5d070dafe63q3b2e6s472c3b",
      "name": "foo@acme.com",
      "network_links": [],
      "organization": "58070daee6sf342e6e4s2c36",
      "organization_name": "Acme",
      "otp_auth": true,
      "otp_secret": "35H5EJA3XB2$4CWG",
      "pin": false,
      "port_forwarding": [],
      "servers": []
    }
)AnsibleModule)	to_native)
dict_merge)PritunlExceptiondelete_pritunl_userget_pritunl_settingslist_pritunl_organizationslist_pritunl_userspost_pritunl_userpritunl_argument_specc                 v   i }| j                   j                  d      }| j                   j                  d      }|| j                   j                  d      | j                   j                  d      | j                   j                  d      | j                   j                  d      | j                   j                  d      | j                   j                  d      d	}t        di t        t	        |       d
d|ii      }t        |      dk(  r| j                  d|z         |d   d   }t        di t        t	        |       |d|id      }t        |      dkD  rd}|j                         D ]Q  }	||	   |d   |	   ||	<   |	dk(  s|	dk(  r$t        |d   |	         t        ||	         k7  s>d}A|d   |	   ||	   k7  sPd}S |r3t        di t        t	        |       ||d   d   |d      }
d|d<   |
|d<   n6d|d<   ||d<   n+t        di t        t	        |       ||d      }
d|d<   |
|d<    | j                  di | y )Norganization	user_name
user_emailuser_groupsuser_disableduser_gravataruser_mac_addresses	user_type)nameemailgroupsdisabledgravatarmac_addressestypefiltersr   r   z:Can not add user to organization '%s' which does not existmsgidorganization_idr    Fr   r   T)r%   user_id	user_datachangedresponse)r%   r'    )paramsgetr   r   r   len	fail_jsonr   keyssetr   	exit_json)moduleresultorg_namer   user_paramsorg_obj_listorg_idusersuser_params_changedkeyr)   s              r/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/pritunl_user.pyadd_or_update_pritunl_userr<      s   F}}  0H!!+.I ""<0--##M2MM%%o6MM%%o6**+?@!!+.K . 
 (*+
L <ALxW 	 	
 !_T"F  
 (#)"I.
E 5zA~###% 	/C3'#(8C=C  h#"8uQx}%[-=)>>*.' 8C=K$44*.'	/  ( 	(0+1#(8D>%0	H !%F9!)F: %F9!&F:$ 
$V,'-!,
 !y%zFv    c           
         i }| j                   j                  d      }| j                   j                  d      }g }t        di t        t	        |       dd|ii      }t        |      dk(  r| j                  d|d|d	       |d   d
   }t        di t        t	        |       |d|id      }t        |      dk(  rd|d<   i |d<   n1t        di t        t	        |       ||d   d
   d      }d|d<   ||d<    | j                  di | y )Nr   r   r    r   r   zCan not remove user 'z$' from a non existing organization ''r!   r#   r$   Fr(   r)   )r%   r&   Tr*   )
r+   r,   r   r   r   r-   r.   r   r
   r1   )r2   r3   r4   r   r6   r7   r8   r)   s           r;   remove_pritunl_userr@     sM   F}}  0H!!+.IL- 
 (FH-
L <A($ 	 	

 !_T"F  
 (#)"I.
E 5zQ!yz ' 
$V,'-$Qx~
 !y%zFvr=   c                  8   t               } | j                  t        t        dddg      t        dddgd      t        dd	      t        dd
dgd
      t        ddd       t        dddd       t        ddd       t        ddd       t        dddd       	             t        |       }|j                  j                  d      }	 |dk(  rt        |       y |dk(  rt        |       y y # t        $ r%}|j                  t        |             Y d }~y d }~ww xY w)NTstrorg)requiredr   aliasesFpresentabsent)rD   choicesdefault)rD   r   clientserver)rD   r   rI   list)rD   r   elementsrI   bool)	r   stater   r   r   r   r   r   r   )argument_specrO   r!   )r   updatedictr   r+   r,   r<   r@   r	   r.   r   )rP   r2   rO   es       r;   mainrT   =  s   )+Mt%%IH(=y Du58(<h UEe&5RVWFDIFDI#U%Y]^	
$ 7FMMg&E+I&v.h'  +Yq\**+s   C+ C+ +	D4DD__main__N)
__future__r   r   r   r   __metaclass__DOCUMENTATIONEXAMPLESRETURNansible.module_utils.basicr   +ansible.module_utils.common.text.convertersr   0ansible.module_utils.common.dict_transformationsr   Pansible_collections.community.general.plugins.module_utils.net_tools.pritunl.apir	   r
   r   r   r   r   r   r<   r@   rT   __name__r*   r=   r;   <module>r`      sl    A @N`2 
F 5 A G  [|7t+D zF r=   