
                         p    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mZ  G d	 d
      Zy)zHModule containing the extended wrappers for Remediation Intents service.    )absolute_import)division)unicode_literals)Any)sps_api)base)errorsc                   t    e Zd ZdZej
                  j                  fdefdZde	fdZ
ddZded	ed
e	de	fdZy)ExtendedSPSClienta  Extended client for the SPS Service (wrappers for specific API calls).

  Attributes:
    release_track: The Gcloud release track to use, like ALPHA, GA.
    org_id: The organization ID for which the API methods are called.
    api_version: The API version to use like v1alpha, main etc.
    client: The client for the SPS Service.
    messages: The messages module for the SPS Service.
  org_idc                     || _         || _        t        j                  j	                  |      | _        t        j                  |      | _        t        j                  |      | _	        y)zInitializes the ExtendedSPSClient.

    Args:
      org_id: The organization ID for which the API methods are called.
      release_track: The release track to use for the API version.
    N)
release_trackr   r   VERSION_MAPgetapi_versionGetClientInstanceclientGetMessagesModulemessages)selfr   r   s      Flib/googlecloudsdk/api_lib/scc/remediation_intents/extended_service.py__init__zExtendedSPSClient.__init__'   sP     'DDK**..}=D++M:DK--m<DM    returnc                 H   | j                   j                  d| j                   dd      }	 | j                  j                  j                  |      }|j                  }|t        |      dk  ry|d   S # t        $ r$}t        j                  dt        |            d}~ww xY w)	aj  Fetches a Remediation Intent resource in ENQUEUED state in given org.

    Returns:
      A Remediation Intent resource in ENQUEUED state for the given org. If no
      such resource is found, returns None.
      Return format is of class (securityposture.messages.RemediationIntent).

    Raises:
      APICallError: An error while calling the SPS Service.
    organizations//locations/globalz#state : REMEDIATION_INTENT_ENQUEUED)parentfilterListN   r   )r   BSecuritypostureOrganizationsLocationsRemediationIntentsListRequestr   r   *organizations_locations_remediationIntentsr    	Exceptionr	   APICallErrorstrremediationIntentslen)r   requestresponseeremediation_intentss        r   !fetch_enqueued_remediation_intentz3ExtendedSPSClient.fetch_enqueued_remediation_intent4   s     mm^^},=>4 _ G0
++
@
@
E
Eg
N  #55"c*=&>&Bq!!  0A//0s   %A4 4	B!=BB!Nc                    | j                   j                  d| j                   d| j                   j                  | j                   j                  j                  j
                              }	 | j                  j                  j                  |      }t        j                  t        j                  |j                        dd      }y
# t        $ r$}t        j                  d	t!        |            d
}~ww xY w)zCreates a Semi Autonomous type Remediation Intent resource.

    Raises:
      APICallError: An error while calling the SPS Service.
    r   r   )workflowType)r   createRemediationIntentRequestr)   z,Waiting for remediation intent to be createdToperation_refmessage
has_resultCreateN)r   DSecuritypostureOrganizationsLocationsRemediationIntentsCreateRequestr   CreateRemediationIntentRequestWorkflowTypeValueValuesEnumWORKFLOW_TYPE_SEMI_AUTONOMOUSr   r#   r6   r   WaitForOperationGetOperationsRefnamer$   r	   r%   r&   )r   r)   	operation_r+   s        r   )create_semi_autonomous_remediation_intentz;ExtendedSPSClient.create_semi_autonomous_remediation_intentO   s     mm``},=>'+}}'S'SEEaa (T (
 a G
2++HHOO P i 
"
"00@@a
  2#a&112s   /AC 	C8C33C8ri_nameupdate_maskremediation_intentc                 V   | j                   j                  |||      }	 | j                  j                  j	                  |      }t        j                  t        j                  |j                        dd      S # t        $ r$}t        j                  dt        |            d}~ww xY w)a  Updates a Remediation Intent resource.

    Args:
      ri_name: The name of the Remediation Intent resource to be updated.
      update_mask: The update mask for the update operation.
      remediation_intent: The updated Remediation Intent resource.

    Returns:
      The updated Remediation Intent resource.
      Return format is of class (securityposture.messages.RemediationIntent).

    Raises:
      APICallError: An error while calling the SPS Service.
    )r=   
updateMaskremediationIntentr1   z,Waiting for remediation intent to be updatedTr2   UpdateN)r   CSecuritypostureOrganizationsLocationsRemediationIntentsPatchRequestr   r#   Patchr   r;   r<   r=   r$   r	   r%   r&   )r   rA   rB   rC   r)   r>   r+   s          r   update_remediation_intentz+ExtendedSPSClient.update_remediation_intentg   s    & mm__, ` G

2++HHNN O i %%00@@ 
  2#a&112s   AA; ;	B(B##B()r   N)__name__
__module____qualname____doc__r   ReleaseTrackALPHAr&   r   r   r-   r@   rJ    r   r   r   r      s^     150A0A0G0G =S =" "620"2"2!$"2 "2 	"2r   r   N)rN   
__future__r   r   r   typingr   .googlecloudsdk.api_lib.scc.remediation_intentsr   googlecloudsdk.callioper   2googlecloudsdk.command_lib.scc.remediation_intentsr	   r   rQ   r   r   <module>rW      s,    O &  '  B ( Em2 m2r   