Rename oci_model to appr_model
This commit is contained in:
parent
f0d4841155
commit
6622f27c93
19 changed files with 222 additions and 171 deletions
|
@ -8,7 +8,7 @@ from cnr.models.package_base import PackageBase, manifest_media_type
|
|||
|
||||
from flask import request
|
||||
from app import storage
|
||||
from endpoints.appr.models_oci import model
|
||||
from endpoints.appr.models_cnr import model
|
||||
|
||||
|
||||
class Blob(BlobBase):
|
||||
|
|
|
@ -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()
|
|
@ -17,7 +17,7 @@ from auth.permissions import CreateRepositoryPermission, ModifyRepositoryPermiss
|
|||
from endpoints.appr import appr_bp, require_app_repo_read, require_app_repo_write
|
||||
from endpoints.appr.cnr_backend import Blob, Channel, Package, User
|
||||
from endpoints.appr.decorators import disallow_for_image_repository
|
||||
from endpoints.appr.models_oci import model
|
||||
from endpoints.appr.models_cnr import model
|
||||
from endpoints.decorators import anon_allowed, anon_protect
|
||||
from util.names import REPOSITORY_NAME_REGEX, TAG_REGEX
|
||||
|
||||
|
|
|
@ -6,13 +6,13 @@ from cnr.tests.conftest import *
|
|||
from cnr.tests.test_apiserver import BaseTestServer
|
||||
from cnr.tests.test_models import CnrTestModels
|
||||
|
||||
import data.oci_model.blob as oci_blob
|
||||
import data.appr_model.blob as oci_blob
|
||||
|
||||
from data.database import User
|
||||
from data.model import organization, user
|
||||
from endpoints.appr import registry # Needed to register the endpoint
|
||||
from endpoints.appr.cnr_backend import Channel, Package, QuayDB
|
||||
from endpoints.appr.models_oci import model as oci_app_model
|
||||
from endpoints.appr.models_cnr import model as oci_app_model
|
||||
|
||||
from test.fixtures import *
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import pytest
|
||||
from endpoints.appr.models_oci import _strip_sha256_header
|
||||
from endpoints.appr.models_cnr import _strip_sha256_header
|
||||
|
||||
|
||||
@pytest.mark.parametrize('digest,expected', [
|
||||
|
|
Reference in a new issue