Skip to content

Commit

Permalink
access_token logic changed
Browse files Browse the repository at this point in the history
  • Loading branch information
baminou committed Feb 7, 2019
1 parent 59feceb commit 1f19f3a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
7 changes: 4 additions & 3 deletions libraries/sing/sing/operations/publish/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from ...operation_types.SingOperationType import Singoperationtype
import requests
import os
import json

class Publish(Singoperationtype):

Expand All @@ -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()
7 changes: 4 additions & 3 deletions libraries/sing/sing/operations/save/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from ...operation_types.SingOperationType import Singoperationtype
import requests
import os
import json

class Save(Singoperationtype):

Expand All @@ -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()
12 changes: 3 additions & 9 deletions libraries/sing/sing/operations/upload/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'))

0 comments on commit 1f19f3a

Please sign in to comment.