
    ?                        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S	KJr  SS
KJr  SSKJr  \" 1 Sk5      rS\S\\R,                     4S jr\R0                  " SS9 " S S5      5       rS\R,                  S\4S jrS\R6                  " 5       R8                  S\R,                  4S jrS\S\4S jrg)zUtilities for GCR.    N)Iterator)
list_pager)docker_name)docker_http)docker_image)client_util)util)log)
properties>    eu.us.asia.parentreturnc              #   d  #    [         R                  " 5       R                  U SS[        R                  R
                  R                  R                  5        S3/SS9n[        R                  " [         R                  " 5       R                  USSSS	9nU H  n[        U5      nUc  M  Uv   M     g
7f)zLists GCR repositories under the parent resource.

Args:
  parent: A parent resource, e.g. projects/123, folders/123, orgnizations/123.

Yields:
  Each docker repository that is a GCR repo under the parent resource.
zname:artifacts appspot comzstorage.z/Bucketzname,parentFullResourceName)scopequery
assetTypesreadMaskSearchAllResourcesresultspageSize)methodfieldbatch_size_attributeN)asset_client_utilGetMessages#CloudassetSearchAllResourcesRequestr   VALUEScoreuniverse_domainGetr   YieldFromList	GetClientv1_BucketToRepo)r   gcr_buckets_search_requestgcr_bucketsbucketrepos        8lib/googlecloudsdk/api_lib/container/images/gcr_utils.pyListGCRReposr-       s      ##%II,**//??CCEFgN 1 J   ((!!#&& !%+ f Dj s   B!B0'	B0T)frozenc                   .    \ rS rSr% Sr\\S'   \\S'   Srg)GCRUsageB   zsGCRUsage represents usage for a GCR repo.

Attributes:
  repository: A GCR repo name.
  usage: Usage for the repo.

repositoryusage N)__name__
__module____qualname____firstlineno____doc__str__annotations____static_attributes__r4       r,   r0   r0   B   s     /	*r=   r0   r+   c                     [         R                  " [        R                  " 5       U [        R                  " 5       S9 n[        [        U 5      UR                  5       5      sSSS5        $ ! , (       d  f       g= f! [        R                  [        R                  4 a(  n[        [        U 5      [        U5      5      s SnA$ SnAff = f)z`Checks usage for a GCR repo.

Args:
  repo: A docker repository.

Returns:
  A GCRUsage object.
)basic_credsname	transportN)r   FromRegistryr	   CredentialProviderHttpr0   r:   check_usage_onlyr   V2DiagnosticExceptionTokenRefreshException)r+   res      r,   CheckGCRUsagerJ   O   s    '		"	"++-))+
 
c$i!3!3!56
 
 
 ''''
 ' CIs1v&&	's:   <A< #A+!	A< +
A95A< 9A< <$C C=CCr*   c                 |   S[         R                  R                  R                  R	                  5        S3nU R
                  R                  U5      (       d$  [        R                  " U R
                   S35        gU R
                  [        U5      S nS[         R                  R                  R                  R	                  5        S3n[        U5      nU R                  R                  U5      (       a   U R                  R                  U5      (       d$  [        R                  " U R                   S35        gU R                  [        U5      [        U5      *  nU[        ;  a$  [        R                  " U R                   S35        gSR                  XRR                  S	SS
5      S9n[         R"                  " U5      $ )zConverts a GCS bucket to a GCR repo.

Args:
  bucket: A CAIS ResourceSearchResult for a GCS bucket.

Returns:
  A docker repository.
z//cloudresourcemanager.z
/projects/z# is not a Project name. Skipping...Nz
//storage./z0 is not a Container Registry bucket. Skipping...z{region}gcr.io/{project}:   )regionproject)r   r    r!   r"   r#   parentFullResourceName
startswithr
   warninglen_BucketSuffixr@   endswith_VALID_GCR_REGION_PREFIXformatreplacer	   ValidateRepositoryPath)r*   project_prefix
project_idbucket_prefixbucket_suffixgcr_region_prefixgcr_repo_paths          r,   r'   r'   g   s    -Z->->-C-C-S-S-W-W-Y,ZZde.		&	&	1	1.	A	AKK((
))LM ,,S-@-AB*z0055EEIIKLAN-
+-				.	.fkk6J6J7 7 KK;;-GH kk#m"4c-6H5HI66KK;;-GH ,33(:(:3Q(G 4 - 
	$	$]	33r=   r\   c                 n    U R                  SS5      n[        U5      S:X  a  SUS    SUS    S3$ SU  S3$ )	av  Converts a project ID to a GCR bucket suffix.

Args:
  project_id: The project ID.

Returns:
  A string representing the suffix of GCR buckets in the project. The suffix
  format is different for normal projects and domain-scoped projects. For
  example:

  my-proj           -> artifacts.my-proj.appspot.com
  my-domain:my-proj -> artifacts.my-proj.my-domain.a.appspot.com
rM   rN      z
artifacts..r   z.a.appspot.comz.appspot.com)splitrT   )r\   chunkss     r,   rU   rU      sN     C#&[Aq	{!F1I;n==j\	..r=   )r9   dataclassestypingr   apitools.base.pyr   containerregistry.clientr   containerregistry.client.v2_2r   r   googlecloudsdk.api_lib.assetr   r   'googlecloudsdk.api_lib.container.imagesr	   googlecloudsdk.corer
   r   	frozensetrW   r:   
Repositoryr-   	dataclassr0   rJ   r   ResourceSearchResultr'   rU   r4   r=   r,   <module>rr      s        ' 0 5 6 I 8 # *$%@A  +*@*@!A D d#	 	 $	'.. '8 '0'4))+@@'4'4T/c /c /r=   