Implement repository API GET methods
* download logo * download application package * get ui definition Partially-implements blueprint murano-repository-api-v2 Change-Id: Ia5999d31aade808f1c1f2e3e3e0de8a41fe0bf4b
This commit is contained in:
parent
d591d98b5e
commit
6892ff379c
@ -172,6 +172,34 @@ class Controller(object):
|
||||
raise exc.HTTPServerError(msg)
|
||||
return package.to_dict()
|
||||
|
||||
def get_ui(self, req, package_id):
|
||||
package = db_api.package_get(package_id, req.context)
|
||||
return package.ui_definition
|
||||
|
||||
def get_logo(self, req, package_id):
|
||||
package = db_api.package_get(package_id, req.context)
|
||||
return package.logo
|
||||
|
||||
def download(self, req, package_id):
|
||||
package = db_api.package_get(package_id, req.context)
|
||||
return package.archive
|
||||
|
||||
def show_categories(self, req):
|
||||
categories = db_api.categories_list()
|
||||
return {"categories": [category.to_dict() for category in categories]}
|
||||
|
||||
|
||||
class PackageSerializer(wsgi.ResponseSerializer):
|
||||
def serialize(self, action_result, accept, action):
|
||||
if action == 'get_ui':
|
||||
accept = 'text/plain'
|
||||
elif action in ('download', 'get_logo'):
|
||||
accept = 'application/octet-stream'
|
||||
return super(PackageSerializer, self).serialize(action_result,
|
||||
accept,
|
||||
action)
|
||||
|
||||
|
||||
def create_resource():
|
||||
return wsgi.Resource(Controller())
|
||||
serializer = PackageSerializer()
|
||||
return wsgi.Resource(Controller(), serializer=serializer)
|
||||
|
@ -121,6 +121,10 @@ class API(wsgi.Router):
|
||||
conditions={'method': ['POST']})
|
||||
|
||||
catalog_resource = catalog.create_resource()
|
||||
mapper.connect('/catalog/packages/categories',
|
||||
controller=catalog_resource,
|
||||
action='show_categories',
|
||||
conditions={'method': ['GET']})
|
||||
mapper.connect('/catalog/packages/{package_id}',
|
||||
controller=catalog_resource,
|
||||
action='get',
|
||||
@ -137,4 +141,17 @@ class API(wsgi.Router):
|
||||
controller=catalog_resource,
|
||||
action='upload',
|
||||
conditions={'method': ['POST']})
|
||||
mapper.connect('/catalog/packages/{package_id}/ui',
|
||||
controller=catalog_resource,
|
||||
action='get_ui',
|
||||
conditions={'method': ['GET']})
|
||||
mapper.connect('/catalog/packages/{package_id}/logo',
|
||||
controller=catalog_resource,
|
||||
action='get_logo',
|
||||
conditions={'method': ['GET']})
|
||||
mapper.connect('/catalog/packages/{package_id}/download',
|
||||
controller=catalog_resource,
|
||||
action='download',
|
||||
conditions={'method': ['GET']})
|
||||
|
||||
super(API, self).__init__(mapper)
|
||||
|
@ -341,3 +341,8 @@ def package_upload(values, tenant_id):
|
||||
package.owner_id = tenant_id
|
||||
package.save(session)
|
||||
return package
|
||||
|
||||
|
||||
def categories_list():
|
||||
session = db_session.get_session()
|
||||
return session.query(models.Category).all()
|
||||
|
@ -561,6 +561,13 @@ class XMLDictSerializer(DictSerializer):
|
||||
return link_nodes
|
||||
|
||||
|
||||
class BlankSerializer(DictSerializer):
|
||||
"""Return raw data.
|
||||
"""
|
||||
def default(self, data):
|
||||
return data
|
||||
|
||||
|
||||
class ResponseHeadersSerializer(ActionDispatcher):
|
||||
"""Default response headers serialization"""
|
||||
|
||||
@ -578,6 +585,8 @@ class ResponseSerializer(object):
|
||||
self.body_serializers = {
|
||||
'application/xml': XMLDictSerializer(),
|
||||
'application/json': JSONDictSerializer(),
|
||||
'text/plain': BlankSerializer(),
|
||||
'application/octet-stream': BlankSerializer()
|
||||
}
|
||||
self.body_serializers.update(body_serializers or {})
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user