
    Vh                     F   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
mZ d d
lmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlZd dlZ e       Zg dZg dZdZddddddddddddZdd d!d"d#d$d%d&d'd(d)d*Zd+ Zd, Z d- Z!d. Z"d/ Z#d7d0Z$ed1fd2Z%d3 Z&d4 Z'd5 Z(e)d6k(  r e(        yy)8    )absolute_importdivisionprint_functionz1.1preview	community)metadata_versionstatussupported_bya  
---
module: cyberark_account
short_description: Module for CyberArk Account object creation, deletion,
    modification, and password retrieval using PAS Web Services SDK.
author:
    - CyberArk BizDev (@cyberark-bizdev)
    - Edward Nunez (@enunez-cyberark)
    - James Stutes (@jimmyjamcabd)
version_added: '1.0.0'
description:
    - Creates a URI for adding, deleting, modifying, and retrieving a privileged credential
      within the Cyberark Vault.  The request uses the Privileged Account
      Security Web Services SDK.


options:
    state:
        description:
            - Assert the desired state of the account C(present) to create or
              update and account object. Set to C(absent) for deletion of an
              account object. Set to C(retrieve) to get the account object including the password.
        required: false
        default: present
        choices: [present, absent, retrieve]
        type: str
    logging_level:
        description:
            - Parameter used to define the level of troubleshooting output to
              the C(logging_file) value.
        required: false
        choices: [NOTSET, DEBUG, INFO]
        type: str
    logging_file:
        description:
            - Setting the log file name and location for troubleshooting logs.
        required: false
        default: /tmp/ansible_cyberark.log
        type: str
    api_base_url:
        description:
            - A string containing the base URL of the server hosting CyberArk's
              Privileged Account Security Web Services SDK.
            - Example U(https://<IIS_Server_Ip>/PasswordVault/api/)
        required: false
        type: str
    validate_certs:
        description:
            - If C(false), SSL certificate chain will not be validated.  This
              should only set to C(true) if you have a root CA certificate
              installed on each node.
        required: false
        default: true
        type: bool
    cyberark_session:
        description:
            - Dictionary set by a CyberArk authentication containing the
              different values to perform actions on a logged-on CyberArk
              session, please see M(cyberark.pas.cyberark_authentication) module for an
              example of cyberark_session.
        required: true
        type: dict
    identified_by:
        description:
            - When an API call is made to Get Accounts, often times the default
              parameters passed will identify more than one account. This
              parameter is used to confidently identify a single account when
              the default query can return multiple results.
        required: false
        default: username,address,platform_id
        type: str
    safe:
        description:
            - The safe in the Vault where the privileged account is to be
              located.
        required: true
        type: str
    platform_id:
        description:
            - The PolicyID of the Platform that is to be managing the account
        required: false
        type: str
    address:
        description:
            - The address of the endpoint where the privileged account is
              located.
        required: false
        type: str
    name:
        description:
            - The ObjectID of the account
        required: false
        type: str
    secret_type:
        description:
            - The value that identifies what type of account it will be.
        required: false
        default: password
        choices: [password, key]
        type: str
    secret:
        description:
            - The initial password for the creation of the account
        required: false
        type: str
    new_secret:
        description:
            - The new secret/password to be stored in CyberArk Vault.
        type: str
    username:
        description:
            - The username associated with the account.
        required: false
        type: str
    secret_management:
        description:
            - Set of parameters associated with the management of the
              credential.
        required: false
        type: dict
        suboptions:
            automatic_management_enabled:
                description:
                    - Parameter that indicates whether the CPM will manage
                        the password or not.
                default: false
                type: bool
            manual_management_reason:
                description:
                    - String value indicating why the CPM will NOT manage
                        the password.
                type: str
            management_action:
                description:
                    - CPM action flag to be placed on the account object
                        for credential rotation.
                choices: [change, change_immediately, reconcile]
                type: str
            new_secret:
                description:
                    - The actual password value that will be assigned for
                        the CPM action to be taken.
                type: str
            perform_management_action:
                description:
                    - C(always) will perform the management action in
                        every action.
                    - C(on_create) will only perform the management action
                        right after the account is created.
                choices: [always, on_create]
                default: always
                type: str
    remote_machines_access:
        description:
            - Set of parameters for defining PSM endpoint access targets.
        required: false
        type: dict
        suboptions:
            remote_machines:
                description:
                    - List of targets allowed for this account.
                type: str
            access_restricted_to_remote_machines:
                description:
                    - Whether or not to restrict access only to specified
                        remote machines.
                type: bool
    platform_account_properties:
        description:
            - Object containing key-value pairs to associate with the account,
              as defined by the account platform. These properties are
              validated against the mandatory and optional properties of the
              specified platform's definition. Optional properties that do not
              exist on the account will not be returned here. Internal
              properties are not returned.
        required: false
        type: dict
        suboptions:
            KEY:
                description:
                    - Freeform key value associated to the mandatory or
                        optional property assigned to the specified
                        Platform's definition.
                aliases: [Port, ExtrPass1Name, database]
                type: str
ac  
- name: Logon to CyberArk Vault using PAS Web Services SDK
  cyberark.pas.cyberark_authentication:
    api_base_url: "http://components.cyberark.local"
    validate_certs: false
    username: "bizdev"
    password: "Cyberark1"

- name: Creating an Account using the PAS WebServices SDK
  cyberark.pas.cyberark_account:
    logging_level: DEBUG
    identified_by: "address,username"
    safe: "Test"
    address: "cyberark.local"
    username: "administrator-x"
    platform_id: WinServerLocal
    secret: "@N&Ibl3!"
    platform_account_properties:
        LogonDomain: "cyberark"
        OwnerName: "ansible_user"
    secret_management:
        automatic_management_enabled: true
    state: present
    cyberark_session: "{{ cyberark_session }}"
    register: cyberarkaction

- name: Rotate credential via reconcile and providing the password to be changed to
  cyberark.pas.cyberark_account:
    identified_by: "address,username"
    safe: "Domain_Admins"
    address: "prod.cyberark.local"
    username: "admin"
    platform_id: WinDomain
    platform_account_properties:
        LogonDomain: "PROD"
    secret_management:
        new_secret: "Ama123ah12@#!Xaamdjbdkl@#112"
        management_action: "reconcile"
        automatic_management_enabled: true
    state: present
    cyberark_session: "{{ cyberark_session }}"
    register: reconcileaccount

- name: Update password only in VAULT
  cyberark.pas.cyberark_account:
    identified_by: "address,username"
    safe: "Domain_Admins"
    address: "prod.cyberark.local"
    username: "admin"
    platform_id: Generic
    new_secret: "Ama123ah12@#!Xaamdjbdkl@#112"
    state: present
    cyberark_session: "{{ cyberark_session }}"
    register: updateaccount

- name: Retrieve account and password
  cyberark.pas.cyberark_account:
    identified_by: "address,username"
    safe: "Domain_Admins"
    address: "prod.cyberark.local"
    username: "admin"
    state: retrieve
    cyberark_session: "{{ cyberark_session }}"
    register: retrieveaccount

- name: Logoff from CyberArk Vault
  cyberark.pas.cyberark_authentication:
    state: absent
    cyberark_session: "{{ cyberark_session }}"
a,  
changed:
    description:
        - Identify if the playbook run resulted in a change to the account in
          any way.
    returned: always
    type: bool
failed:
    description: Whether playbook run resulted in a failure of any kind.
    returned: always
    type: bool
status_code:
    description: Result HTTP Status code.
    returned: success
    type: int
    sample: "200, 201, -1, 204"
result:
    description: A json dump of the resulting action.
    returned: success
    type: complex
    contains:
        address:
            description:
                - The adress of the endpoint where the privileged account is
                  located.
            returned: successful addition and modification
            type: str
            sample: dev.local
        createdTime:
            description:
                - Timeframe calculation of the timestamp of account creation.
            returned: successful addition and modification
            type: int
            sample: "1567824520"
        id:
            description: Internal ObjectID for the account object identified
            returned: successful addition and modification
            type: int
            sample: "25_21"
        name:
            description: The external ObjectID of the account
            returned: successful addition and modification
            type: str
            sample:
                - Operating System-WinServerLocal-cyberark.local-administrator
        platformAccountProperties:
            description:
                - Object containing key-value pairs to associate with the
                  account, as defined by the account platform.
            returned: successful addition and modification
            type: complex
            contains:
                KEY VALUE:
                    description:
                        - Object containing key-value pairs to associate with the
                          account, as defined by the account platform.
                    returned: successful addition and modification
                    type: str
                    sample:
                        - "LogonDomain": "cyberark"
                        - "Port": "22"
        platformId:
            description:
                - The PolicyID of the Platform that is to be managing the
                  account.
            returned: successful addition and modification
            type: str
            sample: WinServerLocal
        safeName:
            description:
                - The safe in the Vault where the privileged account is to
                  be located.
            returned: successful addition and modification
            type: str
            sample: Domain_Admins
        secretManagement:
            description:
                - Set of parameters associated with the management of
                  the credential.
            returned: successful addition and modification
            type: complex
            contains:
                automaticManagementEnabled:
                    description:
                        - Parameter that indicates whether the CPM will manage
                          the password or not.
                    returned: successful addition and modification
                    type: bool
                lastModifiedTime:
                    description:
                        - Timeframe calculation of the timestamp of account
                          modification.
                    returned: successful addition and modification
                    type: int
                    sample: "1567824520"
                manualManagementReason:
                    description:
                        - Reason for disabling automatic management of the account
                    returned: if C(automaticManagementEnabled) is set to false
                    type: str
                    sample: This is a static account
        secretType:
            description:
                - The value that identifies what type of account it will be
            returned: successful addition and modification
            type: list
            sample:
                - key
                - password
        userName:
            description: The username associated with the account
            returned: successful addition and modification
            type: str
            sample: administrator
)to_text)AnsibleModule)open_url)	HTTPError)quote)HTTPExceptionN)stateapi_base_urlvalidate_certscyberark_sessionidentified_bylogging_levellogging_file
new_secret#secret_management.management_actionsecret_management.new_secretmanagement_actionz+secret_management.perform_management_action)createdTimeidnamelastModifiedTimesafeName
secretTypesecretNO_VALUEuserNamer    
platformIdr!   platformAccountPropertiessecretManagementmanualManagementReasonautomaticManagementEnabledremoteMachinesAccess accessRestrictedToRemoteMachinesremoteMachines)usernamesafeplatform_idsecret_typeplatform_account_propertiessecret_managementmanual_management_reasonautomatic_management_enabledremote_machines_access$access_restricted_to_remote_machinesremote_machinesr-   r.   r/   r0   r1   r2   r3   r4   r5   #access_testricted_to_remoteMachinesr7   )r$   r    r%   r!   r&   r'   r(   r)   r*   r+   r,   c                     t        | t              r| t        |      k(  S t        |t              rt        |       |k(  S | |k(  S N)
isinstancestr)existing	parameters     q/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/cyberark/pas/plugins/modules/cyberark_account.pyequal_valuer@     s?    (C 3y>))	Is	#8}	))9$$    c                 X
   t        j                  d       | j                  d   }|d   }|d   }d|i}d}d}d}d	|d
   z  }	d|d   dd}
dg i}t        | j                  j	                               D ]  }|t
        vs| j                  |   | j                  |   }t        |t        |      }t        ||t        |j	                                     }|t        vsl|t        |t              ri }i }i }t        |j	                               D ]  }|d|}|t
        vs||   }t        |t        |      }t        |||t        |j	                               ni       }d|d|}|Wt        j                  d|||       |t        k(  r|j                  ||i       n@|>t        ||      s2|j                  ||i       n||t        k7  r|j                  ||i       t        j                  d|||        t        t        |j	                                     dkD  r|d   j                  dd|z  |d       t        t        |j	                                     dkD  r|d   j                  dd|z  |d       t        |      dkD  s|d   j                  dd|z  |d       7|L|t        k(  r|d   j                  dd|z  d       nLt        ||      s@|d   j                  d|d|z  d       n$|t        k7  r|d   j                  d|d|z  d       t        j                  d|||        t        |d         dk7  r3| j                   rGt        j                  d       t        j                  dt#        j$                  |             d|i}d }d}nt        j                  d!       t        j                  d"t        |d         t#        j$                  |             |d   D ]  }|g}	 t        j                  d#t#        j$                  |g             t'        ||	z   ||
t#        j$                  |      |$      }dt#        j(                  |j+                               i}d }|j-                         } |||fS # t.        t0        f$ rc}t        |t.              rt#        j2                  |      }nt5        |      }| j7                  d%||	d&|||
|j8                  '       Y d }~d }~wt:        $ r1}| j7                  d(||	d)t5        |      ||
d'       Y d }~:d }~ww xY w)*NzUpdating Accountr   r   r   resultFPATCH/PasswordVault/api/Accounts/%sr   application/jsontoken$CyberArk/1.0 (Ansible; cyberark.pas)zContent-TypeAuthorizationz
User-Agent
Operationsdefault)keys./zCchild_module_parm_value: %s child_existing_account_value=%s path=%sz'parameter_name=%s  value=%s existing=%sr   addz/%s)oppathvaluereplaceremove)rS   rT   )rS   rU   rT   z+Proceeding with Update Account (CHECK_MODE)zOperations => %sTzProceeding with Update Accountz)Processing invidual operations (%d) => %sz ==> %smethodheadersdatar   zYError while performing update_account.Please validate parameters provided.
*** end_point=
 ==> msgpayloadrZ   status_codez=Unknown error while performing update_account.
*** end_point=
)loggingdebugparamslistrO   ansible_specific_parametersreferenced_valuecyberark_reference_fieldnamescyberark_fixed_propertiesr;   dictremoval_valueupdater@   lenappend
check_modejsondumpsr   loadsreadgetcoder   r   loadr   	fail_jsoncode	Exception)moduleexisting_accountr   r   r   rC   changedlast_status_code
HTTPMethod	end_pointrZ   r_   parameter_namemodule_parm_valuecyberark_property_nameexisting_account_value	replacingaddingremovingchild_parm_namenested_parm_namechild_module_parm_valuechild_cyberark_property_namechild_existing_account_value
path_value	operationindividual_payloadresponsehttp_exceptionresunknown_exceptions                                  r?   update_accountr     s   MM$%}}%78#N3L%&67N ()FGJ03CD3III +)'2<G R G v}}1134 K"==n-9 &n =%5 =~&" &6& *//12&"
 &-FF$0Z%t6 !#IF!H+/0A0F0F0H+I @6Do+V(+3NN6G6X3;K / =(7<8
 <L < 6#9#E !%%;%@%@%B C%'<8 !7 <*J  <G ')R %<$@$.!" $;m#K$,OO,HJf)*%& %<$G,7(D(?-& %.$4$4,HJa)*%& !8 C$;}$L !'(DF]%&!"
 $MM I * 7 <	w@D 4./!3-44&+(-0F(F)/ 4	 012Q6-44&/(-0F(F)2 8}q(-44&.(-0F(F)1 .9,=#L188'/AW9W X "--CEV!W#L188*3->,14J,J!" +m;-44&+):(-0F(F MMA&(9;QQKZ 7< !Q&MMGHMM,djj.AB 01FG!MM:;MM;GL)*

7#
 %\2 0	&/[".MM)TZZ-DE'$y0) '!ZZ(:;'5 H '

8==?(CDF"G'/'7'7'9$0d V-..A "=1 !.)<"ii7%n5$$
  ,Y=
 !3 '$2$7$7 % 
 
 ! $$  ,Y@Q8RT !3 '$& % 	 	s&   1BQ??T)AS,,T)8&T$$T)c           
         t        j                  d       | j                  d   }|d   }|d   }i }d}d}d|d   d	d
}d| j                  d   i}t        | j                  j	                               D ]l  }	|	t
        vs| j                  |	   t        |	t        |	      }
t        | j                  |	   t              ri ||
<   t        | j                  |	   j	                               D ]t  }t        |t        |      }t        j                  d|	||
|       |	dz   |z   t
        vs=| j                  |	   |   Pt        | j                  |	   |t        d      ||
   |<   v nh|	t        vr-t        | j                  |	t        d      }|B|t        k7  r9|||	<   n3t        | j                  |	t        d      }||t        k7  r||t        |	   <   t        j                  d|	       o t        j                  dt        j                  |             	 | j                  rt        j                  d       ddd idfS t        j                  d       t!        ||z   ||t        j                  |      |      }dt        j"                  |j%                               i}d||j'                         fS # t(        t*        f$ rb}t        |t(              rt        j,                  |      }nt/        |      }| j1                  d||d||||j2                         Y d }~y d }~wt4        $ r0}| j1                  d||dt/        |      ||d       Y d }~y d }~ww xY w)NzAdding Accountr   r   r   POSTz/PasswordVault/api/AccountsrG   rH   rI   rJ   r    r.   rM   zOparameter_name =%s.%s cyberark_property_name=%s cyberark_child_property_name=%srP   FTzparameter_name =%szAdd Account Payload => %sz(Proceeding with Add Account (CHECK_MODE)rC   rD   zProceeding with Add AccountrX   zVError while performing add_account.Please validate parameters provided.
*** end_point=r\   r]   z:Unknown error while performing add_account.
*** end_point=ra   )rb   rc   rd   re   rO   rf   rg   rh   r;   rj   deep_get_emptyrk   rp   rq   ro   r   rr   rs   rt   r   r   ru   r   rv   rw   rx   )ry   r   r   r   rC   r}   r~   rZ   r_   r   r   dict_keycyberark_child_property_namer   r   r   r   r   s                     r?   add_accountr     s   MM"#}}%78#N3L%&67N FJ-I +)'2<G 6==01Gv}}1134 9@"==n-9%5 =~&" &--7>24./ $V]]>%B%G%G%I J H3C "?40 MM> ' .4	 ',x7:;"MM.9(CO %"MM.98VU   678'2 ")FF(0~vu)% *5-> .  * )1~vt)% *5-> .  9.I MM.?s9@v MM-tzz'/BC0
MMDE8T*B//MM78y(!ZZ(-H 

8==? ;<F&("2"2"455}% 
ni0))N+C.)C 4@CQ &++ 	 		
 		
  
  G4E,FH  	 		
 		

s,   'J' 4A2J' 'M6ALM&M

Mc           
      ~   | j                   rt        j                  d       ddd idfS t        j                  d       | j                  d   }|d   }|d   }i }d	}d
|d   z  }d|d   dd}	 t	        ||z   |||      }	dd i}d||	j                         fS # t        t        f$ ra}
t        |
t              rt        j                  |
      }nt        |
      }| j                  d||d|||
j                         Y d }
~
y d }
~
wt        $ r/}| j                  d||dt        |      |d       Y d }~y d }~ww xY w)NzDeleting Account (CHECK_MODE)TrC   rD   zDeleting Accountr   r   r   DELETErF   r   rG   rH   rI   rJ   rY   rZ   r   zYError while performing delete_account.Please validate parameters provided.
*** end_point=r\   r^   rZ   r`   =Unknown error while performing delete_account.
*** end_point=ra   )ro   rb   rc   rd   r   rt   r   r   r;   rp   ru   r   rv   rw   rx   )ry   rz   r   r   r   rC   r}   r~   rZ   r   r   r   r   s                r?   delete_accountr   B  s   56x&++()!==);<'7)*:; 
47G7MM	 /-g6@
(	y(!-	H %F&("2"2"455=) 	.)4ii/n- 8DYPSU  *//     
	 $Y8I0JL     
	s%   -(B D<%ADD<%D77D<c           
         | j                   d   }|d   }|d   }t        | j                   ddd      }t        | j                   ddd      }t        j                  d||       i }d }i }	d }
||d	   }
n| j                  rd
}
|dk(  r,|*|dk7  r%t        j                  d       d|
z  }d|	d<   ||	d<   n|dk(  r'|dk(  s| t        j                  d       d|
z  }d|	d<   n|dk(  r,|*|dk7  r%t        j                  d       d|
z  }d|	d<   ||	d<   n|dk(  rt        j                  d       d|
z  }nedt        | j                   j                               v r@| j                   d   1t        j                  d       d|
z  }d|	d<   | j                   d   |	d<   || j                  rt        j                  d       d|dfS t        j                  d       dd i}d |d!   d"d#}d$}	 t        ||z   ||t        j                  |	      |%      }d||j                         fS d|dfS # t        t        f$ rb}t        |t              rt        j                  |      }nt        |      }| j!                  d&||d'|||	|j"                  (       Y d }~y d }~wt$        $ r0}| j!                  d)||d*t        |      ||	d(       Y d }~y d }~ww xY w)+Nr   r   r   r   	NOT_FOUNDFr   z)management_action: %s  cpm_new_secret: %sr   i'  changez$CPM change secret for next CPM cyclez./PasswordVault/API/Accounts/%s/SetNextPasswordChangeImmediatelyNewCredentialschange_immediatelyz)CPM change_immediately with random secretz%/PasswordVault/API/Accounts/%s/ChangeTChangeEntireGroupz0CPM change immediately secret for next CPM cycle	reconcilezCPM reconcile secretz(/PasswordVault/API/Accounts/%s/Reconciler   zChange Credential in Vaultz./PasswordVault/API/Accounts/%s/Password/Updatez0Proceeding with Credential Rotation (CHECK_MODE)rD   z#Proceeding with Credential RotationrC   rG   rH   rI   rJ   r   rX   zXError while performing reset_account.Please validate parameters provided.
*** end_point=r\   )r^   rZ   r_   r`   r   ra   )rd   r   rb   rc   ro   re   rO   r   rp   rq   rt   r   r   r;   ru   r   rv   rw   rx   )ry   rz   r   r   r   r   cpm_new_secretrC   r~   r_   existing_account_idrZ   r}   r   r   r   r   s                    r?   reset_account_if_neededr     s\   }}%78#N3L%&67N !<k5 5{EN MM35F
 FIG#.t4			" 	X%&k)<=< 	 (-#$$2 !	2	2+%)?AB<@SS	'+#$	2	2"~'DHI< 	 (,#$$2 !	k	),-?CVV	V]]//122MM,'323< 	 (,#$$*MM,$? !MMLM&"%%MM?@%F 2!1'!:DG
  J*# 9,%#G,#1 fh&6&6&899F vr""C }- ni8))N3C!.1C   $Y5 $# . 3 3 ! 
 
     (G<M4NP $# " ! 	 	s%   8H K,AJ		K&K  Kc                      | ||n|v r||    S |S r:    )fielddctrO   rN   s       r?   rg   rg     s    4+;4E3u:R7RrA   Tc           
         i }|j                  d      D ]  }	 |}|rt        |t        |      }t        t	        |j                                     dk(  r| }t        j                  ddj                  t	        |j                                     ||       |t	        |j                               v r||   n||   }||c S  |S # t        $ r6}t        j                  dt        |             |t        u r |cY d }~c S d }~ww xY w)NrP   rM   r   zkeys=%s key_field=>%s   key=>%s,zKeyError %s)splitrg   rh   rm   re   rO   rb   rc   joinKeyErrorr   r   )r   dotted_pathrN   use_reference_table
result_dctkey	key_fieldes           r?   r   r   
  s   J  % 	I",6	 4
)*+q0 
MM1joo/01	 Z__%6 77 9%_ 
 ! "-<   	MM-4& N		s   B#C	D)C<4D<Dc                 |   t        j                  d       | j                  d   j                  d      }t        j                  dt	        j
                  |             d| j                  v r3| j                  d   $t        d      t        | j                  d         z   nd }d }|D ].  }|t        vs||dz   ndt        | j                  |d	d
      }0 t        j                  d|       t        j                  d|       | j                  d   }|d   }|d   }d }|"| d|dt        |j                               }n|d|j                         z  }nd|z  }t        j                  d|       d|d   dd}		 t        j                  d|z   |z          t        ||z   d|	|      }
|
j                         }t	        j                  |      }t        j                  dt	        j
                  |             |d   dk(  rd
d |
j                         fS d}d }|d   D ]  }t        j                  d t	        j
                  |             d
}|D ]c  }t        ||d	      }t        j                  d!|||t        | j                  |d	             |d	k7  r|t        | j                  |d	d
      k(  rd"}ad
} n |s|d#z   }||} t        j                  d$|t	        j
                  |             |d#kD  r| j                  d%|z  &       y |d#k(  ||
j                         fS # t        t         f$ r\}|j"                  d'k(  rd
d |j"                  fcY d }~S | j                  d(||d)t%        |      |	|j"                  *       Y d }~y d }~wt&        $ r/}| j                  d+||d,t%        |      |	d-*       Y d }~y d }~ww xY w).NzFinding Accountr   r   zIdentified_by: %sr.   zsafeName eq   	NOT FOUNDFzSearch_String => %szSafe Filter => %sr   r   r   z#/PasswordVault/api/accounts?filter=z&search=z%/PasswordVault/api/accounts?search=%sz%/PasswordVault/api/accounts?filter=%szEnd Point => %srG   rH   rI   rJ   zExecuting: GETr   zRESULT => %scountr   rU   zAcct Record => %szYComparing field %s | record_field_name=%s  record_field_value=%s   module.params_value=%sT   z&How Many: %d  First Record Found => %szTError while performing get_account. Too many rows (%d) found matching your criteria!)r^   i  zVError while performing get_account.Please validate parameters provided.
*** end_point=r\   r   z:Unknown error while performing get_account.
*** end_point=ra   rD   )rb   rc   rd   r   rp   rq   r   rf   r   lstripr   rs   rr   rt   rv   r   r   rw   r   rx   )ry   identified_by_fieldssafe_filtersearch_stringr   r   r   r   r~   rZ   r   result_stringaccounts_datahow_manyfirst_record_foundaccount_recordfoundrecord_field_valuer   r   s                       r?   get_accountr   -  s   MM#$!==9??DMM%tzz2F'GH V]]"v}}V'<'H 	nfmmF&; << 
 M% 33'4'@#bH{EBM MM'7MM%{3}}%78#N3L%&67NI [%<-&&()
	 
	"<AUAUAWX	;{K	MM#Y/ +)'2<GZ
ml2Y>?9$)	
 !

=1ndjj&?@!Q&4!1!1!344H!%"/"8 <14::n3MN1 E)1.%)U&MMM * {C	 *[8*#FMM5+uMN !% %'( '!|H)1-;*5<8 MM8

-.
 !|  K 	 !  !A'98;K;K;MNN}% #%4!4!455
 $Y0GI
  *//  	 	  

  G4E,FH  	 	
 	


sK   ;BL B!L 3L ;AL L N;)N N;/N  N;%N66N;c           
         t        j                  d       | j                  d   }|d   }|d   }|}d}d|d   z  }d|d	   d
d}	 t        ||z   |||      }	|	j	                         j                  d      }
|
j                  d      r|
j                  d      s| j                  d||d|d       |
dd }
|
|d<   t        j                  d       d||	j                         fS # t        t        f$ rc}d}t        |t              rt        j                  |      }nt        |      }| j                  d||d|||j                          Y d }~y d }~wt"        $ r/}| j                  d||dt        |      |d       Y d }~y d }~ww xY w)NzRetrieving Passwordr   r   r   r   z0/PasswordVault/api/Accounts/%s/Password/Retriever   rG   rH   rI   rJ   r   zutf-8"ziError while performing retrieve_password.The returned value was not formatted as expected.
*** end_point=ra   rD   )r^   rZ   status_cooder   passwordzPassword RetrievedFr   z\Error while performing retrieve_password.Please validate parameters provided.
*** end_point=r\   r   z@Unknown error while performing retrieve_password.
*** end_point=)rb   rc   rd   r   rs   decode
startswithendswithrv   rt   r   r   r;   rp   ru   r   rw   rx   )ry   rz   r   r   r   rC   r}   r~   rZ   r   r   r   r   r   s                 r?   retrieve_passwordr     s   MM'(}}%78#N3L%&67NFJBEUVZE[[I +)'2<G:
9$)	
 ==?))'2##C(X->->s-C 1=iI     Ab>%z*+vx//122}% 
ni0))N+C.)C 4@CQ &++ 	 	
 	
  

  G4E,FH  	 	
 	


s&   BC$ $F3AEF%FFc                     i ddg dddddg ddd	dd
ddddiddddddddddddddddddddddddddddddddddd gdd!d"ddddd#ddddd$dddd%dddddddidg d&dddd'dd(d)gd)dd*dd+d,ddddiddid-d.d/dddi} t        | d0      }|j                  d   1t        j                  |j                  d	   |j                  d   1       t        j                  d2       |j                  d   }t        |      \  }}}t        j                  d3|rd4nd5|       d}d6|i}|dk(  r|rt        ||      \  }}}nt        |      \  }}}d)}d%t        |j                  j                               v r1|j                  d%   }	|	 d7t        |	j                               v r|	d7   }t        j                  d8t        j                  |             |d)k(  s|d(k(  rI|sGt        ||d6         \  }
}}|
r2d}n/|r|d9k(  rt        ||      \  }}}n|r|d:k(  rt        ||      \  }}}|j!                  |||;       y )<Nr   r<   )presentabsentretriever   )typechoicesrN   r   )NOTSETDEBUGINFO)r   r   r   z/tmp/ansible_cyberark.log)r   rN   r   r   r   booltruer   Trj   )requiredr   no_logr   Fzusername,address,platform_id)r   r   rN   r.   )r   r   r/   addressr   r0   r   r   )r   r   r   rN   r"   r   r-   r2   )r   r   r   )r   r   	on_createalways)r4   r3   r   r   perform_management_action)r   r   optionsr   r5   )r7   r6   )r   r   r   r1   )argument_specsupports_check_mode)filenamelevelzStarting ModulezAccount was %s, status_code=%sFOUNDr   rC   r   z
Result=>%sr   r   )r{   rC   r`   )r   rd   rb   basicConfiginfor   rc   r   r   re   rO   rp   rq   r   r   r   	exit_json)fieldsry   r   r   r   r`   r{   rC   r   r2   account_reset	no_resultno_status_codes                r?   mainr     s   <8 
< 	%4OP< 	3NO< 	< 	6f=< 	vN< 	5
<  	T51!<" 	E59#<$ 	u5%<& 	UE2'<( 	"E*!	
)<4 	uetD5<6 	5%4H7<8 	69<: 	 #$1 .4UO!L& (-=! +X6'." )
;<f 	!$*E?9?8H#
g<v 	&E6'Jw<F| TJF}}_%1]]>2&--:X	
 LL"#MM'"E+6v+>(UNKMM(U'[ G'F	-;FN-S*Wfk-8-@*Wfk$,!$v}}'9'9';"<< &.A B ,1LPT!&&(Q 2 ->/-) 	lDJJv$67$0%4U9Px(:6]I~ 	5H$)7)O&&+	5J&):6>)R&&+
WVMrA   __main__)NN)*
__future__r   r   r   r   __metaclass__ANSIBLE_METADATADOCUMENTATIONEXAMPLESRETURNansible.module_utils._textr   ansible.module_utils.basicr   ansible.module_utils.urlsr   +ansible.module_utils.six.moves.urllib.errorr   +ansible.module_utils.six.moves.urllib.parser   *ansible.module_utils.six.moves.http_clientr   rp   rb   objectr   rf   ri   rk   rh   ansible_reference_fieldnamesr@   r   r   r   r   rg   r   r   r   r   __name__r   rA   r?   <module>r     s0  
 C B  k yvENr
j / 4 . A = D  	    #>+ 8$@4,N'!  !>+8"@4(M'  %g/TB
J?D#DS (.4  FG
TK
\tNn zF rA   