
                            S 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  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\	R(                  5      r\R,                  " \R.                  R0                  \R.                  R2                  \R.                  R4                  5      \R6                   " S S\R8                  5      5       5       rg)z.Register gcloud as a Docker credential helper.    )absolute_import)division)unicode_literalsN)base)
exceptions)log)
properties)
console_io)credential_utils)filesc                       \ rS rSrSrSrg)ConfigureDockerError!   zGeneral command error class. N)__name__
__module____qualname____firstlineno____doc____static_attributes__r       $lib/surface/auth/configure_docker.pyr   r   !   s    $r   r   c                   @    \ rS rSrSrS rS r\S 5       rS r	S r
Srg	)
ConfigureDocker%   aM  Register `gcloud` as a Docker credential helper.

{command} adds the Docker `credHelper` entry to Docker's configuration file,
or creates the file if it doesn't exist. This will register `gcloud` as the
credential helper for all Google-supported Docker registries. If the Docker
configuration already contains a `credHelper` entry, it will be overwritten.

Note: `docker` and `gcloud` need to be on the same system `PATH` to work
correctly.

Note: This command will not work for `docker` installed via Snap, as the
`docker` snap package does not currently provide an interface for credential
helpers.

For more details on Docker registries, see
[](https://docs.docker.com/registry/).

For more details on how to authenticate to Google Container Registry using
this command, see
[](https://cloud.google.com/container-registry/docs/advanced-authentication#gcloud-helper).

For more details on Google Container Registry's standalone credential helpers,
see [](https://github.com/GoogleCloudPlatform/docker-credential-gcr).

For more details on Docker credential helpers, see
[](https://docs.docker.com/engine/reference/commandline/login/#credential-helpers).


## EXAMPLES

To configure docker authentication after logging into gcloud, run:

  $ {command}

To configure docker authentication with Container Registry, e.g., `gcr.io`,
run:

  $ {command} gcr.io
c                 h    [         R                  " S5      =(       d    [         R                  " S5      $ )Nzdocker-credential-gcloudzdocker-credential-gcloud.cmd
file_utilsSearchForExecutableOnPathselfs    r   DockerCredentialGcloudExists,ConfigureDocker.DockerCredentialGcloudExistsS   s.    //"$ ,'1'K'K*(,,r   c                 h    [         R                  " S5      =(       d    [         R                  " S5      $ )Ndockerz
docker.exer   r    s    r   DockerExistsConfigureDocker.DockerExistsX   s-    // H99,GHr   c                 J    U R                  SSSS9  U R                  SSSSS	9  g
)zSet args for configure-docker.
registries?a	  The comma-separated list of registries to configure the credential helper for. Container Registry is a service for storing private container images. For available registries, see [](https://cloud.google.com/container-registry/docs/pushing-and-pulling#add-registry).)nargshelpz--include-artifact-registry
store_truez1Whether to include all Artifact Registry domains.T)actionr,   hiddenN)add_argument)parsers    r   ArgsConfigureDocker.Args\   sD     a   %@	  r   c           
         U R                  5       (       d  [        R                  " S5        [        R                  R                  5       nU R                  5       (       aM  UR                  5       (       d7  [        SR                  UR                  5       [        R                  5      5      eO[        R                  " S5        UR                  5       n0 nU(       aV  [        R                  " SR                  UR                  [        R                  " USS95      5        U[        R                      nUR"                  (       a  [        R$                  R'                  SR                  UR"                  5      5        UR"                  R)                  S5      n[*        R,                  R.                  R0                  R3                  5       (       a  [        R4                  " U5      nO[7        U R8                  U5      n[        R4                  " U5      nOUR:                  (       a   [        R$                  R'                  S	5        O[        R$                  R'                  S
5        [        R                  " S5        [        R4                  " SUR:                  5      nUR=                  5       nUR?                  U[        R                      5        XH:X  a   [        R$                  R'                  S5        g[        R                   U0n	[@        RB                  " SR                  UR                  [        R                  " U	SS95      SS9  URE                  U5        [        R$                  R'                  S5        g)z!Run the configure-docker command.z`docker-credential-gcloud` not in system PATH.
gcloud's Docker credential helper can be configured but it will not work until this is corrected.zInvalid Docker version: The version of your Docker client is [{}]; version [{}] or higher is required to support Docker credential helpers.z`docker` not in system PATH.
`docker` and `docker-credential-gcloud` need to be in the same PATH in order to work correctly together.
gcloud's Docker credential helper can be configured but it will not work until this is corrected.zHYour config file at [{0}] contains these credential helper entries:

{1}   )indentzAdding credentials for: {0},z3Adding credentials for all GCR and AR repositories.z,Adding credentials for all GCR repositories.zA long list of credential helpers may cause delays running 'docker build'. We recommend passing the registry name to configure only the registry you are using.Nz7gcloud credential helpers already registered correctly.z]After update, the following will be written to your Docker config file located at [{0}]:
 {1}T)messagecancel_on_noz"Docker configuration file updated.)#r"   r   warning
cred_utilsConfigurationReadFromDiskr&   SupportsRegistryHelpersr   formatDockerVersion MIN_DOCKER_CONFIG_HELPER_VERSIONGetRegisteredCredentialHelperspathjsondumpsCREDENTIAL_HELPER_KEYr)   statusPrintsplitr	   VALUES	artifactsallow_unrecognized_registryGetBoolGetGcloudCredentialHelperConfigfilterCheckValidRegistryinclude_artifact_registrycopyupdater
   PromptContinueRegisterCredentialHelpers)
r!   argscurrent_configcurrent_helperscurrent_helper_mapregistries_listnew_helpersr)   merged_helper_mapmerged_helperss
             r   RunConfigureDocker.Runm   s   ,,..	kk > ?  --::<N3355"""(&,,.;;#=> 	> 6 
kk67 %CCEO	kk $$*F$))jj;%=> +:+K+KL 	jj4;;DOOLM--c2o				$	$	@	@	H	H	J	J @@
 D33_E
 @@L 
	'	'

NO

GH	kk ? @ >>
..0k +//1[)I)IJK.	jj
CE 668IJN..4fN1!E/G	 ,,->?JJ9:r   c                     U[         R                  " 5       ;  a&  [        R                  " SR	                  U5      5        gg)Nz{0} is not a supported registryFT)r;   SupportedRegistriesr   r:   r?   )r!   registrys     r   rP   "ConfigureDocker.CheckValidRegistry   s1    z5577	kk3::8DEr   r   N)r   r   r   r   r   r"   r&   staticmethodr2   r^   rP   r   r   r   r   r   r   %   s3    
&R,
H   K;Zr   r   )r   
__future__r   r   r   rD   googlecloudsdk.callioper   googlecloudsdk.corer   r   r	   googlecloudsdk.core.consoler
   googlecloudsdk.core.dockerr   r;   googlecloudsdk.core.utilr   r   Errorr   ReleaseTracksReleaseTrackALPHABETAGAUniverseCompatibleCommandr   r   r   r   <module>rs      s     5 &  '  ( * # * 2 E 8%:++ % D%%++T->->-C-C%%((*Vdll V *Vr   