
    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mZmZmZmZ d dlmZ  e       Zej-                   e ed	d
d
dg       ed	       ed	       ed	       ed	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)AnsibleActionFail)ISESDKise_argument_specise_compare_equalityget_dict_result)InconsistentParametersstrpresentabsent)typedefaultchoices)r   )r   no_logbool)	statenameprotocolpathpassword
serverNameuserName	enablePkirepositoryNamer   r   r   c                   <    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
y	)

Repositoryc                 X   || _         t        |j                  d      |j                  d      |j                  d      |j                  d      |j                  d      |j                  d      |j                  d      |j                  d      xs |j                  d      	      | _        y )
Nr   r   r   r   r   r   r   r   )r   r   r   r   server_name	user_name
enable_pkirepository_name)isedictget
new_object)selfparamsr&   s      g/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/cisco/ise/plugins/action/repository.py__init__zRepository.__init__:   s    F#ZZ
+F#ZZ
+

<0jj,zz+."JJ'78NFJJv<N	
    c                 *   	 | j                   j                  ddd|i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
repositoryget_repositoryr%   F)familyfunctionr+   handle_func_exceptionresponser   a'  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&   execr5   r   	TypeErrorAttributeError	fail_jsonformat	Exception)r*   r   resultes       r,   get_object_by_namezRepository.get_object_by_nameG   s    	XX]]#))40&+	 # 
 hz#F %VVT:F  >* 		HH.
 &q&/      	F	s   ;? B,B  BBc                 
    d }|S N )r*   idr>   s      r,   get_object_by_idzRepository.get_object_by_id^   s    r.   c                    d}d}d }| j                   j                  d      }| j                   j                  d      }|r'| j                  |      }|d uxr t        |t              }|s)|r'| j                  |      }|d uxr t        |t              }|r%|j                  d      }|r|r||k7  rt        d      |d uxr t        |t              }||fS )NFrD   r%   z9The 'id' and 'name' params don't refer to the same object)r)   r(   rE   
isinstancer'   r@   r   )r*   	id_existsname_existsprev_objo_idr   _id	it_existss           r,   existszRepository.existsc   s    	""4(""#45,,T2H ,KHd1KIT..t4H"$.M:h3MK,,t$C[TS[,O  D(GZ$-G	8$$r.   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%   c              3   z   K   | ]2  \  }}t        j                  |      j                  |              4 y wrB   )r   r(   ).0	ise_paramansible_paramcurrent_objrequested_objs      r,   	<genexpr>z-Repository.requires_update.<locals>.<genexpr>   sB      
 +M %	*M,=,=m,L 
s   8;)r)   any)r*   rT   
obj_paramsrU   s    ` @r,   requires_updatezRepository.requires_updatex   s1    	

  
 /9	
 
 	
r.   c                 j    | j                   j                  dd| j                        j                  }|S )Nr0   create_repositoryr2   r3   r+   )r&   r8   r)   r5   )r*   r>   s     r,   createzRepository.create   s7    (??  
 (	 	
 r.   c                 h   | j                   j                  d      }| j                   j                  d      }d }|sE| j                  |      j                  d      }| j                   j                  t	        |             | j
                  j                  dd| j                         j                  }|S )NrD   r   r   r0   update_repositoryr\   r)   r(   rE   updater'   r&   r8   r5   r*   rD   r   r>   name_s        r,   rb   zRepository.update       __  &""6*))"-11&9EOO""4U#34*=doo  

( 	 r.   c                 h   | j                   j                  d      }| j                   j                  d      }d }|sE| j                  |      j                  d      }| j                   j                  t	        |             | j
                  j                  dd| j                         j                  }|S )NrD   r   r_   r0   delete_repositoryr\   ra   rc   s        r,   deletezRepository.delete   re   r.   N)__name__
__module____qualname__r-   r@   rE   rN   rY   r]   rb   rh   rC   r.   r,   r    r    9   s*    
.
%*
,

r.   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   superrm   r-   _supports_async_supports_check_mode_result)r*   argskwargs	__class__s      r,   r-   zActionModule.__init__   sC    )#k  	lD*D;F;$$)!r.   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   _taskrt   r'   rx   rz   r{   r|   r}   actionvalidater   )r*   aavvaliderrorss       r,   _check_argspeczActionModule._check_argspec   sr    %m4# $' /#5"3	! ""
 *-&vtzz#F++ r.   c                 P   d| j                   _        t        t        |   ||      | _        d| j
                  d<   | j                          t        | j                   j                        }t        | j                   j                  |      }| j                   j                  j                  d      }d }|dk(  r|j                         \  }}|r|j                  |      r[|j                         }	| j
                  j                  t        |	             |j                         \  }}
|
}|j                          n|}|j!                          n|j#                         }|j                         \  }}|}|j%                          nM|dk(  rH|j                         \  }}|r#|j'                          |}|j)                          n|j+                          | j
                  j                  t        |             | j
                  j                  |j-                                | j
                  S )	NFchanged)r+   r   r   )ise_update_responser   )ise_response)r   diffrp   rm   runrs   r   r	   rt   r    r(   rN   rY   rb   r'   object_updatedobject_already_presentr]   object_createdrh   object_deletedobject_already_absent	exit_json)r*   tmp	task_varsr&   objr   r5   
obj_existsrJ   r   updated_objise_create_responsecreated_objrv   s                r,   r   zActionModule.run   s   

\44S)D"'YDJJOO,#.

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

-Z*H&&('H..0&)jjl#,/JJL)[&""$h%(ZZ\"Z

#""$))+Dh78CMMO,||r.   )NN)ri   rj   rk   r-   r   r   __classcell__)rv   s   @r,   rm   rm      s    ,"* *r.   rm   N)
__future__r   r   r   r   __metaclass__ansible.plugins.actionr   Nansible_collections.ansible.utils.plugins.module_utils.common.argspec_validater   ro   ImportErroransible.errorsr   6ansible_collections.cisco.ise.plugins.plugin_utils.iser	   r
   r   r   =ansible_collections.cisco.ise.plugins.plugin_utils.exceptionsr   rx   rb   r'   rz   r{   r|   r}   objectr    rm   rC   r.   r,   <module>r      s"   A @ -& "& , 
 "#   y9h:OPu5!u5.U#5!F#'
 i&"23T:h!12D9   s slG: G  '!&'s   C CC