
    }                     ^   S r SSKJr  SSKJr  SSKJr  SSKJr  SSKrSSKJrJ	r	  SSK
Jr  SSKJr  SSKJr  SS	KJr  \R$                  " S
5      r\R$                  " S5      r\R$                  " S5      r\R,                  rS\S\SS4S jrS\S\SS4S jrS\SS4S jrS\S\	\   SS4S jrg)z4Utility for the CMEK and user-provided AR use cases.    )absolute_import)division)print_function)unicode_literalsN)AnyOptional)
exceptions)http_clientz`^projects/[^/]+/locations/(?P<location>[^/]+)/keyRings/[a-zA-Z0-9_-]+/cryptoKeys/[a-zA-Z0-9_-]+$zc^projects/(?P<project>[^/]+)/locations/(?P<location>[^/]+)/repositories/[a-z]([a-z0-9-]*[a-z0-9])?$zG^(?P<location>.*)-docker.pkg.dev\/(?P<project>[^\/]+)\/(?P<repo>[^\/]+)kms_keyfunction_refreturnc                     [         R                  U 5      nU(       aV  UR                  S5      nUS:X  a  [        R                  " SS5      eUR
                  U:w  a  [        R                  " SS5      egg)zChecks that the KMS key is compatible with the function.

Args:
  kms_key: Fully qualified KMS key name.
  function_ref: Function resource reference.

Raises:
  InvalidArgumentException: If the specified KMS key is not compatible with
    the function.
locationglobalz	--kms-keyz$Global KMS keyrings are not allowed.zBKMS keyrings should be created in the same region as the function.N)_KMS_KEY_REsearchgroupbase_exceptionsInvalidArgumentExceptionlocationsId)r   r   kms_key_matchkms_keyring_locations       1lib/googlecloudsdk/api_lib/functions/cmek_util.pyValidateKMSKeyForFunctionr   0   s}     $$W--(..z:x'44
=  #7744

N  8     docker_repositoryc                 "   U c  gUR                   nUR                  n[        R                  U 5      nU(       a#  UR	                  S5      nUR	                  S5      nOC[
        R                  U 5      nU(       a#  UR	                  S5      nUR	                  S5      nOSnSnU(       aB  X%:w  a=  UR                  5       UR                  5       :X  a  [        R                  " SSU S35      eU(       a!  X6:w  a  [        R                  " SSU S35      egg)a.  Checks that the Docker repository is compatible with the function.

Args:
  docker_repository: Fully qualified Docker repository resource name.
  function_ref: Function resource reference.

Raises:
  InvalidArgumentException: If the specified Docker repository is not
    compatible with the function.
Nprojectr   z--docker-repositoryzLCross-project repositories are not supported: the repository should be in `$z`.zMCross-location repositories are not supported: the repository should be in `$)	
projectsIdr   _DOCKER_REPOSITORY_REr   r   #_DOCKER_REPOSITORY_DOCKER_FORMAT_REisdigitr   r   )r   r   function_projectfunction_location
repo_matchrepo_projectrepo_locationrepo_match_docker_formats           r   #ValidateDockerRepositoryForFunctionr)   I   s#    
!,,"..$++,=>*##I.L$$Z0MBII   -33I>l.44Z@mml 

*

"
"
$(<(<(>
>

2
2	!""	&  (9

2
2	%&b	*  :]r   c                     U c  U $ [         R                  U 5      nU(       aE  UR                  S5      nUR                  S5      nUR                  S5      nSR                  X#U5      $ U $ )zNormalizes the docker repository name to the standard resource format.

Args:
  docker_repository: Fully qualified Docker repository name.

Returns:
  The name in a standard format supported by the API.
r   r   repoz(projects/{}/locations/{}/repositories/{})r!   r   r   format)r   r(   r   r   names        r   NormalizeDockerRepositoryFormatr.   ~   sy     @GG &,,Y7G'--j9H#))&1D5<<4  
r   http_exceptionc                     U(       aB  U R                   [        R                  :X  a#  [        R                  " SR                  US95      eg g )Na3  An error occurred. Ensure that the KMS key {kms_key} exists and the Cloud Functions service account has encrypter/decrypter permissions (roles/cloudkms.cryptoKeyEncrypterDecrypter) on the key. If you have recently made changes to the IAM config, wait a few minutes for the config to propagate and try again.)r   )status_coder
   INTERNAL_SERVER_ERRORr	   FunctionsErrorr,   )r/   r   s     r   ProcessExceptionr4      sN     

$
$(I(I
I 
#
#	5 6<VGV5L 	 J r   )__doc__
__future__r   r   r   r   retypingr   r   apitools.base.pyr	   http_exceptions#googlecloudsdk.api_lib.functions.v1googlecloudsdk.callioper   	six.movesr
   compiler   r    r!   	HttpError
_HttpErrorstrr   r)   r.   r4    r   r   <module>rC      s    ; &  % ' 	   : : A ! jj" 

0  ')jjN' #
 &&
s # $ 222*-2	2js t 4)1#	r   