Skip to content

Commit

Permalink
Merge pull request #3033 from SEED-platform/refactor/better-token-end…
Browse files Browse the repository at this point in the history
…point

refactor(analysis): use BETTER token validation endpoint
  • Loading branch information
macintoshpie committed Dec 13, 2021
2 parents 0a5baa4 + b64d83a commit 78d220a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
7 changes: 3 additions & 4 deletions seed/analysis_pipelines/better/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,20 @@ class BETTERClient:
def __init__(self, token):
self._token = f'Token {token}'

def test_token(self):
def token_is_valid(self):
"""Returns true if token is valid
:return: bool
"""
# TODO: get BETTER to create a "token" endpoint for testing
url = f'{self.API_URL}/weathers/'
url = f'{self.API_URL}/verify_token'
headers = {
'accept': 'application/json',
'Authorization': self._token,
}

try:
response = requests.request("GET", url, headers=headers)
return response.status_code != 401
return response.status_code == 200
except Exception:
return False

Expand Down
3 changes: 1 addition & 2 deletions seed/analysis_pipelines/better/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ def _prepare_analysis(self, property_view_ids, start_analysis=False):

# ping BETTER to verify the token is valid
client = BETTERClient(organization.better_analysis_api_key)
success = client.test_token()
if not success:
if not client.token_is_valid():
message = 'Failed to communicate with BETTER. Please verify organization token is valid and try again.'
self.fail(message, logger)
raise AnalysisPipelineException(message)
Expand Down

0 comments on commit 78d220a

Please sign in to comment.