
                         ~    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  SrSS	 jrS
 rS r SS jrg)zBuild utils.    N)
exceptions)cloudbuild_util)util)iam_util)logz&^\d+@cloudbuild\.gserviceaccount\.com$c                     [         R                  " 5       nSU  SU S3nUR                  R                  UR                  R                  US95      R                  $ )z5Gets the default build service account for a project.z	projects/z/locations/z/defaultServiceAccountname)r   GetClientInstanceprojects_locationsGetDefaultServiceAccountMESSAGES_MODULE:CloudbuildProjectsLocationsGetDefaultServiceAccountRequestserviceAccountEmail)
project_idregionclientr
   s       0lib/googlecloudsdk/command_lib/run/build_util.py_GetDefaultBuildServiceAccountr      sc    ,,.&ZLF83I	J$		"	"	;	;WW X 
 	    c                 b    [         R                  " SU 5      nU(       a  UR                  S5      $ g)zEExtracts the service account email from the service account resource.z/serviceAccounts/([^/]+)$   N)researchgroup)service_accountmatchs     r   _ExtractServiceAccountEmailr   '   s'    
))0/
B%
;;q>r   c                     [         R                  " 5       u  pUR                  R                  UR	                  [
        R                  " U 5      S95      $ )Nr	   )iam_api_utilGetClientAndMessagesprojects_serviceAccountsGet$IamProjectsServiceAccountsGetRequestr   EmailToAccountResourceName)service_account_emailr   messagess      r   _DescribeServiceAccountr(   0   sN    !668&		(	(	,	,33223HI 4 
 r   c                    Uc  [        X5      n[        U5      n [        R                  " [        U5      (       d7  [        U5      nUR                  (       a  [        R                  " SU S35      egg! [        R                   a     [        R                  " SU SU S35         g[        R                   a5    [        R                  " SU S35        [        R                  " S	U S
35      ef = f)a  Util to validate the default build service account permission.

Prompt a warning to users if cloudbuild.builds.builder is missing.

Args:
  project_id: id of project.
  region: region to deploy the service.
  build_service_account: user provided build service account. It will be None,
    if user doesn't provide it.

Raises:
  ServiceAccountError: if the build service account is disabled/not
  found/missing required permissions.
Nz~Could not build the function due to disabled service account used by Cloud Build. Please make sure that the service account: [z] is active.zPYour account does not have permission to check details of build service account z). If the deployment fails, please ensure z is active.zThe build service account z does not exist. If you just created this account, or if this is your first time deploying with the default build service account, it may take a few minutes for the service account to become fully available. Please try again later.zBuild service account z does not exist.)r   r   r   r   _LEGACY_BUILD_SA_FORMATr(   disabledserverless_exceptionsServiceAccountErrorapitools_exceptionsHttpForbiddenErrorr   warningHttpNotFoundError)r   r   build_service_accountr&   !build_service_account_descriptions        r   +ValidateBuildServiceAccountAndPromptWarningr4   9   s   $ "::N56KL88+-BCC*A
+' 
+	3	3#77&'|5
 	
 
4	 D 
	/	/  KK	12 3/0	=
 
	.	. 
KK
$%:$; < 	  
3
3
 !6 77GH 
s   AA3 31C.&AC.)global)N)__doc__r   apitools.base.pyr   r.   !googlecloudsdk.api_lib.cloudbuildr   googlecloudsdk.api_lib.iamr   r    googlecloudsdk.command_lib.iamr   googlecloudsdk.command_lib.runr,   googlecloudsdk.corer   r*   r   r   r(   r4    r   r   <module>r>      sA     	 > = ; 3 N # D  /33r   