Moved genomespace token to environment variable

This commit is contained in:
Nuwan Goonasekera
2017-08-19 00:38:08 +05:30
parent 46dc4a252c
commit 3e8bf3c4e7
4 changed files with 24 additions and 13 deletions
+6 -3
View File
@@ -1,11 +1,13 @@
import argparse
import binascii
import os
import sys
from genomespaceclient import GenomeSpaceClient
def upload_to_genomespace(token, input_file, target_url):
token = token or os.environ.get('GS_TOKEN')
gs_client = GenomeSpaceClient(token=token)
gs_client.copy(input_file, target_url)
print("File successfully copied.")
@@ -13,12 +15,13 @@ def upload_to_genomespace(token, input_file, target_url):
def process_args(args):
parser = argparse.ArgumentParser()
parser.add_argument('-t', '--token', type=str,
help="GenomeSpace auth token", required=True)
parser.add_argument('-i', '--input_file', type=str,
help="File to export", required=True)
parser.add_argument('-o', '--target_url', type=str,
help="GenomeSpace output target folder location", required=True)
parser.add_argument('-t', '--token', type=str,
help="Optional OpenID/GenomeSpace token if not passed in as part of the URL as URLs^Token."
" If none, the environment variable GS_TOKEN will be respected.", required=False)
args = parser.parse_args(args[1:])
return args
@@ -26,7 +29,7 @@ def process_args(args):
def main():
args = process_args(sys.argv)
upload_to_genomespace(binascii.unhexlify(args.token).decode('utf-8'),
upload_to_genomespace(args.token,
binascii.unhexlify(args.input_file).decode('utf-8'),
binascii.unhexlify(args.target_url).decode('utf-8'))
+8 -5
View File
@@ -1,14 +1,18 @@
<?xml version="1.0"?>
<tool name="GenomeSpace Exporter" id="genomespace_exporter" version="0.0.5">
<description> - send data to GenomeSpace</description>
<environment_variables>
<environment_variable name="GS_TOKEN">
#set $token = $genomespace_browser.split('^')[1] or $__user__.preferences.get('genomespace_token', None)
#assert $token, Exception('Invalid token. You must be logged into GenomeSpace through OpenID or select a valid folder via the GenomeSpace browse dialog.')
$token
</environment_variable>
</environment_variables>
<command>python $__tool_directory__/genomespace_exporter.py
#set $target_folder = $genomespace_browser.split('^')[0]
#set $token = $genomespace_browser.split('^')[1] if '^' in $genomespace_browser and $genomespace_browser.split('^')[1] else $__user__.preferences.get('genomespace_token', None)
#assert $target_folder, Exception('You must select a valid target folder.')
#assert $token, Exception('Invalid token. You must be logged into GenomeSpace through OpenID or select a valid folder via the GenomeSpace browse dialog.')
#import binascii
--token '${ binascii.hexlify(str(token).encode("utf-8")) }'
--input_file '${ binascii.hexlify(str($input1).encode("utf8")) }'
#if $filename:
--target_url '${ binascii.hexlify(str($target_folder + "/" + str($filename)).encode("utf8") ) }'
@@ -18,7 +22,6 @@
</command>
<inputs>
<param format="data" name="input1" type="data" label="Send this dataset to GenomeSpace" />
<param name="base_url" type="baseurl" />
<!-- If using this tool through bioblend, the genomespace_browser parameter should contain the path to the GenomeSpaceFile + the security token
separated by a ^ as follows: GenomeSpaceFilePath^Token -->
<param name="genomespace_browser" type="genomespacefile" label="Choose Target Directory" select_type="FOLDER" />
+3 -2
View File
@@ -244,7 +244,8 @@ def process_args(args):
parser.add_argument('-c', '--data_conf', type=str,
help="Galaxy data types conf file for mapping file types", required=True)
parser.add_argument('-t', '--token', type=str,
help="Optional OpenID/GenomeSpace token if not passed in as part of the URL as URLs^Token", required=False)
help="Optional OpenID/GenomeSpace token if not passed in as part of the URL as URLs^Token."
" If none, the environment variable GS_TOKEN will be respected.", required=False)
args = parser.parse_args(args[1:])
return args
@@ -252,7 +253,7 @@ def process_args(args):
def main():
args = process_args(sys.argv)
download_from_genomespace_importer(args.json_parameter_file, args.galaxy_root, args.data_conf, args.token)
download_from_genomespace_importer(args.json_parameter_file, args.galaxy_root, args.data_conf, args.token or os.environ.get("GS_TOKEN"))
if __name__ == "__main__":
+7 -3
View File
@@ -1,16 +1,20 @@
<?xml version="1.0"?>
<tool name="GenomeSpace Push" id="genomespace_push" tool_type="data_source" force_history_refresh="True" hidden="True" display_interface="False" require_login="True" version="0.0.1">
<description> - Push data from GenomeSpace to Galaxy</description>
<environment_variables>
<environment_variable name="GS_TOKEN">
#set $token = $__user__.preferences.get( 'genomespace_token', None )
#assert $token, Exception('Invalid token. You must be logged into GenomeSpace through OpenID or select a valid file via the GenomeSpace browse dialog.' )
$token
</environment_variable>
</environment_variables>
<command interpreter="python">genomespace_importer.py
#set $input_file = $URL.split("^")[0] if "^" in $URL else $URL
#set $token = $__user__.preferences.get( 'genomespace_token', None )
#assert $input_file, Exception( 'You must select a valid input file.' )
#assert $token, Exception( 'Invalid token. You must be logged into GenomeSpace through OpenID or select a valid file via the GenomeSpace browse dialog.' )
--json_parameter_file '${output_file1}'
--galaxy_root $__root_dir__
--data_conf $__datatypes_config__
--token '${token}'
</command>
<!-- If using this tool through bioblend, the URL parameter should contain a comma separated list of GenomeSpace URLs -->
<inputs check_values="False">