
                          N   d Z ddlmZ ddlmZ ddlmZ ddlZddlmZ ddlmZ ddlm	Z	 dd	l
mZ dd
lmZ ddlmZ ddlmZ ej"                  ZdZ ej(                  ej*                  j,                         ej.                  de       G d dej0                                      Zy)zEnable Docker CLI access to Google Container Registry.

Sets Docker up to authenticate with Container Registry,
and passes all flags after `--` to the Docker CLI.
    )absolute_import)division)unicode_literalsN)arg_parsers)base)
exceptions)log)
client_lib)	constants)dockera  `gcloud docker` will not be supported for Docker client versions above 18.03.

As an alternative, use `gcloud auth configure-docker` to configure `docker` to
use `gcloud` as a credential helper, then use `docker` as you would for non-GCR
registries, e.g. `docker pull gcr.io/project-id/my-image`. Add
`--verbosity=error` to silence this warning: `gcloud docker
--verbosity=error -- pull gcr.io/project-id/my-image`.

See: https://cloud.google.com/container-registry/docs/support/deprecation-notices#gcloud-docker
F)
is_removedwarningc                   B    e Zd ZdZdej
                  iZed        Zd Z	y)Dockera  Enable Docker CLI access to Google Container Registry.

  {command} wraps Docker commands so that `gcloud` can
  inject the appropriate fresh authentication token into requests that interact
  with the Docker registry.

  All Docker-specific flags are passed through to the underlying `docker`
  command. A full reference of Docker's command line options available after
  `--` can be found here:
  [](https://docs.docker.com/engine/reference/commandline/cli/). You may also
  run `{command} -- --help` to view the Docker CLI's help directly.

  Detailed documentation on Container Registry can be found here:
  [](https://cloud.google.com/container-registry/docs/)

  ## EXAMPLES

  To pull the image '{registry}/google-containers/pause:1.0' from the docker
  registry, run:

  ```
  {command} -- pull {registry}/google-containers/pause:1.0
  ```

  Push the image '{registry}/example-org/example-image:latest' to our private
  docker registry.

  ```
  {command} -- push {registry}/example-org/example-image:latest
  ```

  Configure authentication, then simply use docker:

  ```
  {command} --authorize-only
  docker push {registry}/example-org/example-image:latest
  ```

  registryc           	          | j                  ddt        j                  d      dddt               | j                  d	d
dd       | j                  dd       | j                  dt        j
                  g d       y )Nz--serverz-s   )
min_lengthSERVERz%Address of the Google Cloud Registry.F)typemetavarhelprequireddefaultz--authorize-onlyz-azKConfigure Docker authorization only; do not launch the Docker command-line.
store_true)r   actionz--docker-hostzSURL to connect to Docker Daemon. Format: tcp://host:port or unix:///path/to/socket.)r   docker_argszArguments to pass to Docker.)nargsr   r   )add_argumentr   ArgList_DEFAULT_REGISTRIESargparse	REMAINDER)parsers    lib/surface/docker.pyArgszDocker.Argse   s    
D  A.4#  % D	   "  #
 X//+  -    c                    |j                   rt        j                  d       t        j                         5  d}|j
                  D ]H  }|t        vr%t        j                  dj                  |             t        j                  ||       d}J |j                  rCt        j                  j                  dj                  |j
                               	 ddd       y|j                  xs g }|j                  s|nd	|j                  g|z   }t        j                   |      }|rt#        j$                  |
      	 ddd       y# 1 sw Y   yxY w)a  Executes the given docker command, after refreshing our credentials.

    Args:
      args: An argparse.Namespace that contains the values for
         the arguments specified in the .Args() method.

    Raises:
      exceptions.ExitCodeNoError: The docker command execution failed.
    zDocker uses the account from the gcloud config.To set the account in the gcloud config, run `gcloud config set account <account_name>`.Tz1Authenticating to a non-default server: {server}.)server)refreshFz+Short-lived access for {server} configured.Nz-H)	exit_code)accountr	   r   r   WithLegacyQuotar)   r!   formatr   UpdateDockerCredentialsauthorize_onlyerrPrintr   docker_hostdocker_client_utilsExecuter   ExitCodeNoError)selfargsforce_refreshr)   r   results         r%   Runz
Docker.Run}   s5    || 
kk @ A 
			mKK&,,
++AHH I !" 	&&v}E   
		
 	CJJ;; K   	!% 
 	( $$*k!--+D$:J:J3K
4  #**;7f 
((6::= 
 		s   B EAEEN)
__name__
__module____qualname____doc__r   DEFAULT_REGISTRYdetailed_helpstaticmethodr&   r;    r'   r%   r   r   6   s5    &R ),,- - -.2r'   r   )r?   
__future__r   r   r   r"   googlecloudsdk.callioper   r   r   googlecloudsdk.corer	   googlecloudsdk.core.dockerr
   r4   r   r   "DEFAULT_REGISTRIES_TO_AUTHENTICATEr!   _DEPRECATION_WARNINGReleaseTracksReleaseTrackGA	DeprecateCommandr   rC   r'   r%   <module>rO      s     '  '  / ( . # H 0 -  BB 
  D%%(()5*>?wT\\ w @ *wr'   