Remove Link class
This patch removes the link class since there is no need of class and link can be created by method only. This patch also removes the old validation methods which were done prior to JSONSchema. Partially-Implements: BP api-json-input-validation Change-Id: I20a307fe83c54912ccf3d92d6b47e97ffeeec121
This commit is contained in:
parent
17331e9f5a
commit
c2a2359de4
@ -15,9 +15,6 @@
|
||||
|
||||
import pecan
|
||||
|
||||
from zun.api.controllers import base
|
||||
from zun.api.controllers import types
|
||||
|
||||
|
||||
def build_url(resource, resource_args, bookmark=False, base_url=None):
|
||||
if base_url is None:
|
||||
@ -31,34 +28,11 @@ def build_url(resource, resource_args, bookmark=False, base_url=None):
|
||||
return template % {'url': base_url, 'res': resource, 'args': resource_args}
|
||||
|
||||
|
||||
class Link(base.APIBase):
|
||||
"""A link representation."""
|
||||
|
||||
fields = {
|
||||
'href': {
|
||||
'validate': types.Text.validate
|
||||
},
|
||||
'rel': {
|
||||
'validate': types.Text.validate
|
||||
},
|
||||
'type': {
|
||||
'validate': types.Text.validate
|
||||
},
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
def make_link(rel_name, url, resource, resource_args,
|
||||
bookmark=False, type=None):
|
||||
href = build_url(resource, resource_args,
|
||||
bookmark=bookmark, base_url=url)
|
||||
if type is None:
|
||||
return Link(href=href, rel=rel_name)
|
||||
else:
|
||||
return Link(href=href, rel=rel_name, type=type)
|
||||
|
||||
@classmethod
|
||||
def sample(cls):
|
||||
sample = cls(href="http://localhost:8080/containers/"
|
||||
"eaaca217-e7d8-47b4-bb41-3f99f20eed89",
|
||||
rel="bookmark")
|
||||
return sample
|
||||
def make_link(rel_name, url, resource, resource_args,
|
||||
bookmark=False, type=None):
|
||||
href = build_url(resource, resource_args,
|
||||
bookmark=bookmark, base_url=url)
|
||||
if type is None:
|
||||
return {'href': href, 'rel': rel_name}
|
||||
else:
|
||||
return {'href': href, 'rel': rel_name, 'type': type}
|
||||
|
@ -15,47 +15,34 @@ from pecan import rest
|
||||
|
||||
from zun.api.controllers import base
|
||||
from zun.api.controllers import link
|
||||
from zun.api.controllers import types
|
||||
from zun.api.controllers import v1
|
||||
|
||||
|
||||
class Version(base.APIBase):
|
||||
"""An API version representation."""
|
||||
|
||||
fields = {
|
||||
'id': {
|
||||
'validate': types.Text.validate
|
||||
},
|
||||
'links': {
|
||||
'validate': types.List(types.Custom(link.Link)).validate
|
||||
},
|
||||
}
|
||||
fields = (
|
||||
'id',
|
||||
'links',
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def convert(id):
|
||||
version = Version()
|
||||
version.id = id
|
||||
version.links = [link.Link.make_link('self', pecan.request.host_url,
|
||||
id, '', bookmark=True)]
|
||||
version.links = [link.make_link('self', pecan.request.host_url,
|
||||
id, '', bookmark=True)]
|
||||
return version
|
||||
|
||||
|
||||
class Root(base.APIBase):
|
||||
|
||||
fields = {
|
||||
'id': {
|
||||
'validate': types.Text.validate
|
||||
},
|
||||
'description': {
|
||||
'validate': types.Text.validate
|
||||
},
|
||||
'versions': {
|
||||
'validate': types.List(types.Custom(Version)).validate
|
||||
},
|
||||
'default_version': {
|
||||
'validate': types.Custom(Version).validate
|
||||
},
|
||||
}
|
||||
fields = (
|
||||
'id',
|
||||
'description',
|
||||
'versions',
|
||||
'default_version',
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def convert():
|
||||
|
@ -24,7 +24,6 @@ from pecan import rest
|
||||
|
||||
from zun.api.controllers import base as controllers_base
|
||||
from zun.api.controllers import link
|
||||
from zun.api.controllers import types
|
||||
from zun.api.controllers.v1 import containers as container_controller
|
||||
from zun.api.controllers.v1 import images as image_controller
|
||||
from zun.api.controllers.v1 import zun_services
|
||||
@ -35,71 +34,55 @@ LOG = logging.getLogger(__name__)
|
||||
class MediaType(controllers_base.APIBase):
|
||||
"""A media type representation."""
|
||||
|
||||
fields = {
|
||||
'base': {
|
||||
'validate': types.Text.validate
|
||||
},
|
||||
'type': {
|
||||
'validate': types.Text.validate
|
||||
},
|
||||
}
|
||||
fields = (
|
||||
'base',
|
||||
'type',
|
||||
)
|
||||
|
||||
|
||||
class V1(controllers_base.APIBase):
|
||||
"""The representation of the version 1 of the API."""
|
||||
|
||||
fields = {
|
||||
'id': {
|
||||
'validate': types.Text.validate
|
||||
},
|
||||
'media_types': {
|
||||
'validate': types.List(types.Custom(MediaType)).validate
|
||||
},
|
||||
'links': {
|
||||
'validate': types.List(types.Custom(link.Link)).validate
|
||||
},
|
||||
'services': {
|
||||
'validate': types.List(types.Custom(link.Link)).validate
|
||||
},
|
||||
'containers': {
|
||||
'validate': types.List(types.Custom(link.Link)).validate
|
||||
},
|
||||
'images': {
|
||||
'validate': types.List(types.Custom(link.Link)).validate
|
||||
},
|
||||
}
|
||||
fields = (
|
||||
'id',
|
||||
'media_types',
|
||||
'links',
|
||||
'services',
|
||||
'containers',
|
||||
'images'
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def convert():
|
||||
v1 = V1()
|
||||
v1.id = "v1"
|
||||
v1.links = [link.Link.make_link('self', pecan.request.host_url,
|
||||
'v1', '', bookmark=True),
|
||||
link.Link.make_link('describedby',
|
||||
'http://docs.openstack.org',
|
||||
'developer/zun/dev',
|
||||
'api-spec-v1.html',
|
||||
bookmark=True, type='text/html')]
|
||||
v1.links = [link.make_link('self', pecan.request.host_url,
|
||||
'v1', '', bookmark=True),
|
||||
link.make_link('describedby',
|
||||
'http://docs.openstack.org',
|
||||
'developer/zun/dev',
|
||||
'api-spec-v1.html',
|
||||
bookmark=True, type='text/html')]
|
||||
v1.media_types = [MediaType(base='application/json',
|
||||
type='application/vnd.openstack.zun.v1+json')]
|
||||
v1.services = [link.Link.make_link('self', pecan.request.host_url,
|
||||
'services', ''),
|
||||
link.Link.make_link('bookmark',
|
||||
pecan.request.host_url,
|
||||
'services', '',
|
||||
bookmark=True)]
|
||||
v1.containers = [link.Link.make_link('self', pecan.request.host_url,
|
||||
'containers', ''),
|
||||
link.Link.make_link('bookmark',
|
||||
pecan.request.host_url,
|
||||
'containers', '',
|
||||
bookmark=True)]
|
||||
v1.images = [link.Link.make_link('self', pecan.request.host_url,
|
||||
'images', ''),
|
||||
link.Link.make_link('bookmark',
|
||||
pecan.request.host_url,
|
||||
'images', '',
|
||||
bookmark=True)]
|
||||
v1.services = [link.make_link('self', pecan.request.host_url,
|
||||
'services', ''),
|
||||
link.make_link('bookmark',
|
||||
pecan.request.host_url,
|
||||
'services', '',
|
||||
bookmark=True)]
|
||||
v1.containers = [link.make_link('self', pecan.request.host_url,
|
||||
'containers', ''),
|
||||
link.make_link('bookmark',
|
||||
pecan.request.host_url,
|
||||
'containers', '',
|
||||
bookmark=True)]
|
||||
v1.images = [link.make_link('self', pecan.request.host_url,
|
||||
'images', ''),
|
||||
link.make_link('bookmark',
|
||||
pecan.request.host_url,
|
||||
'images', '',
|
||||
bookmark=True)]
|
||||
return v1
|
||||
|
||||
|
||||
|
@ -44,5 +44,5 @@ class Collection(base.APIBase):
|
||||
'args': q_args, 'limit': limit,
|
||||
'marker': self.collection[-1].uuid}
|
||||
|
||||
return link.Link.make_link('next', pecan.request.host_url,
|
||||
resource_url, next_args).href
|
||||
return link.make_link('next', pecan.request.host_url,
|
||||
resource_url, next_args).href
|
||||
|
@ -44,9 +44,9 @@ def format_container(url, container):
|
||||
return
|
||||
if key == 'uuid':
|
||||
yield ('uuid', value)
|
||||
yield ('links', [link.Link.make_link(
|
||||
yield ('links', [link.make_link(
|
||||
'self', url, 'containers', value),
|
||||
link.Link.make_link(
|
||||
link.make_link(
|
||||
'bookmark', url,
|
||||
'containers', value,
|
||||
bookmark=True)])
|
||||
|
@ -30,9 +30,9 @@ def format_image(url, image):
|
||||
return
|
||||
if key == 'uuid':
|
||||
yield ('uuid', value)
|
||||
yield ('links', [link.Link.make_link(
|
||||
yield ('links', [link.make_link(
|
||||
'self', url, 'images', value),
|
||||
link.Link.make_link(
|
||||
link.make_link(
|
||||
'bookmark', url,
|
||||
'images', value,
|
||||
bookmark=True)])
|
||||
|
@ -20,11 +20,11 @@ from zun.tests import base as test_base
|
||||
class TestLink(test_base.BaseTestCase):
|
||||
|
||||
def test_make_link(self):
|
||||
link = link_module.Link.make_link(
|
||||
link = link_module.make_link(
|
||||
'self', 'http://localhost:8080', 'v1', '',
|
||||
bookmark=True)
|
||||
|
||||
ordered_link = collections.OrderedDict(sorted(link.as_dict().items()))
|
||||
ordered_link = collections.OrderedDict(sorted(link.items()))
|
||||
expected_value = collections.OrderedDict([
|
||||
('href', 'http://localhost:8080/v1/'),
|
||||
('rel', 'self')
|
||||
|
Loading…
x
Reference in New Issue
Block a user