Skip to content
Snippets Groups Projects
Commit 7eb99cf1 authored by Harsha Kethineni's avatar Harsha Kethineni
Browse files

Download gear file endpoint added

parent 63ccb191
No related branches found
No related tags found
No related merge requests found
......@@ -143,7 +143,7 @@ endpoints = [
]),
route('/gears', GearsHandler),
route('/gears/temp', GearHandler, h='upload', m=['POST']),
route('/gears/temp/<cid:{cid}>', GearHandler, h='download', m=['GET']),
route('/gears/temp/<cid:{cid}>', GearHandler, h='download', m=['GET']),
prefix('/gears', [
route('/<:[^/]+>', GearHandler),
route('/<:[^/]+>/invocation', GearHandler, h='get_invocation'),
......
......@@ -3,10 +3,12 @@ API request handlers for the jobs module
"""
import bson
import json
import os
import StringIO
from jsonschema import ValidationError
from .. import upload
from .. import util
from ..auth import require_login, has_access
from ..dao import APIPermissionException
from ..dao.containerstorage import AcquisitionStorage
......@@ -73,7 +75,7 @@ class GearHandler(base.RequestHandler):
# Temporary Function
def upload(self):
"""Upload new gear file"""
"""Upload new gear tarball file"""
if not self.user_is_admin:
self.abort(403, 'Request requires admin')
......@@ -83,8 +85,18 @@ class GearHandler(base.RequestHandler):
# Temporary Function
def download(self, **kwargs):
"""Download gear tarball file"""
if not self.user_is_admin:
self.abort(403, 'Request requires admin')
dl_id = kwargs.pop('cid')
return {'_id':str(dl_id)}
gear = get_gear(dl_id)
hash_ = gear['hash']
filepath = os.path.join(config.get_item('persistent', 'data_path'), util.path_from_hash(hash_))
self.response.app_iter = open(filepath, 'rb')
self.response.headers['Content-Length'] = str(gear['size']) # must be set after setting app_iter
self.response.headers['Content-Type'] = 'application/octet-stream'
self.response.headers['Content-Disposition'] = 'attachment; filename="' + gear['filename'] + '"'
def post(self, _id):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment