
                            d Z ddlmZ ddlmZ ddlZddl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  ej                  d	
      Zej#                  ddd       ej#                  dddd       ej#                  ddd       ej#                  ddd       ej#                  ddd       ej#                  ddd       ej#                  ddd       d Zed k(  r e        yy)!zThis package calculates the digest of an image.

The format this tool *expects* to deal with is proprietary.
Image digests aren't stable upon gzip implementation/configuration.
This tool is expected to be only self-consistent.
    )absolute_import)print_functionN)docker_image)
oci_compat)logging_setup)zipz'Calculate digest for a container image.)descriptionz	--tarballstorez&An optional legacy base image tarball.)actionhelpz--output-digestTzFilename to store digest in.)requiredr   r   z--configz.The path to the file storing the image config.z
--manifestz0The path to the file storing the image manifest.z--digestappendz,The list of layer digest filenames in order.z--layerz%The list of layer filenames in order.z--oci
store_truezImage has an OCI Manifest.c            
      z   t        j                  t               t        j                         } t        j                  |        | j
                  sB| j                  s| j                  r*t        j                  d       t        j                  d       | j
                  s6| j                  s*t        j                  d       t        j                  d       | j
                  }| j                  }| j
                  rPt        j                  d| j
                         t        | j
                  d      5 }|j!                         }d d d        nd| j                  rXt        j                  d| j                         t#        j$                  | j                        5 }|j'                         }d d d        | j                  r/t        | j                  d      5 }|j!                         }d d d        t)        | j                  xs g       t)        | j                  xs g       k7  r*t        j                  d       t        j                  d       t        j                  d	       t#        j*                  |t-        t/        | j                  xs g | j                  xs g             | j                  |
      5 }	 | j0                  r/t3        j4                  |      5 }|j                         }d d d        n|j                         }t        | j6                  d      5 }|j9                         d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   nxY w# 1 sw Y   ixY w# 1 sw Y   ExY w# t:        $ r5}	t        j                  d|	       t        j                  d       Y d }	~	d }	~	ww xY w# 1 sw Y   y xY w)N)argsz<Using --layer or --digest requires --config to be specified.   z/Either --config or --tarball must be specified.zReading config from %rrzReading config from tarball %rz0--digest and --layer must have matching lengths.z Loading v2.2 image from disk ...)legacy_baseforeign_layers_manifestzw+zError getting digest: %s)r   DefineCommandLineArgsparser
parse_argsInitconfiglayerdigestloggingfatalsysexittarballmanifestinfoopenread
v2_2_imageFromTarballconfig_filelenFromDisklistr   ocir   
OCIFromV22output_digestwrite	Exception)
r   r   r"   readerbasev2_2_imgoci_imgr   digest_filees
             :lib/third_party/containerregistry/tools/image_digester_.pymainr8   D   s   %%f-				$$	$**MMFHHHQK	T\\MMCDHHQK ;;&]](	[[LL)4;;7	dkk3	6{{}f 
 	||LL14<<@				-!f 
. 
]]	dmmS	!Vh 
" 		s4::#344MMDEHHQK	,,12
3t{{ b$**"234,,&	( ,4	""8,>>#& -, """D)[&! *( (! 
 	 
.	- 
"	!  -,
 *)  mm.2	hhqkk!( (s   .L1L>M+N1-!M0M/M0M$ M01L;>MMM!	M0$M-	)M00	N.9+N)$N1)N..N11N:__main__)__doc__
__future__r   r   argparser   r   containerregistry.client.v2_2r   r&   r   containerregistry.toolsr   	six.movesr   ArgumentParserr   add_argumentr8   __name__     r7   <module>rE      s+   ' %   
 D 4 1 	 	 	 9
;   &N  P   	'	  )   	9  ;
   	;  =
   	7  9
   h%L  N   L'C  E6r z& rD   