Skip to content

Commit

Permalink
Changed response codes to HTTPStatus.<Conditions>
Browse files Browse the repository at this point in the history
  • Loading branch information
mrinal wahal committed Aug 26, 2019
1 parent c0805d0 commit 890174f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
14 changes: 7 additions & 7 deletions back-end/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,24 +46,24 @@ def login(self):

except errors.ServerError as e:
log('critical', e)
return (e, HTTPStatus(500))
return (e, HTTPStatus.INTERNAL_SERVER_ERROR)

if (
ensureKeys(self.GIN_TOKEN) and ensureSecrets(self.username)
):
return ({'token': self.GIN_TOKEN}, HTTPStatus(200))
return ({'token': self.GIN_TOKEN}, HTTPStatus.OK)
else:
return ('login failed', HTTPStatus(401))
return ('login failed', HTTPStatus.UNAUTHORIZED)

def logout(self):
user.username = None
user.GIN_TOKEN = None
user.DRONE_TOKEN = None

return ("logged out", HTTPStatus(200))
return ("logged out", HTTPStatus.OK)

def details(self):
return (userData(self.GIN_TOKEN), HTTPStatus(200))
return (userData(self.GIN_TOKEN), HTTPStatus.OK)

def run(self, request):

Expand All @@ -83,10 +83,10 @@ def run(self, request):
username=self.username
)
return ("Success: workflow pushed to {}".format(
request.json['repo']), HTTPStatus(200))
request.json['repo']), HTTPStatus.OK)

except errors.ServiceError as e:
return (e, HTTPStatus(500))
return (e, HTTPStatus.INTERNAL_SERVER_ERROR)

def repos(self):

Expand Down
14 changes: 7 additions & 7 deletions back-end/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,13 @@ def writeSecret(key, repo, user):
except Exception.ConnectionError as e:
raise ServerError(e)

if res.status_code == 200:
if res.status_code == HTTPStatus.OK:
log('debug', 'Secret installed in `{}`'.format(repo))
return True
else:
log('critical', res.json()['message'])
raise ServerError('Secret could not be installed in `{}`'.format(repo),
HTTPStatus(500))
HTTPStatus.INTERNAL_SERVER_ERROR)


def updateSecret(secret, data, user, repo):
Expand All @@ -129,12 +129,12 @@ def updateSecret(secret, data, user, repo):
"pull_request": False
})

if res.status_code == 200:
if res.status_code == HTTPStatus.OK:
log('debug', 'Secret updated in `{}`'.format(repo))
return True
else:
raise ServerError('Secret could not be updated in `{}`'.format(repo),
HTTPStatus(500))
HTTPStatus.INTERNAL_SERVER_ERROR)


def ensureSecrets(user):
Expand Down Expand Up @@ -175,7 +175,7 @@ def ensureSecrets(user):
repo=repo['name'],
user=user
)
break
break

log('debug', 'Secret not found in `{}`'.format(repo['name']))
writeSecret(key.read(), repo['name'], user)
Expand Down Expand Up @@ -227,7 +227,7 @@ def deleteKeysOnServer(token):
log('error', response.text)
raise ServerError(
"You'll have to manually delete the keys from the server.",
HTTPStatus(401))
HTTPStatus.SERVICE_UNAVAILABLE)


def ensureKeysOnLocal(path):
Expand Down Expand Up @@ -328,7 +328,7 @@ def ensureKeys(token):

except:
log('critical', 'Failed to ensure keys.')
raise ServerError('Cannot ensure keys.', HTTPStatus(500))
raise ServerError('Cannot ensure keys.', HTTPStatus.INTERNAL_SERVER_ERROR)


def getRepos(user, token):
Expand Down

0 comments on commit 890174f

Please sign in to comment.