
    9                     6   S r SSKrSSKJr  SSKJr  SSKJr  SSKJr  SSK	J
r
  SSKJr  \R                  R                  S	0r\R                  R                  4S
 jr\R                  R                  4S jrS rS rS rS rS rS r  SS jr  SS jrS rg)z API lib for Gemini Cloud Assist.    N)apis)waiter)base)cloud_assist)iam_util)	resourcesv1alphac                 V    [         R                  " S[        R                  U 5      5      $ )zReturns the messages module for the given release track.

Args:
  release_track: The release track to use.

Returns:
  The messages module for the given release track.
geminicloudassist)r   GetMessagesModuleVERSION_MAPgetrelease_tracks    6lib/googlecloudsdk/api_lib/gemini_cloud_assist/util.pyr   r      %     
		;??=9
     c                 V    [         R                  " S[        R                  U 5      5      $ )zReturns the client instance for the given release track.

Args:
  release_track: The release track to use.

Returns:
  The client instance for the given release track.
r   )r   GetClientInstancer   r   r   s    r   r   r   ,   r   r   c                 z    [        5       n[        5       nUR                  R                  UR	                  U S95      $ )zReturns the investigation for the given investigation resource.

Args:
  investigations_resource_name: The name of the investigation resource.

Returns:
  The investigation for the given investigation resource.
name)r   r   !projects_locations_investigationsGet:GeminicloudassistProjectsLocationsInvestigationsGetRequestinvestigations_resource_nameclientmessagess      r   GetInvestigationr    :   sD     & (		1	1	5	5II+ J 
 r   c                 \   [        5       n[        5       nU R                  5       R                  S5      S   nUR	                  0 S9n	US:w  a  U R                  5       U	l        OSnU	R                  R                  R                  UR                  R                  R                  SUR                  SU R                  5       R                  5       R                  5       R                  S5      S   UR                  R                  R                  UR                  R                  R                   S9S95        U(       a  Xl        U(       d  U(       d  U(       d  U(       Ga  UR                  S	S
UR                  R                  R$                  UR                  R                  R                   S9n
U(       a  X*l        U(       aM  U(       aF  U
R(                  R                  UR+                  UR-                  5       UR-                  5       S95        OU(       a7  U
R(                  R                  UR+                  UR-                  5       S95        OU(       a7  U
R(                  R                  UR+                  UR-                  5       S95        O[.        R.                  R1                  [.        R2                  R4                  5      [.        R6                  " SS9-
  nU
R(                  R                  UR+                  UR-                  5       S95        U(       a  XZl        U	R                  R                  R                  UR                  R                  R                  U
R:                  U
S95        UR<                  R?                  URA                  U R                  5       R                  5       UU	S95      $ )a  Creates the investigation for the given investigation resource.

Args:
  investigation_resource: The investigation resource to create.
  title: The title of the investigation.
  issue: The issue of the investigation.
  start_time: The start time of the investigation.
  end_time: The end time of the investigation.
  relevant_resources: The resources of the investigation.

Returns:
  The created investigation.
/observations-Nuser.projectidtextobservationTypeobserverTypekeyvalueuser.input.logUser Provided Issuer)   titler+   r,   	startTimeendTime)r5   )r6      )minutes)parentinvestigationIdinvestigation)!r   r   RelativeNamesplitInvestigationr   r%   additionalPropertiesappendObservationsValueAdditionalPropertyObservationParentObservationTypeValueValuesEnum!OBSERVATION_TYPE_STRUCTURED_INPUTObserverTypeValueValuesEnumOBSERVER_TYPE_USERr3   OBSERVATION_TYPE_CLOUD_LOGr*   timeIntervalsInterval	isoformatdatetimenowtimezoneutc	timedeltarelevantResourcesr)   r   Create=GeminicloudassistProjectsLocationsInvestigationsCreateRequest)investigation_resourcer3   issue
start_timeend_timerelevant_resourcesr   r   investigation_idr;   observationhalf_an_hour_agos               r   CreateInvestigationr]   L   s!   * & (+88:@@EbI((b(9-/<<>M1188..AA$$)002vx|~uSz" '22QQss#//KK^^ %  B  
jH(:&&# ,,KKff))EEXX	 ' K h&&


",,.8J8J8L  
 
&&


j&:&:&<

= 
&&


H$6$6$8

9 "**..







R
() &&


&6&@&@&B

C &8#33::00CC 	D 	
 
	1	1	8	8LL'..0==?*% M 
 r   c                    Su  p4U(       aK  [        UR                  5      S:  a2  UR                  S   R                  nUR                  S   R                  nU (       a0  U [        R                  R
                  :w  a  U R                  5       OSnU(       a0  U[        R                  R                  :w  a  UR                  5       OSn[        5       R                  X4S9$ )a  Calculates the time interval for the given start and end times.

Args:
  start_time: The start time of the investigation.
  end_time: The end time of the investigation.
  observation: The observation to get the existing time interval from.

Returns:
  The calculated time interval.
)NN   r   Nr4   )
lenrJ   r5   r6   rM   minrL   maxr   rK   )rW   rX   r[   start_time_strend_time_strs        r   CalculateTimeIntervalre      s     ",.S223q8 ..q1;;N,,Q/77L **... 		   x((,,, 		  
		%	% 
& 
 r   c                    [        U R                  5       5      n[        5       n[        5       nUR	                  0 S9n	/ n
U R                  5       U	l        U	R                  R                  R                  UR                  R                  R                  SUR                  SU R                  5       R                  5       R                  5       R                  S5      S   UR                  R                  R                  UR                  R                   R"                  S9S95        U
R                  S5        Ub  U
R                  S	5        Xl        Uc  U(       d  U(       d  UGb  UR                  S
SUR                  R                  R&                  UR                  R                   R"                  S9nU
R                  S5        U
R                  S5        U
R                  S5        U
R                  S5        Ub  U
R                  S5        X+l        U(       d  U(       at  U
R                  S5        SnUR                  R                   H!  nUR*                  S
:X  d  M  UR,                  n  O   UR.                  R                  [1        UUU5      5        Ub  U
R                  S5        X[l        U	R                  R                  R                  UR                  R                  R                  UR4                  US95        UR6                  R9                  UR;                  U R                  5       SR=                  U
5      U	S95      $ )a/  Updates the investigation for the given investigation resource.

Args:
  investigation_resource: The investigation resource to create.
  title: The title of the investigation. Pass an empty string to clear.
  issue: The issue of the investigation.
  start_time: The start time of the investigation. Pass datetime.datetime.min
    to clear.
  end_time: The end time of the investigation. Pass datetime.datetime.max to
    clear.
  relevant_resources: The resources of the investigation. Pass an empty array
    to clear.

Returns:
  The updated investigation.
r$   r'   r"   r#   r(   r-   zobservations.`user.project`Nr3   r0   r1   r2   z observations.`user.input.log`.idz#observations.`user.input.log`.titlez-observations.`user.input.log`.observationTypez*observations.`user.input.log`.observerTypez"observations.`user.input.log`.textz+observations.`user.input.log`.timeIntervalsz/observations.`user.input.log`.relevantResources,)r   
updateMaskr;   )r    r<   r   r   r>   r   r%   r?   r@   rA   rB   rC   rD   r=   rE   rF   rG   rH   r3   rI   r*   r.   r/   rJ   re   rR   r)   r   Patch<GeminicloudassistProjectsLocationsInvestigationsPatchRequestjoin)rU   r3   rV   rW   rX   rY   old_investigationr   r   r;   maskr[   old_observationobss                 r   UpdateInvestigationrp      s   4 ''='J'J'LM& (((b(9-	$-::<-1188..AA$$)002vx|~uSz" '22QQss#//KK^^ %  B  +++,
KK 				'&&# ,,KKff))EEXX	 ' K 	KK23KK56KK?@KK<=
kk67X
kk?@ o"//DD#77&&II/
 E
 &&
 %
kkCD&8#33::00CC 	D 	
 
	1	1	7	7KK%224XXd^% L 
 r   c                    [        5       n[        5       nUR                  R                  UR	                  U S95      n[
        R                  " UR                  5      n[        R                  R                  UR                  SS9n[
        R                  " XESS9  [        R                  " [        U R!                  S5      S   5      5      $ )zRuns the investigation revision for the given revision name.

Args:
  revision_name: The name of the investigation revision.

Returns:
  The response of running the investigation revision.
r   z/geminicloudassist.projects.locations.operations)
collectionzRunning investigation)messagez/revisions/r   )r   r   +projects_locations_investigations_revisionsRunCGeminicloudassistProjectsLocationsInvestigationsRevisionsRunRequestr   CloudOperationPollerNoResourcesprojects_locations_operationsr   REGISTRYParser   WaitForr   ReformatInvestigationr    r=   )revision_namer   r   	operationpolleroperation_refs         r    RunInvestigationRevisionBlockingr   E  s     & (@@DDRR S )
 11**& $$**nnB + - 	..0GH		+	+}**=9!<=
 r   c                 z    [        5       n[        5       nUR                  R                  UR	                  U S95      $ )zReturns the IAM policy for the given investigation resource.

Args:
  investigations_resource_name: The name of the investigation resource.

Returns:
  The IAM policy for the given investigation resource.
)resource)r   r   r   GetIamPolicyCGeminicloudassistProjectsLocationsInvestigationsGetIamPolicyRequestr   s      r   GetInvestigationIamPolicyr   b  sD     & (		1	1	>	>RR/ S 
 r   c           	          [        5       n[        5       n[        U 5      n[        R                  " UR
                  XQU5        UR                  R                  UR                  U UR                  US9S95      $ )a,  Adds an IAM policy binding to the given investigation resource.

Args:
  investigations_resource_name: The name of the investigation resource.
  member: The member to add to the binding.
  role: The role to add to the binding.

Returns:
  The updated IAM policy for the given investigation resource.
policyr   setIamPolicyRequest)
r   r   r   r   AddBindingToIamPolicyBindingr   SetIamPolicyCGeminicloudassistProjectsLocationsInvestigationsSetIamPolicyRequestSetIamPolicyRequestr   memberroler   r   r   s         r    AddInvestigationIamPolicyBindingr   t  sx     & ($%AB&
  !1!164H		1	1	>	>RR/&::&:I S 
 r   c           	          [        5       n[        5       n[        U 5      n[        R                  " XQU5        UR
                  R                  UR                  U UR                  US9S95      $ )a;  Removes an IAM policy binding from the given investigation resource.

Args:
  investigations_resource_name: The name of the investigation resource.
  member: The member to remove from the binding.
  role: The role to remove from the binding.

Returns:
  The updated IAM policy for the given investigation resource.
r   r   )	r   r   r   r   RemoveBindingFromIamPolicyr   r   r   r   r   s         r   #RemoveInvestigationIamPolicyBindingr     sp     & ($%AB&
%%fd;		1	1	>	>RR/&::&:I S 
 r   c           
         [        5       n[        5       n[        R                  " XR                  5      u  pEUR
                  R                  UR                  U UR                  XES9S95      n[        R                  " U S5        U$ )zSets the IAM policy for the given investigation resource.

Args:
  investigations_resource_name: The name of the investigation resource.
  policy_file: The path to the policy file.

Returns:
  The updated IAM policy for the given investigation resource.
)r   rh   r   r;   )
r   r   r   ParseYamlOrJsonPolicyFilePolicyr   r   r   r   LogSetIamPolicy)r   policy_filer   r   r   update_maskresults          r   SetInvestigationIamPolicyr     s     & ( ::??& 33@@RR/&:: ;  S & 7I	-r   )allUsersz+roles/geminicloudassist.investigationViewer)__doc__rM   googlecloudsdk.api_lib.utilr   r   googlecloudsdk.callioper   !googlecloudsdk.command_lib.geminir   googlecloudsdk.command_lib.iamr   googlecloudsdk.corer   ReleaseTrackALPHAr   r   r   r    r]   re   rp   r   r   r   r   r    r   r   <module>r      s     '  , . ( : 3 )   &&	2 %)$5$5$;$;  %)$5$5$;$; $`F!Hod:( 	6: 	66r   