Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean the netrc output format for the new "account" item #334

Merged
merged 3 commits into from
Apr 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion solvebio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ def login(**kwargs):
api_host = creds[0]
if creds[2] == 'Bearer':
access_token = creds[3]
elif creds[2] in [None, 'Token']:
else:
# By default, assume it is an API key.
api_key = creds[3]

# Always update the client host, version and agent
Expand Down
7 changes: 1 addition & 6 deletions solvebio/cli/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,8 @@ def save(self, path):
rep = rep + "machine " + host + "\n\tlogin " \
+ six.text_type(attrs[0]) + "\n"
if attrs[1]:
rep = rep + "account " + six.text_type(attrs[1])
rep = rep + "\taccount " + six.text_type(attrs[1]) + "\n"
rep = rep + "\tpassword " + six.text_type(attrs[2]) + "\n"
for macro in self.macros.keys():
rep = rep + "macdef " + macro + "\n"
for line in self.macros[macro]:
rep = rep + line
rep = rep + "\n"

f = open(path, 'w')
f.write(rep)
Expand Down
52 changes: 17 additions & 35 deletions solvebio/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,49 +33,31 @@ def __init__(self, message=None, response=None):
'API Response (%d): %s'
% (self.status_code, self.json_body))
except:
self.json_body = ''
logger.debug(
'API Response (%d): Response does not contain JSON.'
% self.status_code)

if self.status_code == 400:
self.message = 'Bad Request'
self.message = 'Bad Request ({})'.format(response.url)
elif response.status_code == 401:
self.message = '401 Unauthorized'
self.message = '401 Unauthorized ({})'.format(response.url)
elif response.status_code == 403:
self.message = '403 Forbidden'
self.message = '403 Forbidden ({})'.format(response.url)
elif response.status_code == 404:
self.message = '404 Not Found'

if 'detail' in self.json_body:
self.message = '%s' % self.json_body['detail']
del self.json_body['detail']

if 'non_field_errors' in self.json_body:
self.message = '%s' % \
', '.join(self.json_body['non_field_errors'])
del self.json_body['non_field_errors']

if self.json_body:
self.message += ' %s' % self.json_body

# TODO
# NOTE there are other keys that exist in some Errors that
# are not detail or non_field_errors. For instance 'manifest'
# is a key if uploading using a manifest with invalid file format.
# It includes a very useful error message that gets lost.
# Is there harm in just handling any error key here?
# (handle keys with list values and those without)
# Implementation below
#
# for k, v in self.json_body:
# if isinstance(v, list):
# self.message += ' %s Errors: %s' % \
# (k, ', '.join(self.json_body[k]))
# else:
# self.message += ' %s Errors: %s' % \
# (k, self.json_body[k])
# del self.json_body[k]
self.message = '404 Not Found ({})'.format(response.url)

# Handle other keys
for k, v in self.json_body.items():
if k in ["non_field_errors"]:
self.message += '\nError: '
else:
self.message += '\nError (%s): ' % k

if isinstance(v, list):
self.message += ', '.join(self.json_body[k])
else:
self.message += self.json_body[k]
del self.json_body[k]

def __str__(self):
return self.message