
    Vh(                        d dl mZmZmZ eZd dlmZ 	 d dlm	Z	 dZ
d dlmZ d dlZd dlmZmZmZmZ  e       Zej+                   e ed	d
d
dg       ed	       ed	       ed	       ed	       ed       ed	       ed       ed	       ed	       ed	       ed       ed       ed	                   dd
ddgdfddddgdfgZg Zg Zg Z G d de      Z G d de      Zy# e$ r dZ
Y w xY w)    )absolute_importdivisionprint_function)
ActionBase)AnsibleArgSpecValidatorTF)AnsibleActionFailN)ISESDKise_argument_specise_compare_equalityget_dict_resultstrpresentabsent)typedefaultchoices)r   booldict)statenamedescriptionmac	profileIdstaticProfileAssignmentgroupIdstaticGroupAssignment
portalUseridentityStoreidentityStoreIdmdmAttributescustomAttributesidr   r"   r   c                   <    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
y	)
Endpointc                    || _         t        |j                  d      |j                  d      |j                  d      |j                  d      |j                  d      |j                  d      |j                  d      |j                  d      |j                  d	      |j                  d
      |j                  d      |j                  d      |j                  d            | _        y )Nr   r   r   r   r   r   r   r   r   r   r    r!   r"   )r   r   r   
profile_idstatic_profile_assignmentgroup_idstatic_group_assignmentportal_useridentity_storeidentity_store_idmdm_attributescustom_attributesr"   )iser   get
new_object)selfparamsr/   s      e/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/cisco/ise/plugins/action/endpoint.py__init__zEndpoint.__init__=   s    F#

=1

5!zz+.&,jj1J&KZZ	*$*JJ/F$G

<0!::o6$jj):;!::o6$jj);<zz$
    c                    	 | j                   j                  ddd|id      j                  d   }t        j                  dd|j                  d            j                         |d<   t        j                  dd|j                  d	            j                         |d	<   t        |d|      }|S # t        t        f$ r7}| j                   j                  d
j                  |             Y d }~S d }~wt        $ r d }Y |S w xY w)Nendpointget_endpoint_by_namer   F)familyfunctionr3   handle_func_exceptionERSEndPointz[-:.] r   '  An error occured when executing operation. Check the configuration of your API Settings and API Gateway settings on your ISE server. This collection assumes that the API Gateway, the ERS APIs and OpenAPIs are enabled. You may want to enable the (ise_debug: True) argument. The error was: {error}errormsg)r/   execresponseresubr0   lowerr   	TypeErrorAttributeError	fail_jsonformat	Exception)r2   r   resultes       r4   get_object_by_namezEndpoint.get_object_by_nameO   s   	XX]]!/~&+	 # 
 h}&F  VVGRF1CDJJLF6NFF7B

50ABHHJF5M$VVT:F  >* 		HH.
 &q&/      	F	s   B)B- -D <,C..D ?D c                    	 | j                   j                  dddd|i      j                  d   }|S # t        t        f$ r7}| j                   j                  dj                  |      	       Y d }~S d }~wt        $ r d }Y |S w xY w)
Nr8   get_endpoint_by_idFr"   )r:   r;   r<   r3   r=   r?   r@   rB   )r/   rD   rE   rI   rJ   rK   rL   rM   )r2   r"   rN   rO   s       r4   get_object_by_idzEndpoint.get_object_by_idh   s    	XX]]!-&+bz	 # 
 h}&F$  >* 		HH.
 &q&/      	F	s   .2 B,A33BBc                 *   d}d }| j                   j                  d      }| j                   j                  d      }|r+| j                  |      }|d uxr t        |t              }||fS |r'| j                  |      }|d uxr t        |t              }||fS )NFr"   r   )r1   r0   rS   
isinstancer   rP   )r2   rN   prev_objr"   r   s        r4   existszEndpoint.exists~   s    __  &""6*,,R0HT)Hj4.HF !! ..t4HT)Hj4.HF!!r6   c                 P    | j                   g d}t        fd|D              S )N))r   r   )r   r   )r   r   )r   r&   )r   r'   )r   r(   )r   r)   )r   r*   )r   r+   )r   r,   )r    r-   )r!   r.   )r"   r"   c              3   z   K   | ]2  \  }}t        j                  |      j                  |              4 y w)N)r   r0   ).0	ise_paramansible_paramcurrent_objrequested_objs      r4   	<genexpr>z+Endpoint.requires_update.<locals>.<genexpr>   sB      
 +M %	*M,=,=m,L 
s   8;)r1   any)r2   r]   
obj_paramsr^   s    ` @r4   requires_updatezEndpoint.requires_update   s1    

"  
 /9	
 
 	
r6   c                 j    | j                   j                  dd| j                        j                  }|S )Nr8   create_endpointr:   r;   r3   )r/   rD   r1   rE   )r2   rN   s     r4   createzEndpoint.create   s7    &??  
 (	 	
 r6   c                 h   | j                   j                  d      }| j                   j                  d      }d }|sE| j                  |      j                  d      }| j                   j                  t	        |             | j
                  j                  dd| j                         j                  }|S )Nr"   r   r"   r8   update_endpoint_by_idre   r1   r0   rP   updater   r/   rD   rE   r2   r"   r   rN   id_s        r4   rk   zEndpoint.update       __  &""6*))$/33D9COO""43<0(?  

( 	 r6   c                 h   | j                   j                  d      }| j                   j                  d      }d }|sE| j                  |      j                  d      }| j                   j                  t	        |             | j
                  j                  dd| j                         j                  }|S )Nr"   r   rh   r8   delete_endpoint_by_idre   rj   rl   s        r4   deletezEndpoint.delete   rn   r6   N)__name__
__module____qualname__r5   rP   rS   rW   rb   rf   rk   rq    r6   r4   r$   r$   <   s*    
$2,"
6

r6   r$   c                   0     e Zd Z fdZd Zd fd	Z xZS )ActionModulec                 x    t         st        d      t        t        |   |i | d| _        d| _        d | _        y )NzYansible.utils is not installed. Execute 'ansible-galaxy collection install ansible.utils'F)ANSIBLE_UTILS_IS_INSTALLEDr   superrw   r5   _supports_async_supports_check_mode_result)r2   argskwargs	__class__s      r4   r5   zActionModule.__init__   sC    )#k  	lD*D;F;$$)!r6   c                 *   t        | j                  j                  t        t              dt        t
        t        t        t              | j                  j                        }|j                         \  }}| j                  _        |st        |      y )N)argument_specargspec)required_ifrequired_one_ofmutually_exclusiverequired_together)dataschemaschema_formatschema_conditionalsr   )r   _taskr~   r   r   r   r   r   r   actionvalidater   )r2   aavvaliderrorss       r4   _check_argspeczActionModule._check_argspec   sr    %m4# $' /#5"3	! ""
 *-&vtzz#F++ r6   c                    d| j                   _        t        t        |   ||      | _        d| j
                  d<   | j                          t        | j                   j                        }t        | j                   j                  |      }| j                   j                  j                  d      }d }|dk(  rh|j                         \  }}|r|j                  |      r|j                         }	| j
                  j                  t        |	             |j                         \  }}
|
}d }|	j                  d      j                  d      }t        |      d	k(  s@|d	   j                  d
      dk(  rV|d	   j                  d
      |d	   j                  d      k(  r-| j
                  j!                  dd        |j#                          n|j%                          n|}|j#                          n|j'                         }|j                         \  }}|}|j)                          nM|dk(  rH|j                         \  }}|r#|j+                          |}|j-                          n|j/                          | j
                  j                  t        |             | j
                  j                  |j1                                | j
                  S )NFchanged)r3   r   r   )ise_update_responseUpdatedFieldsListupdatedFieldr   newValuer>   oldValuer   r   )ise_response)r   diffrz   rw   runr}   r   r	   r~   r$   r0   rW   rb   rk   r   lenpopobject_already_presentobject_updatedrf   object_createdrq   object_deletedobject_already_absent	exit_json)r2   tmp	task_varsr/   objr   rE   
obj_existsrV   r   updated_objhas_changedise_create_responsecreated_objr   s                 r4   r   zActionModule.run   s<   

\44S)D"'YDJJOO,tzz,

##G,I%(ZZ\"Z&&x0*-**,'LL''AT(UV03

-Z*H"&K"5"9"9:M"N"R"R&#K K(A-&q>--j9R?'N..z:&q>--j9: (()>E224**,'H..0&)jjl#,/JJL)[&""$h%(ZZ\"Z

#""$))+Dh78CMMO,||r6   )NN)rr   rs   rt   r5   r   r   __classcell__)r   s   @r4   rw   rw      s    ,"7 7r6   rw   )
__future__r   r   r   r   __metaclass__ansible.plugins.actionr   Nansible_collections.ansible.utils.plugins.module_utils.common.argspec_validater   ry   ImportErroransible.errorsr   rF   6ansible_collections.cisco.ise.plugins.plugin_utils.iser	   r
   r   r   r   rk   r   r   r   r   r   objectr$   rw   ru   r6   r4   <module>r      sB   A @ -& "& , 	  "#   y9h:OPue$eE" $& 1% "/U#&%('6*U( i$.hv-   Hv HVT: To  '!&'s   C1 1C;:C;