diff --git a/libraries/sing/sing/operations/publish/__init__.py b/libraries/sing/sing/operations/publish/__init__.py index f5cd72b..1ba3215 100644 --- a/libraries/sing/sing/operations/publish/__init__.py +++ b/libraries/sing/sing/operations/publish/__init__.py @@ -2,6 +2,7 @@ from ...operation_types.SingOperationType import Singoperationtype import requests import os +import json class Publish(Singoperationtype): @@ -14,18 +15,18 @@ def description(): return "Publish an analysis" def _parser(self, main_parser): - main_parser.add_argument('access_token_variable', help="Access token global variable name") + main_parser.add_argument('access_token', help="Access token variable") main_parser.add_argument('study', help="ICGC study ID") main_parser.add_argument('analysis_id', help="Analysis ID") return def _run(self): - access_token = os.environ.get(self.args.access_token_variable) + access_token = self.args.access_token response = requests.put('%s/studies/%s/analysis/publish/%s' % (self.song_server,self.args.study,self.args.analysis_id),headers={'Authorization':'Bearer '+access_token,'Content-Type':'application/json','Accept':'application/json'}) if not response.status_code == 201: raise Exception(response.json().get('message')) - print(response.json()) + print(json.dump(response.json())) return response.json() \ No newline at end of file diff --git a/libraries/sing/sing/operations/save/__init__.py b/libraries/sing/sing/operations/save/__init__.py index 8923f48..5a4f28c 100644 --- a/libraries/sing/sing/operations/save/__init__.py +++ b/libraries/sing/sing/operations/save/__init__.py @@ -2,6 +2,7 @@ from ...operation_types.SingOperationType import Singoperationtype import requests import os +import json class Save(Singoperationtype): @@ -14,15 +15,15 @@ def description(): return "Save a SONG upload ID." def _parser(self, main_parser): - main_parser.add_argument('access_token_variable', help="Access token global variable name") + main_parser.add_argument('access_token', help="SONG access token") main_parser.add_argument('study', help="ICGC study ID") main_parser.add_argument('upload_id', help="Upload ID") return def _run(self): - access_token = os.environ.get(self.args.access_token_variable) + access_token = self.args.access_token response = requests.post('%s/upload/%s/save/%s' % (self.song_server, self.args.study,self.args.upload_id),headers={'Authorization':'Bearer '+access_token}) if not response.status_code >= 200 and not response.status_code <=204: raise Exception(response.text) - print(response.json()) + print(json.dumps(response.json())) return response.json() \ No newline at end of file diff --git a/libraries/sing/sing/operations/upload/__init__.py b/libraries/sing/sing/operations/upload/__init__.py index ae93375..c0af95c 100644 --- a/libraries/sing/sing/operations/upload/__init__.py +++ b/libraries/sing/sing/operations/upload/__init__.py @@ -17,26 +17,20 @@ def description(): return "Upload json payload to song" def _parser(self, main_parser): - main_parser.add_argument('access_token_variable', help="Access token global variable name") + main_parser.add_argument('access_token', help="SONG access token") main_parser.add_argument('study', help="ICGC study ID") main_parser.add_argument('payload', type=argparse.FileType('r'), help="Path to payload.json") return - def _before_start(self): - super(Upload,self)._before_start() - if not os.environ.get(self.args.access_token_variable): - raise Exception("Your environment does not contain variable: %s" % (self.args.access_token_variable)) - return True - def _run(self): - access_token = os.environ.get(self.args.access_token_variable) + access_token = self.args.access_token headers={'Authorization':'Bearer '+access_token,'Content-Type':'application/json','Accept':'application/json'} payload = json.dumps(json.load(self.args.payload)) response = requests.post('%s/upload/%s' % (self.args.song_server,self.args.study),data=payload,headers=headers) if response.status_code == 200: - print(response.json()) + print(json.dumps(response.json())) return response.json() else: raise Exception(response.json().get('message')) \ No newline at end of file