
                             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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S jr  SS jrSS jrg)z:Utilities for working with Artifact Registry repositories.    )absolute_import)division)print_function)unicode_literals)
exceptions)waiter)requests)flags)log)	resources)
console_ioc                 H    SR                  U R                  S5      S S 5      $ )N-   )joinsplit)zones    7lib/googlecloudsdk/command_lib/run/artifact_registry.py_RegionFromZoner       s     	$**S/"1%	&&    Nc                     U(       a  [        U5      $ [        R                  " U 5      nU(       a  U$ [        R                  " U SS9nU(       a  U$ [        R
                  " S5      e)a  Returns the region for the Artifact Registry repo.

 The intended behavior is platform-specific:
 * managed: Same region as the service (run/region or --region). For
   multi-region services, we will use the first specified region.
 * gke: Appropriate region based on cluster zone (cluster_location arg)
 * kubernetes: The run/region config value will be used or an exception
   raised when unset.

Args:
  args: Namespace, the args namespace.
  cluster_location: The zone which a Cloud Run for Anthos cluster resides.
    When specified, this will result in the region for this zone being
    returned.

Returns:
  The appropriate region for the repository.
F)promptzlTo deploy from source with this platform, you must set run/region via "gcloud config set run/region REGION".)r   r
   GetFirstRegion	GetRegionr   ArgumentError)argscluster_locationfirst_regionregions       r   
RepoRegionr    $   s\    & +,,%%d+,??4.&M  /	0 0r   c                     [         R                  " U R                  5       U5        g! [        R                   a    [
        R                  " S5        e [        R                   a    [
        R                  " S5        e [        R                   aE    U(       a   gSR                  U R                  U R                  S9n[        R                  " USS9   gf = f)a2  Checks for the existence of the provided repository.

If the provided repository does not exist, the user will be prompted
as to whether they would like to continue.

Args:
  repo: googlecloudsdk.command_lib.artifacts.docker_util.DockerRepo defining
    the repository.
  skip_activation_prompt: bool determining if the client should prompt if the
    API isn't activated.
  skip_console_prompt: bool determining if the client should prompt the
    user if the repository doesn't exist.

Returns:
  A boolean indicating whether a repository needs to be created.
FzpPermission denied while accessing Artifact Registry. Artifact Registry access is required to deploy from source.z6Error in retrieving repository from Artifact Registry.TzDeploying from source requires an Artifact Registry Docker repository to store built containers. A repository named [{name}] in region [{location}] will be created.)namelocation)cancel_on_no)r	   GetRepositoryGetRepositoryNamebase_exceptionsHttpForbiddenErrorr   errorHttpBadRequestErrorHttpNotFoundErrorformatrepor#   r   PromptContinue)r-   skip_activation_promptskip_console_promptmessages       r   ShouldCreateRepositoryr2   E   s    &:41135KL		+	+ 
II C D			,	, 
IIFG			*	* :BBH&		DMM CI C; 
 gD9	:s   %( A/C9CCc                    [         R                  " 5       nUR                  U R                  5       SUR                  R                  R
                  S9n[         R                  " U R                  U R                  X15      n[        R                  R                  UR                  SS9n[         R                  " 5       n[        R                  " [        R                   " UR"                  UR$                  5      U5        g)zCreates an Artifact Registry repostiory and waits for the operation.

Args:
  repo: googlecloudsdk.command_lib.artifacts.docker_util.DockerRepo defining
    the repository to be created.
  skip_activation_prompt: True if
zCloud Run Source Deployments)r"   descriptionr,   z.artifactregistry.projects.locations.operations)
collectionN)r	   GetMessages
Repositoryr&   FormatValueValuesEnumDOCKERCreateRepositoryprojectr#   r   REGISTRYParseRelativeNamer"   	GetClientr   WaitForCloudOperationPollerprojects_locations_repositoriesprojects_locations_operations)r-   r/   messagesrepository_messageopop_resourceclients          r   r:   r:   o   s     !!#(**!!#0  66== +    
llDMM#5" ""44ggJ 5 L+ &..!!&"H"H"("F"FHr   )N)FF)F)__doc__
__future__r   r   r   r   apitools.base.pyr   r'   googlecloudsdk.api_lib.utilr   $googlecloudsdk.command_lib.artifactsr	   googlecloudsdk.command_lib.runr
   googlecloudsdk.corer   r   googlecloudsdk.core.consoler   r   r    r2   r:    r   r   <module>rQ      sM    A &  % ' : . 9 5 0 # ) 2'0D 38/4'Tr   