From 8536ca4315fdf09afb546f818ab09b1e6eb23282 Mon Sep 17 00:00:00 2001 From: John Chilton Date: Mon, 15 Dec 2014 00:20:35 -0500 Subject: [PATCH] Allow downloading index files via tool data API. This provides direct access to the files to admins - probably still wise to provide some mechanism to download a copressed archive of these files. --- lib/galaxy/webapps/galaxy/api/tool_data.py | 13 +++++++++++++ lib/galaxy/webapps/galaxy/buildapp.py | 1 + test/api/test_tool_data.py | 6 ++++++ 3 files changed, 20 insertions(+) diff --git a/lib/galaxy/webapps/galaxy/api/tool_data.py b/lib/galaxy/webapps/galaxy/api/tool_data.py index 24945481dbf..7646502e624 100644 --- a/lib/galaxy/webapps/galaxy/api/tool_data.py +++ b/lib/galaxy/webapps/galaxy/api/tool_data.py @@ -1,6 +1,9 @@ +import os + from galaxy import exceptions from galaxy import web from galaxy.web import _future_expose_api as expose_api +from galaxy.web import _future_expose_api_raw as expose_api_raw from galaxy.web.base.controller import BaseAPIController @@ -74,6 +77,16 @@ class ToolData( BaseAPIController ): """ return self._data_table_field( id, value ).to_dict() + @web.require_admin + @expose_api_raw + def download_field_file( self, trans, id, value, path, **kwds ): + field_value = self._data_table_field( id, value ) + base_dir = field_value.get_base_dir() + full_path = os.path.join( base_dir, path ) + if full_path not in field_value.get_files(): + raise exceptions.ObjectNotFound("No such path in data table field.") + return open(full_path, "r") + def _data_table_field( self, id, value ): out = self._data_table(id).get_field(value) if out is None: diff --git a/lib/galaxy/webapps/galaxy/buildapp.py b/lib/galaxy/webapps/galaxy/buildapp.py index afae14b7d27..7015b23627a 100644 --- a/lib/galaxy/webapps/galaxy/buildapp.py +++ b/lib/galaxy/webapps/galaxy/buildapp.py @@ -171,6 +171,7 @@ def populate_api_routes( webapp, app ): webapp.mapper.resource( 'dataset', 'datasets', path_prefix='/api' ) webapp.mapper.resource( 'tool_data', 'tool_data', path_prefix='/api' ) + webapp.mapper.connect( '/api/tool_data/{id:.+?}/fields/{value:.+?}/files/{path:.+?}', action='download_field_file', controller="tool_data" ) webapp.mapper.connect( '/api/tool_data/{id:.+?}/fields/{value:.+?}', action='show_field', controller="tool_data" ) webapp.mapper.resource( 'dataset_collection', 'dataset_collections', path_prefix='/api/') webapp.mapper.resource( 'sample', 'samples', path_prefix='/api' ) diff --git a/test/api/test_tool_data.py b/test/api/test_tool_data.py index f30d354dabc..f1f154a2eff 100644 --- a/test/api/test_tool_data.py +++ b/test/api/test_tool_data.py @@ -36,3 +36,9 @@ class ToolDataApiTestCase( api.ApiTestCase ): self._assert_has_keys( field, "files", "name", "fields", "fingerprint", "base_dir" ) files = field[ "files" ] assert len( files ) == 2 + + def test_download_field_file(self): + show_field_response = self._get( "tool_data/testalpha/fields/data1/files/entry.txt", admin=True ) + self._assert_status_code_is( show_field_response, 200 ) + content = show_field_response.content + assert content == "This is data 1.", content