|
|
|
@ -7,7 +7,7 @@ from cnr.exception import raise_package_not_found, raise_channel_not_found
|
|
|
|
|
import data.model
|
|
|
|
|
|
|
|
|
|
from app import storage, authentication
|
|
|
|
|
from data import oci_model
|
|
|
|
|
from data import appr_model
|
|
|
|
|
from data.database import Tag, Manifest, MediaType, Blob, Repository, Channel
|
|
|
|
|
from endpoints.appr.models_interface import (
|
|
|
|
|
ApplicationManifest, ApplicationRelease, ApplicationSummaryView, AppRegistryDataInterface,
|
|
|
|
@ -47,7 +47,7 @@ def _application(package):
|
|
|
|
|
return repo
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class OCIAppModel(AppRegistryDataInterface):
|
|
|
|
|
class CNRAppModel(AppRegistryDataInterface):
|
|
|
|
|
def log_action(self, event_name, namespace_name, repo_name=None, analytics_name=None,
|
|
|
|
|
analytics_sample=1, metadata=None):
|
|
|
|
|
metadata = {} if metadata is None else metadata
|
|
|
|
@ -70,7 +70,7 @@ class OCIAppModel(AppRegistryDataInterface):
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
views = []
|
|
|
|
|
for repo in oci_model.package.list_packages_query(namespace, media_type, search,
|
|
|
|
|
for repo in appr_model.package.list_packages_query(namespace, media_type, search,
|
|
|
|
|
username=username):
|
|
|
|
|
releases = [t.name for t in repo.tag_set_prefetch]
|
|
|
|
|
if not releases:
|
|
|
|
@ -81,7 +81,7 @@ class OCIAppModel(AppRegistryDataInterface):
|
|
|
|
|
if with_channels:
|
|
|
|
|
channels = [
|
|
|
|
|
ChannelView(name=chan.name, current=chan.linked_tag.name)
|
|
|
|
|
for chan in oci_model.channel.get_repo_channels(repo)]
|
|
|
|
|
for chan in appr_model.channel.get_repo_channels(repo)]
|
|
|
|
|
|
|
|
|
|
app_name = _join_package_name(repo.namespace_user.username, repo.name)
|
|
|
|
|
manifests = self.list_manifests(app_name, available_releases[0])
|
|
|
|
@ -137,7 +137,7 @@ class OCIAppModel(AppRegistryDataInterface):
|
|
|
|
|
Todo:
|
|
|
|
|
* Paginate
|
|
|
|
|
"""
|
|
|
|
|
return oci_model.release.get_releases(_application(package_name), media_type)
|
|
|
|
|
return appr_model.release.get_releases(_application(package_name), media_type)
|
|
|
|
|
|
|
|
|
|
def list_manifests(self, package_name, release=None):
|
|
|
|
|
""" Returns the list of all manifests of an Application.
|
|
|
|
@ -147,7 +147,7 @@ class OCIAppModel(AppRegistryDataInterface):
|
|
|
|
|
"""
|
|
|
|
|
try:
|
|
|
|
|
repo = _application(package_name)
|
|
|
|
|
return list(oci_model.manifest.get_manifest_types(repo, release))
|
|
|
|
|
return list(appr_model.manifest.get_manifest_types(repo, release))
|
|
|
|
|
except (Repository.DoesNotExist, Tag.DoesNotExist):
|
|
|
|
|
raise_package_not_found(package_name, release)
|
|
|
|
|
|
|
|
|
@ -157,7 +157,7 @@ class OCIAppModel(AppRegistryDataInterface):
|
|
|
|
|
"""
|
|
|
|
|
repo = _application(package_name)
|
|
|
|
|
try:
|
|
|
|
|
tag, manifest, blob = oci_model.release.get_app_release(repo, release, media_type)
|
|
|
|
|
tag, manifest, blob = appr_model.release.get_app_release(repo, release, media_type)
|
|
|
|
|
created_at = _timestamp_to_iso(tag.lifetime_start)
|
|
|
|
|
|
|
|
|
|
blob_descriptor = BlobDescriptor(digest=_strip_sha256_header(blob.digest),
|
|
|
|
@ -178,7 +178,7 @@ class OCIAppModel(AppRegistryDataInterface):
|
|
|
|
|
path = cnrblob.upload_url(cnrblob.digest)
|
|
|
|
|
locations = storage.preferred_locations
|
|
|
|
|
storage.stream_write(locations, path, fp, 'application/x-gzip')
|
|
|
|
|
db_blob = oci_model.blob.get_or_create_blob(cnrblob.digest, cnrblob.size, content_media_type,
|
|
|
|
|
db_blob = appr_model.blob.get_or_create_blob(cnrblob.digest, cnrblob.size, content_media_type,
|
|
|
|
|
locations)
|
|
|
|
|
return BlobDescriptor(mediaType=content_media_type,
|
|
|
|
|
digest=_strip_sha256_header(db_blob.digest), size=db_blob.size, urls=[])
|
|
|
|
@ -193,7 +193,7 @@ class OCIAppModel(AppRegistryDataInterface):
|
|
|
|
|
repo = data.model.repository.get_or_create_repository(ns, name, user, visibility=visibility,
|
|
|
|
|
repo_kind='application')
|
|
|
|
|
tag_name = package.release
|
|
|
|
|
oci_model.release.create_app_release(repo, tag_name,
|
|
|
|
|
appr_model.release.create_app_release(repo, tag_name,
|
|
|
|
|
package.manifest(), manifest['content']['digest'], force)
|
|
|
|
|
|
|
|
|
|
def delete_release(self, package_name, release, media_type):
|
|
|
|
@ -202,7 +202,7 @@ class OCIAppModel(AppRegistryDataInterface):
|
|
|
|
|
"""
|
|
|
|
|
repo = _application(package_name)
|
|
|
|
|
try:
|
|
|
|
|
oci_model.release.delete_app_release(repo, release, media_type)
|
|
|
|
|
appr_model.release.delete_app_release(repo, release, media_type)
|
|
|
|
|
except (Channel.DoesNotExist, Tag.DoesNotExist, MediaType.DoesNotExist):
|
|
|
|
|
raise_package_not_found(package_name, release, media_type)
|
|
|
|
|
|
|
|
|
@ -213,7 +213,7 @@ class OCIAppModel(AppRegistryDataInterface):
|
|
|
|
|
def channel_exists(self, package_name, channel_name):
|
|
|
|
|
""" Returns true if channel exists """
|
|
|
|
|
repo = _application(package_name)
|
|
|
|
|
return oci_model.tag.tag_exists(repo, channel_name, "channel")
|
|
|
|
|
return appr_model.tag.tag_exists(repo, channel_name, "channel")
|
|
|
|
|
|
|
|
|
|
def delete_channel(self, package_name, channel_name):
|
|
|
|
|
""" Delete an AppChannel
|
|
|
|
@ -222,14 +222,14 @@ class OCIAppModel(AppRegistryDataInterface):
|
|
|
|
|
"""
|
|
|
|
|
repo = _application(package_name)
|
|
|
|
|
try:
|
|
|
|
|
oci_model.channel.delete_channel(repo, channel_name)
|
|
|
|
|
appr_model.channel.delete_channel(repo, channel_name)
|
|
|
|
|
except (Channel.DoesNotExist, Tag.DoesNotExist):
|
|
|
|
|
raise_channel_not_found(package_name, channel_name)
|
|
|
|
|
|
|
|
|
|
def list_channels(self, package_name):
|
|
|
|
|
""" Returns all AppChannel for a package """
|
|
|
|
|
repo = _application(package_name)
|
|
|
|
|
channels = oci_model.channel.get_repo_channels(repo)
|
|
|
|
|
channels = appr_model.channel.get_repo_channels(repo)
|
|
|
|
|
return [ChannelView(name=chan.name, current=chan.linked_tag.name) for chan in channels]
|
|
|
|
|
|
|
|
|
|
def fetch_channel(self, package_name, channel_name, with_releases=True):
|
|
|
|
@ -237,12 +237,12 @@ class OCIAppModel(AppRegistryDataInterface):
|
|
|
|
|
repo = _application(package_name)
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
channel = oci_model.channel.get_channel(repo, channel_name)
|
|
|
|
|
channel = appr_model.channel.get_channel(repo, channel_name)
|
|
|
|
|
except (Channel.DoesNotExist, Tag.DoesNotExist):
|
|
|
|
|
raise_channel_not_found(package_name, channel_name)
|
|
|
|
|
|
|
|
|
|
if with_releases:
|
|
|
|
|
releases = oci_model.channel.get_channel_releases(repo, channel)
|
|
|
|
|
releases = appr_model.channel.get_channel_releases(repo, channel)
|
|
|
|
|
chanview = ChannelReleasesView(
|
|
|
|
|
current=channel.linked_tag.name, name=channel.name,
|
|
|
|
|
releases=[channel.linked_tag.name] + [c.name for c in releases])
|
|
|
|
@ -254,7 +254,7 @@ class OCIAppModel(AppRegistryDataInterface):
|
|
|
|
|
def list_release_channels(self, package_name, release, active=True):
|
|
|
|
|
repo = _application(package_name)
|
|
|
|
|
try:
|
|
|
|
|
channels = oci_model.channel.get_tag_channels(repo, release, active=active)
|
|
|
|
|
channels = appr_model.channel.get_tag_channels(repo, release, active=active)
|
|
|
|
|
return [ChannelView(name=c.name, current=c.linked_tag.name) for c in channels]
|
|
|
|
|
except (Channel.DoesNotExist, Tag.DoesNotExist):
|
|
|
|
|
raise_package_not_found(package_name, release)
|
|
|
|
@ -265,11 +265,11 @@ class OCIAppModel(AppRegistryDataInterface):
|
|
|
|
|
A new AppChannel with the release
|
|
|
|
|
"""
|
|
|
|
|
repo = _application(package_name)
|
|
|
|
|
channel = oci_model.channel.create_or_update_channel(repo, channel_name, release)
|
|
|
|
|
channel = appr_model.channel.create_or_update_channel(repo, channel_name, release)
|
|
|
|
|
return ChannelView(current=channel.linked_tag.name, name=channel.name)
|
|
|
|
|
|
|
|
|
|
def get_blob_locations(self, digest):
|
|
|
|
|
return oci_model.blob.get_blob_locations(digest)
|
|
|
|
|
return appr_model.blob.get_blob_locations(digest)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
model = OCIAppModel()
|
|
|
|
|
model = CNRAppModel()
|