
    VhsE                         d dl mZmZmZ eZddgddZdZdZdZ	d d	l
Z
d d
lmZmZ d dlmZmZ d ZddZd Zd Zd Zd Zd Zd Zedk(  r e        y	y	)    )absolute_importdivisionprint_functionz1.1
deprecated	community)metadata_versionstatussupported_bya  
---
module: meraki_admin
short_description: Manage administrators in the Meraki cloud
version_added: '2.16.0'
description:
- Allows for creation, management, and visibility into administrators within Meraki.
deprecated:
  removed_in: '3.0.0'
  why: Updated modules released with increased functionality
  alternative: cisco.meraki.organizations_admins
options:
    name:
        description:
        - Name of the dashboard administrator.
        - Required when creating a new administrator.
        type: str
    email:
        description:
        - Email address for the dashboard administrator.
        - Email cannot be updated.
        - Required when creating or editing an administrator.
        type: str
    org_access:
        description:
        - Privileges assigned to the administrator in the organization.
        aliases: [ orgAccess ]
        choices: [ full, none, read-only ]
        type: str
    tags:
        description:
        - Tags the administrator has privileges on.
        - When creating a new administrator, C(org_name), C(network), or C(tags) must be specified.
        - If C(none) is specified, C(network) or C(tags) must be specified.
        type: list
        elements: dict
        suboptions:
            tag:
                description:
                - Object tag which privileges should be assigned.
                type: str
            access:
                description:
                - The privilege of the dashboard administrator for the tag.
                type: str
    networks:
        description:
        - List of networks the administrator has privileges on.
        - When creating a new administrator, C(org_name), C(network), or C(tags) must be specified.
        type: list
        elements: dict
        suboptions:
            id:
                description:
                - Network ID for which administrator should have privileges assigned.
                type: str
            network:
                description:
                - Network name for which administrator should have privileges assigned.
                type: str
            access:
                description:
                - The privilege of the dashboard administrator on the network.
                - Valid options are C(full), C(read-only), or C(none).
                type: str
    state:
        description:
        - Create or modify, or delete an organization
        - If C(state) is C(absent), name takes priority over email if both are specified.
        choices: [ absent, present, query ]
        required: true
        type: str
    org_name:
        description:
        - Name of organization.
        - Used when C(name) should refer to another object.
        - When creating a new administrator, C(org_name), C(network), or C(tags) must be specified.
        aliases: ['organization']
        type: str
author:
    - Kevin Breit (@kbreit)
extends_documentation_fragment: cisco.meraki.meraki
a\  
- name: Query information about all administrators associated to the organization
  meraki_admin:
    auth_key: abc12345
    org_name: YourOrg
    state: query
  delegate_to: localhost

- name: Query information about a single administrator by name
  meraki_admin:
    auth_key: abc12345
    org_id: 12345
    state: query
    name: Jane Doe

- name: Query information about a single administrator by email
  meraki_admin:
    auth_key: abc12345
    org_name: YourOrg
    state: query
    email: jane@doe.com

- name: Create new administrator with organization access
  meraki_admin:
    auth_key: abc12345
    org_name: YourOrg
    state: present
    name: Jane Doe
    org_access: read-only
    email: jane@doe.com

- name: Create new administrator with organization access
  meraki_admin:
    auth_key: abc12345
    org_name: YourOrg
    state: present
    name: Jane Doe
    org_access: read-only
    email: jane@doe.com

- name: Create a new administrator with organization access
  meraki_admin:
    auth_key: abc12345
    org_name: YourOrg
    state: present
    name: Jane Doe
    org_access: read-only
    email: jane@doe.com

- name: Revoke access to an organization for an administrator
  meraki_admin:
    auth_key: abc12345
    org_name: YourOrg
    state: absent
    email: jane@doe.com

- name: Create a new administrator with full access to two tags
  meraki_admin:
    auth_key: abc12345
    org_name: YourOrg
    state: present
    name: Jane Doe
    orgAccess: read-only
    email: jane@doe.com
    tags:
      - tag: tenant
        access: full
      - tag: corporate
        access: read-only

- name: Create a new administrator with full access to a network
  meraki_admin:
    auth_key: abc12345
    org_name: YourOrg
    state: present
    name: Jane Doe
    orgAccess: read-only
    email: jane@doe.com
    networks:
      - id: N_12345
        access: full
a
  
data:
    description: List of administrators.
    returned: success
    type: complex
    contains:
        email:
            description: Email address of administrator.
            returned: success
            type: str
            sample: your@email.com
        id:
            description: Unique identification number of administrator.
            returned: success
            type: str
            sample: 1234567890
        name:
            description: Given name of administrator.
            returned: success
            type: str
            sample: John Doe
        account_status:
            description: Status of account.
            returned: success
            type: str
            sample: ok
        two_factor_auth_enabled:
            description: Enabled state of two-factor authentication for administrator.
            returned: success
            type: bool
            sample: false
        has_api_key:
            description: Defines whether administrator has an API assigned to their account.
            returned: success
            type: bool
            sample: false
        last_active:
            description: Date and time of time the administrator was active within Dashboard.
            returned: success
            type: str
            sample: 2019-01-28 14:58:56 -0800
        networks:
            description: List of networks administrator has access on.
            returned: success
            type: complex
            contains:
                id:
                     description: The network ID.
                     returned: when network permissions are set
                     type: str
                     sample: N_0123456789
                access:
                     description: Access level of administrator. Options are 'full', 'read-only', or 'none'.
                     returned: when network permissions are set
                     type: str
                     sample: read-only
        tags:
            description: Tags the administrator has access on.
            returned: success
            type: complex
            contains:
                tag:
                    description: Tag name.
                    returned: when tag permissions are set
                    type: str
                    sample: production
                access:
                    description: Access level of administrator. Options are 'full', 'read-only', or 'none'.
                    returned: when tag permissions are set
                    type: str
                    sample: full
        org_access:
            description: The privilege of the dashboard administrator on the organization. Options are 'full', 'read-only', or 'none'.
            returned: success
            type: str
            sample: full

N)AnsibleModulejson)MerakiModulemeraki_argument_specc                 p    | j                  | j                  dd|      d      }| j                  dk(  r|S y )Nqueryadminfunctionorg_idGETmethod   )requestconstruct_pathr	   )merakir   adminss      m/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/cisco/meraki/plugins/modules/meraki_admin.py
get_adminsr     sN    ^^ 	 	

   F }}     c                    d }|D ]n  }| j                   d   1| j                   d   |d   k(  s(|| j                  d       =|d   }C| j                   d   sS| j                   d   |d   k(  si|d   c S  || j                  d       |S )Nnamez4There are multiple administrators with the same namemsgidemailzNo admin_id found)params	fail_json)r   datar!   r%   admin_idas         r   get_admin_idr+     s    H 	== ,}}V$&	1'$$)_$` wH]]7#}}W%73w	 01Or   c                 N    |D ]  }|d   |k(  s|c S  | j                  d       y )Nr$   z)No admin found by specified name or emailr"   )r'   )r   r(   r$   r*   s       r   	get_adminr-   )  s5     T7b=H DEr   c                 *    |D ]  }|d   |k(  s|c S  y )Nr%    )r   r(   r%   r*   s       r   
find_adminr0   0  s'     W:H r   c                 z    | j                  dd|      |z   }| j                  |d      }| j                  dk(  r|S y )Nrevoker   r   DELETEr      )r   r   r	   )r   r   r)   pathrs        r   delete_adminr8   7  sN      76 BXMDt& 	 	A }} r   c                     g }|D ]d  }d|v r?|d   :|j                  | j                  | j                  d   |d   |      |d   d       Fd|v sK|j                  |d   |d   d       f |S )Nnetworkorg_name)r;   net_namer(   access)r$   r=   r$   )append
get_net_idr&   )r   networksnetsnetworks_newns        r   network_factoryrD   @  s    L 
$>a	l6v'8'8&--PZB[BCI,>B (9 (D ,-X;!# $
 QYqw+,X;!# $
$ r   c                    t               }||d<   ||d<   t        | t        | |      |      }| j                  d   | j                  d   |d<   | j                  d   | j                  d   |d<   | j                  d   1| j	                  |      }t        | | j                  d   |      }||d<   || j                  j                  du r:|| j                  d	<   d| j                  d
<    | j                  di | j                   | j                  dd|      }| j                  |dt        j                  |            }	| j                  dk(  rd| j                  d
<   |	S y |f| j                  d   sg |d<   | j                  d   sg |d<   | j                  ||      du r| j                  j                  du r]| j!                  ||       |j#                  |       d| j                  d
<   || j                  d	<    | j                  di | j                   | j                  dd|      |d   z   }| j                  |dt        j                  |            }	| j                  dk(  rd| j                  d
<   |	S y || j                  d	<   | j                  j                  du r+|| j                  d	<    | j                  di | j                   yy )Nr!   r%   
org_access	orgAccesstagsr@   r3   Tr(   changedcreater   r   POST)r   payload   updater$   PUTr   r/   )dictr0   r   r&   get_netsrD   module
check_moderesult	exit_jsonr   r   r   dumpsr	   is_update_requiredgenerate_diffrN   )
r   r   r!   r%   rL   is_admin_existingrA   r@   r6   r7   s
             r   create_adminr[   Q  s   fGGFOGG"6:ff+EuM}}\".%}}\:}}V( --/}}Z ,f-"66==+DdK&
 ==##t+$+FMM&!'+FMM)$F-v}}-$$X$ONN4"(#'::g#6   ==C'+FMM)$H   
	&}}V$ GFO}}Z("$GJ$$%6@DH}}''4/$$%6@!((1+/i((/f%   16==1((GF(SVghlVmmDt&+'+zz'':  !A }}#+/i( $ %6FMM&!}}''4/(/f%   16==13 
'r   c                  b   t        t        d      t        d      t        d            } t        t        d      t        d            }t               }|j                  t        dg dd      t        d      t        d      t        ddgg d	
      t        dd|      t        dd|       t        ddg      t        d             t        |d      }t	        |d      }d|_        d|j                  d<   ddi}ddi}ddi}ddi}||j                  d<   ||j                  d<   ||j                  d<   ||j                  d<   	 t        j                  d   |j                  d<   |j                  d   dk(  r9dd g|_        |j                  d!   s!|j                  d"   s|j                  d#$       dgd%gd gfg|_        |j                  d"   }	|j                  d"   s|j                  |j                  d!         }	|j                  d   dk(  rt        ||	      }
|j                  d   s|j                  d    s|
|j                   d&<   |j                  d   Ht#        ||
|j                  d   '      }||j                   d&<   t%        ||
|      }||j                   d&<   n`|j                  d    Pt#        ||
|j                  d    (      }||j                   d&<   t%        ||
|      }||j                   d&<   n|j                  d   d)k(  r=t'        ||	|j                  d   |j                  d          }|d*k7  r||j                   d&<   n|j                  d   d%k(  r|j(                  j*                  du r:i |j                   d&<   d|j                   d+<    |j,                  d,i |j                    t#        |t        ||	      |j                  d    (      }t/        ||	|      }|d*k7  r||j                   d&<   d|j                   d+<    |j,                  d,i |j                    y # t        $ r Y w xY w)-Nstr)type)r$   r:   r=   )tagr=   )presentr   absentT)r^   choicesrequiredrG   )fullz	read-onlynone)r^   aliasesrb   listrQ   )r^   elementsoptionsorganization)r^   rf   )stater!   r%   rF   rH   r@   r;   r   )argument_specsupports_check_moder   )r   allfollow_redirectsz/organizations/{org_id}/adminsz/organizations/{org_id}/admins/r   rJ   rN   r2   
MERAKI_KEYauth_keyrk   r!   r%   r;   r   zorg_name or org_id requiredr"   ra   r(   )r!   )r%   r`   rP   rI   r/   )rQ   r   rN   r   r   r   r&   url_catalogosenvironKeyErrormututally_exclusiver'   required_if
get_org_idr   rU   r+   r-   r[   rS   rT   rV   r8   )network_arg_spectag_arg_specrl   rS   r   
query_urlscreate_urlsupdate_urlsrevoke_urlsr   r   r)   r   r7   s                 r   mainr     s!    t/$(e$4#'U#3
 De,#/L )*Mt8Vaef".#/$(ek]Tq$r"V"&FVM]"^"&EN;K"L $% 0   /3F &73FFO(-FMM$%; J< K= K= K #-Fw#.Fx #.Fx #.Fx $&JJ|$<j! }}W(&,g%6"}}Z(x1H!>?#9xj7)< F
 ]]8$F=="""6==#<=}}W(FF+}}V$V]]7-C$*FMM&!== ,#FFv9NOH$,FMM&!ffh7E$)FMM&!]]7#/#FF&--:PQH$,FMM&!ffh7E$)FMM&!	w	9	,v.w/
 7$%FMM&!	w	8	+==##t+$&FMM&!'+FMM)$F-v}}- *66 :&,mmG&<" 27$%FMM&!'+FMM)$ F%v}}%w  s    P! !	P.-P.__main__)NN)
__future__r   r   r   r^   __metaclass__ANSIBLE_METADATADOCUMENTATIONEXAMPLESRETURNrs   ansible.module_utils.basicr   r   Kansible_collections.cisco.meraki.plugins.module_utils.network.meraki.merakir   r   r   r+   r-   r0   r8   rD   r[   r   __name__r/   r   r   <module>r      s    A @ n RhQfM
^ 
 : z
"F"5po&d zF r   