
                             S r SSK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  S\S	\4S
 jrS	\4S jrg)z/Utilities for IAP checks in Cloud Run commands.    N)encoding)
exceptions)projects_api)util)
properties
project_idreturnc                     [         R                  " U 5      nU(       a  UR                  (       d  gUR                   H/  nUR                  R                  R                  S5      (       d  M/    g   g! [        R                   a    [        R                  " SU SS9   g[        R                   a    [        R                  " SU SS9   g[        R                   a    [        R                  " SU SS9   gf = f)a  Checks if a given project is part of an organization.

Args:
  project_id: The ID of the project to check.

Returns:
  True if the project is not associated with any organization, False
  otherwise.
  Also returns True if there are errors fetching the ancestry.
TorganizationFz2Permission denied to get project ancestry for [%r]exc_infoz1HTTP error when getting project ancestry for [%r]z4Unknown error when getting project ancestry for [%r])r   GetAncestryancestor
resourceIdtype
startswithapi_exceptionsHttpForbiddenErrorloggingdebug	HttpErrorcore_exceptionsError)r   ancestryr   s      .lib/googlecloudsdk/command_lib/run/iap_util.pyIsOrglessProjectr      s    ''
3H8,,%%				!	!	,	,^	<	< & 		*	* MM<
 		!	! MM;
 			 MM>
 s.   .A1 7A1 ,A1 .A1 1*C4)C4)C43C4c                     [         R                  " 5       n[        R                  R                  R
                  R                  SS9Ul        SUl        SUl        SUl	        SUl
        SUl        SUl        [        R                  " U R                  5       U5      n UR!                  5       n[.        R0                  " U5      nUR3                  S	0 5      R3                  S
0 5      nUR3                  S5      nUR3                  S5      n[5        U5      =(       a    [5        U5      $ ! ["        R$                   a    [&        R(                  " SSS9   g["        R*                   a#    [&        R(                  " SUR
                  SS9   g["        R,                   a    [&        R(                  " SSS9   gf = f! [6        R8                   a    [&        R(                  " SSS9   gf = f)zChecks if IAP is already enabled for the current project.

Args:
  self: The command object.

Returns:
  True if IAP is enabled (client ID and secret are present), False otherwise.
T)requiredNzHPermission 'iap.projects.getSettings' denied. Cannot confirm IAP status.r   Fz-No project-level IAP settings found for [%r].z-Failed to get IAP settings due to HTTP error.accessSettingsoauthSettingsclientIdclientSecretSha256z'Unknown error when getting IAP settings)typesSimpleNamespacer   VALUEScoreprojectGetresource_typeserviceregionr   folderversioniap_command_utilParseIapSettingsResourceReleaseTrackGetIapSettingr   r   r   r   HttpNotFoundErrorr   r   MessageToDictgetboolr   r   )selfiap_argsiap_setting_refiap_settingsiap_settings_dictoauth_settings	client_idclient_secret_sha256s           r   IsIapAlreadyEnabledr>   H   s   -$$&H!((--559949HH!HHHO HHOH&??O$224l* !..|<&**+;R@DDN "":.I)--.BC	?9t$8995 ,, mm
 ++ mm
9



 ## mm
9  
		 MM;dKsO   BF2 D$ -A6F2 $)F/F2 3F/F2 (F/,F2 .F//F2 2)GG)__doc__r   r#   apitools.base.pyr   r   r   +googlecloudsdk.api_lib.cloudresourcemanagerr   googlecloudsdk.command_lib.iapr   r.   googlecloudsdk.corer   r   strr5   r   r>        r   <module>rG      sD     6   % 9 D C = *' ' 'T6 6rF   