
    6                        S r SSKrSSKJrJrJrJr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  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  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'  Sr(S/r)Sr*\RV                  RX                  S0r- " S S\	R\                  5      r/S r0S r1\RV                  RX                  4S jr2 " S S\35      r4g)z@Common utility functions for Developer Connect Insights Configs.    N)AnyDictListSetTuple)
exceptions)projects_api)common)discover_apphub)discover_artifact_configs)folders)serviceusage)apis)waiter)basename)iam_util)util)log)	resources)
console_io)z$roles/developerconnect.insightsAgentcloudruni N  v1c                       \ rS rSrSrSrg)!InsightsConfigInitializationError3   z9Error initializing the Developer Connect Insights Config. N)__name__
__module____qualname____firstlineno____doc____static_attributes__r       Plib/googlecloudsdk/api_lib/developer_connect/insights_configs/insights_config.pyr   r   3   s    Ar%   r   c                 8    [         R                  " X5      nUS   $ )aL  Gets the P4SA for the given project and location.

If the P4SA does not exist for this project, it will be created. Otherwise,
the email address of the existing P4SA will be returned.

Args:
  project: The project to get the P4SA for.
  service_name: The service name to get the P4SA for.

Returns:
  The email address of the P4SA.
email)r   GenerateServiceIdentity)projectservice_nameresponses      r&   	_get_p4sar-   7   s     11'H(	'	r%   c                 \    U [         R                  :H  =(       d    U [         R                  :H  $ )a  Whether to retry the request when receiving errors.

Args:
  exc_type: type of the raised exception.
  unused_exc_value: the instance of the raise the exception.
  unused_exc_traceback: Traceback, traceback encapsulating the call stack at
    the point where the exception occurred.
  unused_state: RetryerState, state of the retryer.

Returns:
  True if exception and is due to NOT_FOUND or INVALID_ARGUMENT.
)apitools_exceptionsHttpBadRequestErrorHttpNotFoundError)exc_typeunused_exc_valueunused_exc_tracebackunused_states       r&   _should_retry_http_errorr6   H   s,     )==
= <
);;
;=r%   c                 Z    [         R                  U 5      n[        R                  " SU5      $ )Ndeveloperconnect)VERSION_MAPgetr   GetMessagesModule)release_trackapi_versions     r&   get_messages_moduler>   \   s$    .+			 2K	@@r%   c            
          \ rS rSrSrS rS rS\" 5       R                  4S jr	S\" 5       R                  4S jr
S\\\" 5       R                  4   S	\\\4   S\\\" 5       R                  4   4S
 jrS rS\\   S\\   S\\\" 5       R                  4   4S jrS\S\\\" 5       R                  4   4S jrS\\   S\\\" 5       R                  4   S\\\" 5       R                  4   4S jrS\\\" 5       R                  4   S\\\" 5       R                  4   S\\\   \\" 5       R                     4   4S jrS\S\4S jrS rS rS rS rS rS rS rS r S  r!S! r"S" r# S,S# jr$S$ r%S% r&S&\'RP                  " S'S(94S) jr)S*r*g+)-InsightsConfigClienta   z2Wrapper for Developer Connect Insights API client.c                    [         R                  U5      nXl        [        R                  " SU5      U l        [        R                  " 5       U l        U R                  R                  SS5        [        U5      U l        X l        S U l        g )Nr8   r   )r9   r:   r<   r   GetClientInstanceclientr   Registry_resource_parserRegisterApiByNamer>   messagesr=   
p4sa_email)selfr<   r=   s      r&   __init__InsightsConfigClient.__init__d   sl    //-0K&(();[IDK%..0D++,>E'6DM"DOr%   c           
      N   U(       a  U R                  XU5      nOU R                  XU5      n U R                  R                  R	                  US9$ ! [
        R                   a?    [        R                  " SUR                   SUR                   SUR                   S35      ef = f)zCreates the insight config.requestInsights Config [z] already exists in project [] location [].)%create_apphub_insights_config_request,create_project_scope_insights_config_requestrD   "projects_locations_insightsConfigsCreater/   HttpConflictErrorr   ErrorinsightsConfigsId
projectsIdlocationsId)rJ   insight_config_refapp_hubtarget_projectsuser_artifact_configscreate_requests         r&   createInsightsConfigClient.createn   s     AA
'<n HH
/Dn	[[;;BB  C   00 0BBC D!!3!>!> ? @!--.b2 s   "A AB$returnc           
      .   [         R                  " U5      nUR                  UR                  :g  n[	        UR
                  5      UR                  :g  nU(       a-  U(       a&  [        SUR                   SUR                   S35      eU R                  X5      u  pxn	U R                  X5      n
[         R                  " U5      nU R                  X5      nU R                  X5      u  pUR                  U5        U(       a$  U R                  UR                  [        U5      SS9  U R                  R!                  UR#                  5       R%                  5       UR&                  U R                  R)                  UR%                  5       UR+                  5       US9S9$ )zACreates the insight config request for app hub application scope.z'Mismatch: App Hub application project [zM] must be the same as the project where the insight config is being created [rR   Fmanagement_project)r   appHubApplicationartifactConfigsparentinsightsConfigIdinsightsConfig)r   parse_app_hub_application_uri
project_idrZ   strproject_numberr   .find_apphub_resources_and_grant_sa_permissionsget_artifact_configs_from_caisparse_artifact_configsmerge_artifact_configsbuild_artifact_configsupdateinit_service_accountsortedrH   =DeveloperconnectProjectsLocationsInsightsConfigsCreateRequestParentRelativeNamerY   InsightsConfigresource_name)rJ   r\   r]   r_   app_hub_applicationis_project_id_mismatchis_project_num_mismatchdependent_projectsgke_workloadscloud_run_servicescais_artifact_configs_dictuser_artifact_configs_dictmerged_artifact_configs_dictartifact_projectsartifact_configss                  r&   rS   :InsightsConfigClient.create_apphub_insights_config_request   s    <<WE 	&&*<*G*GG  	../3E3P3PP  "9-"--. /!,,-R1  	;;	
 :'9
 "&!D!D" "&!<!<" $(#>#>"$  +/*E*E$+' /0


'
'
#
$"    ==VV!((*779+==}}33#0021??A, 4 
 W  r%   c                    [         R                  " U5      n[        U5      n0 nU H%  nU R                  U5      nUR	                  U5        M'     [         R
                  " U5      n	U R                  Xi5      n
U R                  X5      u  pUR	                  U5        U(       a$  U R                  UR                  [        U5      SS9  U R                  R                  UR                  5       R                  5       UR                  U R                  R!                  UR                  5       U R                  R#                  US9US9S9$ )z5Creates the insight config request for project scope.Fre   )
projectIds)r   projectsrh   ri   )r   parse_target_projectsset*get_artifact_configs_from_cais_for_projectrv   rs   rt   ru   rw   rZ   rx   rH   ry   rz   r{   rY   r|   Projects)rJ   r\   r^   r_   r   r   r   r*   cais_artifactsr   r   r   r   s                r&   rT   AInsightsConfigClient.create_project_scope_insights_config_request   sE    ))/:HX!#FFwOn ''7  "&!<!<" $(#>#>"$  +/*E*E$+' /0


'
'
#
$"    ==VV!((*779+==}}33#002]]++x+@, 4 
 W  r%   artifact_configs_dictuser_provided_artifact_configsc                     0 nU(       a  UR                  5        H	  u  pEXSU'   M     U(       d  U$ UR                  5        H8  u  pFU R                  R                  UU R                  R                  US9S9X4'   M:     U$ )zMerges artifact configs from CAIS and user provided configs user provided configs will overwrite configs extracted from CAIS if URIs match.
    	projectIdurigoogleArtifactAnalysis)itemsrH   ArtifactConfigGoogleArtifactAnalysis)rJ   r   r   r   r   
config_msgbuild_projects          r&   rt   +InsightsConfigClient.merge_artifact_configs   s     	 ! 288:/#,6S) ; *))<BBD*.--*F*F!%!E!E% "F " +G +"' E ('r%   c                     U R                  UR                  5       5      u  p4n[        R                  " UR                  5      (       d  X4U4$ U R                  X5        [        5       XE4$ )a  Finds the GKE workloads and Cloud Run services and grants SA permissions at the folder level for management project or returns the dependent projects for non-management projects.

Args:
  insight_config_ref: The insight config reference.
  app_hub_application: The app hub application.

Returns:
  A tuple of dependent projects(based on if it is a management project or
  not), gke workloads and cloud run services.
)get_runtimesr}   r   is_management_projectrn   assign_management_permissionsr   )rJ   r\   r~   r   r   r   s         r&   rq   CInsightsConfigClient.find_apphub_resources_and_grant_sa_permissions  sl     =A<M<M))+=9'9 %%&9&D&DEE0BBB 	&&'9O5-33r%   r   r   c                 ^   0 nU HO  n[         R                  " U5      n[         R                  " U5      nUR                  U R	                  Xc5      5        MQ     U HO  n[         R
                  " U5      n[         R                  " U5      nUR                  U R	                  Xc5      5        MQ     U$ )zQueries CAIS for artifacts associated with the gke workloads in the resources scope.

Args:
  gke_workloads: A list of GKE workloads.
  cloud_run_services: A list of Cloud Run services.

Returns:
  A dict of artifact configs IC type.
)discover_artifactsquery_cais_for_gke_assets!get_artifact_uris_from_gke_assetsrv   -update_artifact_config_dict_from_artifact_uri!query_cais_for_cloud_run_services'get_artifact_uris_from_cloud_run_assets)rJ   r   r   r   gke_workloadassetsartifact_uriscloud_run_services           r&   rr   3InsightsConfigClient.get_artifact_configs_from_cais0  s     NP%!;;LIf(JJ
m ""

<
< & 0!CC
f 
D
DV
L  ""

<
< 0 ! r%   r*   c                 :   0 n[         R                  " U5      n[         R                  " U5      nUR                  U R	                  XB5      5        [         R
                  " U5      n[         R                  " U5      nUR                  U R	                  Xb5      5        U$ )zQueries CAIS for artifacts associated with the GCP Project.

Args:
  project: A GCP Project.

Returns:
  A dict of artifact configs IC type.
)r   $query_cais_for_gke_assets_in_projectr   rv   r   ,query_cais_for_cloud_run_services_in_projectr   )rJ   r*   r   
gke_assetsgke_artifact_uriscloud_run_assetscloud_run_artifact_uriss          r&   r   ?InsightsConfigClient.get_artifact_configs_from_cais_for_projectW  s     NP $HHJ +LL   ::	
 	GGP  	BB	
 
   ::#	

 ! r%   r   c                    U H  n[         R                  " U5      nU(       d  M"  UR                  [        ;   a  M8  UR                  nU R
                  R                  UU R
                  R                  UR                  S9S9X%'   M     U$ )zUpdates the artifact configs dict with the artifact uris.

Args:
  artifact_uris: The artifact uris.
  artifact_configs_dict: The artifact configs dict.

Returns:
  The artifact configs dict.
r   r   )r   validate_artifact_urirn   _EXCLUDED_PROJECTSbase_urirH   r   r   )rJ   r   r   artifactvalidated_artifact_urir   s         r&   r   BInsightsConfigClient.update_artifact_config_dict_from_artifact_uri  s     "#99(C#		*	*.@	@'00h(,(D(D!%!E!E.99 "F " )E )% " ! r%   r   r   c                    [        5       nU(       d#  [        R                  R                  S5        U/ 4$ U(       a  UR	                  5        H  nUR
                  R                  n[        R                  R                  SU SUR                   S35        [        R                  " 5       =(       a    [        R                  " SSS9nU(       a  U R                  UR                  5      nU R                  R                  UR                  U R                  R                  US9S	9XR                  '   M     [        UR	                  5       5      nUR!                  S
 U 5       5        X74$ )a]  Builds the artifact configs and returns the dependent projects and artifact configs.

Args:
  merged_artifact_configs_dict: A combined dict of artifact configs IC type
    from CAIS and user provided configs.
  cais_artifact_configs_dict: A dict of artifact configs IC type from CAIS.

Returns:
  A tuple of dependent projects and artifact configs.
z*No existing artifact configurations found.z
Build project [z?] will be used to extract provenance information for artifact []z+Would you like to change the build project?F)prompt_stringdefaultr   r   c              3   N   #    U  H  nUR                   R                  v   M     g 7f)N)r   r   ).0r   s     r&   	<genexpr>>InsightsConfigClient.build_artifact_configs.<locals>.<genexpr>  s#      (H 	''11(s   #%)r   r   statusPrintvaluesr   r   r   r   	CanPromptPromptContinueprompt_for_build_projectrH   r   r   listrv   )rJ   r   r   r   artifact_configr   change_build_projectr   s           r&   ru   +InsightsConfigClient.build_artifact_configs  s\   & $'5'	jjCD## "9@@B/'>>HH

   $$%Q(	
   " ))K 	  778K8KL- MM((#'''+}}'K'K+ (L ( )  	%%8%89% C8 8??AB  (  //r%   artifact_uric                 ,   SnSnU(       dE  [         R                  " SU S35      nU(       d  M*   [        R                  " U5        SnU(       d  ME  U$ ! [        R
                   a1    [        R                  R                  SR                  U5      5         NO[        R                   a1    [        R                  R                  SR                  U5      5         N[        R                   a&  n[        R                  " SU SU 35         SnANSnAff = f)	z'Prompts the user for the build project.FNz2Please enter the build project for your artifact [z]: TzPermission denied when checking build project [{}]. Please ensure your account has necessary permissions or that the project exists.z^Invalid build project ID [{}]. Please ensure it is a valid project ID (e.g., "my-project-123")z Error validating build project [)r   PromptResponser   validate_projectr/   HttpForbiddenErrorr   r   r   formatr0   r   rX   warning)rJ   r   foundr   es        r&   r   -InsightsConfigClient.prompt_for_build_project  s    EM //nC!m Nm, e2  !33 


* VM"		
 !44 


3396-3H	
  N6}oSLMMNs%   A ADADD-DDc                    [        5       n/ n[        R                  " 5       nUR                  SUS9nU H  nUR                  (       a  UR                  R
                  (       d  M1  [        R                  " UR                  R
                  5      nU(       d  Md  UR                  [        R                  " UR                  R                  R                  5      R                  5        UR                  U5        M     X#4$ )zGets the runtime configs.

Args:
  app_hub: The app hub application.

Returns:
  A tuple of gke runtime configs projects and gke workloads associated with
  the app hub application.
d   	page_sizerj   )r   r   DiscoveredApphubClientlist_workloadsworkloadReferencer   r   parse_gke_deployment_uriaddProjectgke_namespacegke_clusterr*   rn   append)rJ   r]   runtime_configs_projectsr   rD   	workloadsworkloadr   s           r&   get_gke_workloads_runtime.InsightsConfigClient.get_gke_workloads_runtime  s      #uM335F%% & I
  ''x/I/I/M/M22

$
$
(
(l  ""
,,((44<<J
 <(% & $22r%   c                    [        5       n/ n[        R                  " 5       nUR                  SUS9nU H  nUR                  (       a  UR                  R
                  (       d  M1  [        R                  " UR                  R
                  5      nU(       d  Md  UR                  UR                  5        UR                  U5        M     X#4$ )zGets the cloud run services.

Args:
  app_hub: The app hub application.

Returns:
  A tuple of cloud run runtime configs projects and cloud run services
  associated with the app hub application.
r   r   )r   r   r   list_servicesserviceReferencer   r   parse_cloud_run_service_urir   rn   r   )rJ   r]   r   r   rD   servicesservicer   s           r&   get_cloud_run_services_runtime3InsightsConfigClient.get_cloud_run_services_runtime&  s      #u335F## $ H  %%W-E-E-I-I::

"
"
&
&  ""#4#?#?@ 12  $77r%   c                     U(       d  [        5       / / 4$ U R                  U5      u  p#U R                  U5      u  pEUnUR                  U5        XcU4$ )zGets the runtime configs.

Args:
  app_hub: The app hub application.

Returns:
  A tuple of runtime configs projects, gke workloads, and cloud run services
  associated with the app hub application.
)r   r   r   rv   )rJ   r]   gke_runtime_configs_projectsr   "cloud_run_runtime_configs_projectsr   r   s          r&   r   !InsightsConfigClient.get_runtimesH  sf     UB]&&w/ 0  	++G4 ;&  <##$FG#4FFFr%   c                     [         R                  " [        R                  " UR                  5      5      R
                  R                  nU/nU R                  UR                  USS9  g)zBAssigns permissions to at the folder level for management project.Tre   N)	r	   Getprojects_utilParseProjectrn   rj   idrw   rZ   )rJ   r\   r]   folder_numberdependent_folders        r&   r   2InsightsConfigClient.assign_management_permissions^  se     !$$""7#5#56fRR  &%%  
 r%   c                 J   U(       a  U(       a  U R                  XU5      nOU R                  U5      n[        R                  " [        R                  " UR
                  5      5      (       d-  U R                  U5      nU R                  UR                  USS9  Oz[        R                  " [        R                  " [        R                  " UR
                  5      5      5      R                  R                  nU/nU R                  UR                  USS9  U R                  U5      n	U(       a/  U R                   R"                  R$                  R&                  U	l        U R                   R+                  U	UR-                  5       S9n
U R.                  R0                  R3                  U
S9$ )zUpdates the insight config.Fre   T)rl   r   rN   )handle_artifact_configsget_existing_insights_configr   r   extract_projectrg   get_dependent_projectsrw   rZ   r	   r   r   r   rj   r   insights_config_message_typerH   r|   StateValueValuesEnumPENDINGstate<DeveloperconnectProjectsLocationsInsightsConfigsPatchRequestr{   rD   rU   Patch)rJ   r\   	discoveryr   r   old_insights_configr   r   r  new_insights_configupdate_requests              r&   rv   InsightsConfigClient.updatel  s     88
M !==
 %%0BBC   667JK


'
'
"    #&&

$
$""#6#H#HI 	rr	 
 (


'
'
!    ;;<OP
--
&
&
;
;
C
C  ]]__*,,. ` N ;;99?? @  r%   c           	      T   [         R                  " U5      nU(       d  [        R                  " SU S35      e [         R                  " U5        U R                  U5      n[        UR                  5       HX  u  pxUR                  U:X  d  M  U R                  R!                  UU R                  R#                  US9S9n	XR                  U'   Us  $    UR                  R%                  U R                  R!                  UU R                  R#                  US9S95        U$ ! [
        R                   a:    [        R                  " SR                  U[        R                  " 5       5      5      e[
        R                   a*  n[        R                  " SR                  X55      5      eSnAff = f)zHandles the artifact config.zInvalid artifact URI: z`. Artifact URI must be in the format {location}-docker.pkg.dev/{project}/{repository}/{package}.zPermission denied when checking build project [{}]. Please ensure the account [{}] has necessary permissions (e.g., resourcemanager.projects.get) or that the project exists.z{Invalid build project ID [{}]: {}. Please ensure it is a valid project ID (e.g., "my-project-123") and not an artifact URI.Nr   r   )r   r   r   rX   r   r/   r   r   r   GetAuthenticatedAccountr0   r  	enumeraterh   r   rH   r   r   r   )
rJ   insights_refr   r   artifact_projectr   icindexr   updated_artifacts
             r&   r  ,InsightsConfigClient.handle_artifact_configs  s   11,?"<. 1H H 
M*" 
	*	*<	8B"+B,>,>"?				,==77#'==#G#G' $H $ 8 
 %55!	 #@ $$#'==#G#G' $H $ 	% 	
 IG 11 G 6-!A!A!CD	  22 J6-# s   D A F'=%F""F'c                 ^    U R                   R                  UR                  UR                  S9$ )z+Creates a new insights config message type.)r  rh   )rH   r|   r  rh   )rJ   current_insights_configs     r&   r  1InsightsConfigClient.insights_config_message_type  s0    ==''%++/?? (  r%   c           
      @    U R                   R                  R                  U R                  R	                  UR                  5       S9S9$ ! [        R                   a?    [        R                  " SUR                   SUR                   SUR                   S35      ef = f)zGets the insight config.r   rN   rP   z] not found in project [rQ   rR   )rD   rU   r   rH   :DeveloperconnectProjectsLocationsInsightsConfigsGetRequestr{   r/   r1   r   rX   rY   rZ   r[   )rJ   r\   s     r&   r  1InsightsConfigClient.get_existing_insights_config  s    [[;;??--ZZ%224 [  @  
 00 0BBC D,778 9!--.b2 s   AA
 
ABc                    [        5       nUR                  [        R                  " UR                  5      5        UR
                   H  nUR                  (       aB  [        R                  " UR                  5      nU(       a  UR                  UR                  5        UR                  (       d  Mi  UR                  R                  (       d  M  UR                  UR                  R                  5        M     UR                   HE  nUR                  (       d  M  UR                  [        R                  " UR                  5      5        MG     [        [        U5      5      $ )z.Gets the P4SA projects for the insight config.)r   r   r   r  rg   rh   r   r   rn   r   r   runtimeConfigsrx   r   )rJ   insights_configr   r   r   runtime_configs         r&   r  +InsightsConfigClient.get_dependent_projects  s    uHLL%%o&G&GHI*::			11/2E2EF
,,|..
/

0
0
044>>>_;;EEF ; *88				T)).*<*<=> 9 $x.!!r%   c                    [         R                  " U R                  5      nU R                  c  [	        X5      U l        U R                  (       d  [        SR                  U5      5      eU(       aG  [        U5      S:X  a!  U R                  U R                  US   S5        g[        R                  " S5        g[        U5       H6  n[        R                  " U5      nU R                  U R                  US5        M8     g)a  Get the Developer Connect P4SA, and grant IAM roles to it.

1) First, get the P4SA for the project.
Args:
  p4sa_project: The project to get the P4SA for.
  dependent_resources: The resources to grant the P4SA permissions to.
  management_project: Whether the resource is a management project.

2) Then grant necessary roles needed to the P4SA for updating an insight
  config.

3) If the app hub application is a management project, grant the P4SA
  permissions on the folder.

4) If the app hub application is a non management project, grant the P4SA
  permissions on the dependent projects.

Raises:
  InsightsConfigInitializationError: P4SA failed to be created.
Nz"Failed to get P4SA for project {}.   r   Tz\Could not find folder number for the management project.Skipping permissions checks/binding.F)r
   GetApiServiceNamer=   rI   r-   r   r   lenbind_roles_to_service_accountr   r   rx   r   r   )rJ   p4sa_projectdependent_resourcesrf   r+   r*   project_refs          r&   rw   )InsightsConfigClient.init_service_account  s    . ++D,<,<=L!,=do??-
.
5
5l
C  	 	!Q	&**OO03T	
 	3	
 /0'#009**4??KO 1r%   c           	      D    [          H  nU R                  UUUUSS9  M     g)zBinds roles to the provided service account.

Args:
  sa_email: str, the service account to bind roles to.
  resource_ref: str, the resource to bind roles to.
  management_project: bool, whether the resource is a management project.
z8required to update the Developer Connect Insights Config)reasonN)_ROLESprompt_to_bind_role_if_missing)rJ   sa_emailresource_refrf   roles        r&   r+  2InsightsConfigClient.bind_roles_to_service_account+  s0     
))



K *  r%   c                 v   SR                  U5      n U(       a  [        R                  " U5      nO[        R                  " U5      nU R	                  XqU5      (       a  g[
        R                  R                  SR                  XX%5      5        [        R                  " 5       =(       a$    [        R                  " SR                  X1U5      S9nU(       d  [
        R                  " S5        gU(       aN  [        R                  " 5       n	[        R                  " U	R                  XvU5        [        R                   " X'5        O[        R"                  " X&U5        [
        R                  R                  SR                  X1U5      5        g! [$        R&                   a    [
        R                  " SUUU5         gf = f)	a  Prompts to bind the role to the service account in project level if missing.

If the console cannot prompt, a warning is logged instead.

Args:
  sa_email: The service account email to bind the role to.
  resource_ref: The resource to bind the role to.
  role: The role to bind if missing.
  management_project: Whether the resource is a management project.
  reason: Extra information to print explaining why the binding is
    necessary.
serviceAccount:{}NzB
Service account [{}] is missing the role [{}] in project [{}].
{}z<
Bind the role [{}] to service account [{}] in project [{}]?)r   z0Manual binding of above role will be necessary.
zHSuccessfully bound the role [{}] to service account [{}] in project [{}]zYour account does not have permission to check or bind IAM policies to resource [%s]. If the deployment fails, ensure [%s] has the role [%s] before retrying.)r   r   GetIamPolicyr	   has_role_bindingr   r   r   r   r   r   r   FoldersMessagesr   AddBindingToIamPolicyBindingSetIamPolicyAddIamPolicyBindingr/   r   )
rJ   r4  r5  r6  rf   r1  member
iam_policybindrH   s
             r&   r3  3InsightsConfigClient.prompt_to_bind_role_if_missing>  s[    !''1F.	)),7
!..|<
			zT	:	:	jj
P6(,7
 !!# 
(A(AMvdl3)d GH	**,&&j$	
 	\6((tD	jj&6 11 
	kk4 

	
s    AF BF ,BF -F87F8c                 F   ^^ [        UU4S jUR                   5       5      $ )zReturns whether the given SA has the given role bound in given policy.

Args:
  iam_policy: The IAM policy to check.
  sa_email: The service account to check.
  role: The role to check for.
c              3      >#    U  H9  nS R                  T5      UR                  ;   =(       a    UR                  T:H  v   M;     g7f)r9  N)r   membersr6  )r   br6  r4  s     r&   r   8InsightsConfigClient.has_role_binding.<locals>.<genexpr>  s<      $A 	""8,		9LaffnL$s   AA)anybindings)rJ   rB  r4  r6  s     ``r&   r;  %InsightsConfigClient.has_role_binding~  s%      $$  r%   c                 N    U R                   R                  UR                  S5      $ )zKConverts an operation to a resource that can be used with `waiter.WaitFor`.z1securesourcemanager.projects.locations.operations)rF   ParseRelativeNamer   )rJ   	operations     r&   get_operation_ref&InsightsConfigClient.get_operation_ref  s'      22KM Mr%   TiX  )secondsc                 (   U(       a@  [         R                  " U R                  R                  U R                  R                  5      nO*[         R
                  " U R                  R                  5      n[         R                  " XQX$R                  S-  S9$ )a  Waits for a Developer Connect operation to complete.

  Polls the Developer Connect Insights Operation service until the operation
  completes, fails, or max_wait_seconds elapses.

Args:
  operation_ref: a resource reference created by GetOperationRef describing
    the operation.
  message: a message to display to the user while they wait.
  has_result: If True, the function will return the target of the operation
    (i.e. the InsightConfig) when it completes. If False, nothing will be
    returned (useful for Delete operations).
  max_wait: The time to wait for the operation to complete before returning.

Returns:
  A resource reference to the target of the operation if has_result is True,
  otherwise None.
i  )max_wait_ms)r   CloudOperationPollerrD   rU   projects_locations_operationsCloudOperationPollerNoResourcesWaitForrR  )rJ   operation_refmessage
has_resultmax_waitpollers         r&   wait_for_operation'InsightsConfigClient.wait_for_operation  ss    2 **
++
8
8
++
3
3f
 55
++
3
3f >>w4D4Dt4K r%   )rF   r=   rD   rH   rI   r<   N) )+r   r    r!   r"   r#   rK   ra   r>   ry   rS   rT   r   ro   r   rt   rq   r   r   rr   r   r   r   r   ru   r   r   r   r   r   rv   r  r  r  r  rw   r+  r3  r;  rP  datetime	timedeltar^  r$   r   r%   r&   r@   r@   a   s8   :0A YYAF- YY-^(!#':'<'K'K"KL( '+38n( C$&5556	(:46%!9%!:>s)%!C$&5556%!N(!(!C$&5556(!T!#Y! "#':'<'K'K"KL! C$&5556	!<?0$(
"$33
3%?0
 #'
"$33
3#?0 SXt/1@@AAB?0B3 3 >%3N 8DG,3j0d"(,P\( FH>@M !!#.%r%   r@   )5r#   ra  typingr   r   r   r   r   apitools.base.pyr   r/   +googlecloudsdk.api_lib.cloudresourcemanagerr	   (googlecloudsdk.api_lib.developer_connectr
   9googlecloudsdk.api_lib.developer_connect.insights_configsr   r   r   'googlecloudsdk.api_lib.resource_managerr   googlecloudsdk.api_lib.servicesr   googlecloudsdk.api_lib.utilr   r   googlecloudsdk.callioper   ,googlecloudsdk.command_lib.developer_connectr   googlecloudsdk.command_lib.iamr   #googlecloudsdk.command_lib.projectsr   r   googlecloudsdk.corer   r   googlecloudsdk.core.consoler   r2  r   _MAX_WAIT_TIME_IN_MSReleaseTrackALPHAr9   InternalErrorr   r-   r6   r>   objectr@   r   r%   r&   <module>rv     s     G  . . > D ; U u ; 8 , . ( = 3 E * # ) 2
 !\   T
B
(@(@ B"=( '+&7&7&=&= A
T6 Tr%   