
                             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rSSKr " S
 S\5      rg)zThis package manages interaction sessions with the docker registry.

'Push' implements the go/docker:push session.
'Pull' is not implemented (go/docker:pull).
    )absolute_import)division)print_functionN)docker_creds)docker_name)docker_http)docker_imagec                   Z    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rS rS rS rSrg)Push$   z+Push encapsulates a go/docker:push session.c                 6    Xl         X l        X0l        SU l        g)zConstructor.

Args:
  name: the fully-qualified name of the tag to push.
  creds: provider for authorizing requests.
  transport: the http transport to use for sending requests.

Raises:
  TypeError: an incorrectly typed argument was supplied.
N)_name_basic_creds
_transport_top)selfnamecreds	transports       >lib/third_party/containerregistry/client/v1/docker_session_.py__init__Push.__init__'   s     JODI    c           	      >   [         R                  " U R                  SR                  [         R                  " U R
                  R                  5      U R
                  R                  U R
                  R                  S9U R                  [        R                  R                  R                  [        R                  R                  R                  /SS9u  p[        R                  " US   5      U l        US   U l        [$        R&                  " SU R
                  5        U $ )Nz3{scheme}://{registry}/v1/repositories/{repository}/schemeregistry
repositoryz[]accepted_codesbodyzx-docker-tokenzx-docker-endpointszInitiated upload of: %s)r   Requestr   formatSchemer   r   r   r   sixmoveshttp_clientOKCREATEDv1_credsToken_token_creds	_endpointlogginginfo)r   respunused_contents      r   	__enter__Push.__enter__9   s     '..=DD%%djj&9&9:ZZ((zz,, 	E 	. 	II!!$$cii&;&;&C&C
 
D !t,<'=>D./DN LL*DJJ7Kr   c           	         [         R                  " U R                  SR                  [         R                  " U R
                  5      U R
                  US9U R                  [        R                  R                  R                  [        R                  R                  R                  /S9u  p#UR                  [        R                  R                  R                  :H  $ )z%Check the remote for the given layer.,{scheme}://{endpoint}/v1/images/{layer}/jsonr   endpointlayer)r    )r   r"   r   r#   r$   r-   r,   r%   r&   r'   r(   	NOT_FOUNDstatus)r   layer_idr0   r1   s       r   _existsPush._existsX   s    &..6==%%dnn5^^ 	> 	 	II!!$$cii&;&;&E&E
	D ;;#))//2222r   c           	      L   [         R                  " U R                  SR                  [         R                  " U R
                  5      U R
                  US9U R                  [        R                  R                  R                  /UR                  U5      R                  S5      S9  g)z#Upload the json for a single layer.r5   r6   utf8r   N)r   r"   r   r#   r$   r-   r,   r%   r&   r'   r(   jsonencoder   imager;   s      r   	_put_jsonPush._put_jsonf   s~    6==%%dnn5^^ 	> 	 			--001ZZ!((02r   c           	      0   [         R                  " U R                  SR                  [         R                  " U R
                  5      U R
                  US9U R                  [        R                  R                  R                  /UR                  U5      SS9  g)z+Upload the aufs tarball for a single layer.z-{scheme}://{endpoint}/v1/images/{layer}/layerr6   zapplication/octet-stream)r    r!   content_typeN)r   r"   r   r#   r$   r-   r,   r%   r&   r'   r(   r8   rB   s      r   
_put_layerPush._put_layerr   sx     7>>%%dnn5^^ 	? 	 			--001[["/	1r   c                     g)z'Upload the checksum for a single layer.N rB   s      r   _put_checksumPush._put_checksum   s    
 	r   c                     U R                  U5      (       a  [        R                  " SU5        gU R                  X5        U R	                  X5        U R                  X5        [        R                  " SU5        g)z@Upload a single layer, after checking whether it exists already.zLayer %s exists, skippingNzLayer %s pushed.)r<   r.   r/   rD   rH   rL   rB   s      r   _upload_onePush._upload_one   s\     ||Hll.9 	NN5#OOE$u'LL#X.r   c                     UR                  5       U l        [        UR                  U R                  5      5       H  nU R	                  X5        M     g)zSUpload the layers of the given image.

Args:
  image: the image tarball to upload.
N)topr   reversedancestryrO   )r   rC   r8   s      r   uploadPush.upload   s;     		DI%..34
u$ 5r   c           
         [         R                  " U R                  SR                  [         R                  " U R
                  5      U R
                  U R                  R                  U R                  R                  S9U R                  [        R                  R                  R                  /SU R                  -  R                  S5      S9  g)z/Upload the new value of the tag we are pushing.z={scheme}://{endpoint}/v1/repositories/{repository}/tags/{tag})r   r7   r   tagz"%s"r?   r   N)r   r"   r   r#   r$   r-   r   r   rX   r,   r%   r&   r'   r(   r   rA   r   s    r   _put_tagPush._put_tag   s    GNN%%dnn5^^zz,,

	 	O 	 
 			--001tyy ((0	2r   c           	      `   [         R                  " U R                  SR                  [         R                  " U R
                  R                  5      U R
                  R                  U R
                  R                  S9U R                  [        R                  R                  R                  /SS9  g)z8Close the session by putting to the .../images endpoint.z9{scheme}://{registry}/v1/repositories/{repository}/imagesr   s   []r   N)r   r"   r   r#   r$   r   r   r   r   r%   r&   r'   
NO_CONTENTrY   s    r   _put_imagesPush._put_images   s    CJJ%%djj&9&9:ZZ((zz,, 	K 	. 			--889r   c                     U(       a"  [         R                  " SU R                  5        g U R                  5         U R	                  5         [         R
                  " SU R                  5        g )NzError during upload of: %szFinished upload of: %s)r.   errorr   rZ   r^   r/   )r   exception_typeunused_valueunused_tracebacks       r   __exit__Push.__exit__   sG    mm0$**=
 	MMO 	LL)4::6r   )r   r-   r   r,   r   r   N)__name__
__module____qualname____firstlineno____doc__r   r2   r<   rD   rH   rL   rO   rU   rZ   r^   re   __static_attributes__rK   r   r   r   r   $   s<    3$>3
21	/ %2
7r   r   )rk   
__future__r   r   r   r.   containerregistry.clientr   r   containerregistry.client.v1r*   r   r	   httplib2six.moves.http_clientr%   objectr   rK   r   r   <module>rs      s;    '  %  1 0 @ 3 4  e76 e7r   