Change label creation function to return the label created

This commit is contained in:
Joseph Schorr 2018-08-21 14:27:10 -04:00
parent 23ff49f0c1
commit 5a997eb4e3
2 changed files with 15 additions and 3 deletions

View file

@ -10,6 +10,16 @@ class RepositoryReference(datatype('Repository', [])):
return RepositoryReference(db_id=repo_obj.id) return RepositoryReference(db_id=repo_obj.id)
class Label(datatype('Label', ['key', 'value'])):
""" Label represents a label on a manifest. """
@classmethod
def for_label(cls, label):
if label is None:
return None
return Label(db_id=label.id, key=label.key, value=label.value)
class Tag(datatype('Tag', ['name'])): class Tag(datatype('Tag', ['name'])):
""" Tag represents a tag in a repository, which points to a manifest or image. """ """ Tag represents a tag in a repository, which points to a manifest or image. """
@classmethod @classmethod

View file

@ -5,7 +5,7 @@ from collections import defaultdict
from data import database from data import database
from data import model from data import model
from data.registry_model.interface import RegistryDataInterface from data.registry_model.interface import RegistryDataInterface
from data.registry_model.datatypes import Tag, RepositoryReference, Manifest, LegacyImage from data.registry_model.datatypes import Tag, RepositoryReference, Manifest, LegacyImage, Label
class PreOCIModel(RegistryDataInterface): class PreOCIModel(RegistryDataInterface):
@ -60,9 +60,11 @@ class PreOCIModel(RegistryDataInterface):
try: try:
tag_manifest = database.TagManifest.get(id=manifest._db_id) tag_manifest = database.TagManifest.get(id=manifest._db_id)
except database.TagManifest.DoesNotExist: except database.TagManifest.DoesNotExist:
return return None
model.label.create_manifest_label(tag_manifest, key, value, source_type_name, media_type_name) label = model.label.create_manifest_label(tag_manifest, key, value, source_type_name,
media_type_name)
return Label.for_label(label)
def get_legacy_images(self, repository_ref): def get_legacy_images(self, repository_ref):
""" """