
    P                        d Z ddlmZ ddlmZ ddlmZ ddlZddlmZ ddlmZ ddl	m
Z
 dd	lmZ d
Ze
j                  j                  de
j                  j                   diZe
j                  j                  fdZe
j                  j                  fdZe
j                  j                  fdZde
j                  j                   ej*                  d      fdZy)z/Utility functions to call Security Posture API.    )absolute_import)division)unicode_literalsN)apis)waiter)base)	resourcessecurityposturev1alphav1c                 `    t         j                  |       }t        j                  t        |      S N)VERSION_MAPgetr   GetMessagesModuleAPI_NAMErelease_trackapi_versions     =lib/googlecloudsdk/api_lib/scc/remediation_intents/sps_api.pyr   r   $   #    .+			+	66    c                 `    t         j                  |       }t        j                  t        |      S r   )r   r   r   GetClientInstancer   r   s     r   r   r   )   r   r   c                 l    t         j                  j                  | dt        j	                  |            S )a  Operations to Resource used for `waiter.WaitFor`.

  Args:
    operation_id: The operation ID for which resource reference is required.
    release_track: The release track to use for the API version.

  Returns:
    The resource reference for the operation.
  z2securityposture.organizations.locations.operations)
collectionr   )r	   REGISTRYParseRelativeNamer   r   )operation_idr   s     r   GetOperationsRefr    .   s4     
			-	-E//-0 
. 
 r   FiX  )secondsc                     t        |      }|j                  }|j                  }|rt        j                  ||      }nt        j
                  |      }t        j                  || ||j                  dz        }	|	S )a  Waits for an operation to complete.

  Polls the Security Posture Operations service until the operation completes,
  fails, or max_wait_seconds elapses.

  Args:
    operation_ref: A Resource created by GetOperationRef describing the
      Operation.
    message: The message to display to the user while they wait.
    has_result: If True, the function will return the target of the operation
      when it completes. If False, nothing will be returned.
    release_track: The release track to use for the API version.
    max_wait: The time to wait for the operation to succeed before timing out.

  Returns:
    if has_result = True, a RemediationIntent entity.
    Otherwise, None.
  i  )max_wait_ms)r   *organizations_locations_remediationIntents"organizations_locations_operationsr   CloudOperationPollerCloudOperationPollerNoResourcesWaitForr!   )
operation_refmessage
has_resultr   max_waitclientresource_clientoperations_clientpollerresponses
             r   WaitForOperationr2   ?   sz    2 ]+&EE/??((*F
 334EFF^^mW(2B2BT2I( 
/r   )__doc__
__future__r   r   r   datetimegooglecloudsdk.api_lib.utilr   r   googlecloudsdk.callioper   googlecloudsdk.corer	   r   ReleaseTrackALPHAGAr   r   r   r    	timedeltar2    r   r   <module>r>      s    6 &  '  , . ( ) Y$ %)$5$5$;$; 7
 %)$5$5$;$; 7
 261B1B1H1H ( ##))X,'r   