Rename oci_model to appr_model

This commit is contained in:
Joseph Schorr 2018-05-23 17:08:00 -04:00
parent f0d4841155
commit 6622f27c93
19 changed files with 222 additions and 171 deletions

View file

@ -3,7 +3,7 @@ from collections import defaultdict
from datetime import datetime, timedelta
from auth.permissions import ReadRepositoryPermission
from data import model, oci_model
from data import model, appr_model
from endpoints.api.repository_models_interface import RepositoryDataInterface, RepositoryBaseElement, Repository, \
ApplicationRepository, ImageRepositoryRepository, Tag, Channel, Release, Count
@ -142,10 +142,9 @@ class PreOCIModel(RepositoryDataInterface):
repo.namespace_user.organization, repo.namespace_user.removed_tag_expiration_s, None, None,
False, False, False)
# Note: This is *temporary* code for the new OCI model stuff.
if base.kind_name == 'application':
channels = oci_model.channel.get_repo_channels(repo)
releases = oci_model.release.get_release_objs(repo)
channels = appr_model.channel.get_repo_channels(repo)
releases = appr_model.release.get_release_objs(repo)
releases_channels_map = defaultdict(list)
return ApplicationRepository(
base, [_create_channel(channel, releases_channels_map) for channel in channels], [

View file

@ -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):

View file

@ -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()

View file

@ -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

View file

@ -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 *

View file

@ -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', [