Skip to content
This repository has been archived by the owner on Sep 17, 2021. It is now read-only.

Commit

Permalink
Adding token validation to CircleAPI class
Browse files Browse the repository at this point in the history
  • Loading branch information
particledecay committed Jul 13, 2016
1 parent 25904fb commit f408c30
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion circlecli.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,26 @@ def __init__(self, token):
Args:
token (str): the CircleCI API token (obtained at https://circleci.com/account/api)
"""
self._token = token
self._token = self._validate_token(token)
self._base_url = "https://circleci.com/api/v1"

def _validate_token(self, token):
"""Ensure the provided token is a valid CircleCI API token.
Args:
token (str): the CircleCI API token
Returns:
(str) a valid token
"""
if len(token) != 40:
raise ValueError(u"Invalid API token: {}".format(token))
try:
int(token, 16)
except ValueError:
raise ValueError(u"Invalid API token: {}".format(token))
return token

def _build_url(self, endpoint, params={}):
"""Return the full URL for the desired endpoint.
Expand Down

0 comments on commit f408c30

Please sign in to comment.