Add created_datetime to schema1 format
This commit is contained in:
parent
2cc4fdd48b
commit
7fa3506723
2 changed files with 18 additions and 0 deletions
|
@ -11,6 +11,8 @@ import logging
|
|||
from collections import namedtuple, OrderedDict
|
||||
from datetime import datetime
|
||||
|
||||
import dateutil.parser
|
||||
|
||||
from jsonschema import validate as validate_schema, ValidationError
|
||||
|
||||
from jwkest.jws import SIGNER_ALGS, keyrep
|
||||
|
@ -268,6 +270,18 @@ class DockerSchema1Manifest(ManifestInterface):
|
|||
def leaf_layer(self):
|
||||
return self.layers[-1]
|
||||
|
||||
@property
|
||||
def created_datetime(self):
|
||||
created_datetime_str = self.leaf_layer.v1_metadata.created
|
||||
if created_datetime_str is None:
|
||||
return None
|
||||
|
||||
try:
|
||||
return dateutil.parser.parse(created_datetime_str).replace(tzinfo=None)
|
||||
except:
|
||||
# parse raises different exceptions, so we cannot use a specific kind of handler here.
|
||||
return None
|
||||
|
||||
@property
|
||||
def layers(self):
|
||||
if self._layers is None:
|
||||
|
|
|
@ -78,6 +78,7 @@ def test_valid_manifest():
|
|||
assert manifest.layers[1].v1_metadata.parent_image_id == 'anotherid'
|
||||
|
||||
assert manifest.leaf_layer == manifest.layers[1]
|
||||
assert manifest.created_datetime is None
|
||||
|
||||
|
||||
def test_validate_manifest():
|
||||
|
@ -88,6 +89,7 @@ def test_validate_manifest():
|
|||
manifest = DockerSchema1Manifest(manifest_bytes, validate=True)
|
||||
digest = manifest.digest
|
||||
assert digest == 'sha256:b5dc4f63fdbd64f34f2314c0747ef81008f9fcddce4edfc3fd0e8ec8b358d571'
|
||||
assert manifest.created_datetime
|
||||
|
||||
|
||||
def test_validate_manifest_with_unicode():
|
||||
|
@ -98,6 +100,7 @@ def test_validate_manifest_with_unicode():
|
|||
manifest = DockerSchema1Manifest(manifest_bytes, validate=True)
|
||||
digest = manifest.digest
|
||||
assert digest == 'sha256:815ecf45716a96b19d54d911e6ace91f78bab26ca0dd299645d9995dacd9f1ef'
|
||||
assert manifest.created_datetime
|
||||
|
||||
|
||||
def test_validate_manifest_with_unicode_encoded():
|
||||
|
@ -108,3 +111,4 @@ def test_validate_manifest_with_unicode_encoded():
|
|||
manifest = DockerSchema1Manifest.for_latin1_bytes(manifest_bytes, validate=True)
|
||||
digest = manifest.digest
|
||||
assert digest == 'sha256:dde3714ce7e23edc6413aa85c0b42792e4f2f79e9ea36afc154d63ff3d04e86c'
|
||||
assert manifest.created_datetime
|
||||
|
|
Reference in a new issue