Skip to content

Commit

Permalink
Merge pull request #42 from ghrcdaac/mlh0079-6463-list-output-fix
Browse files Browse the repository at this point in the history
 - Fixed mishandling of list response from the api and updated requir…
  • Loading branch information
sflynn-itsc authored Jul 18, 2024
2 parents 07c4fc2 + 0987d9e commit 537cd10
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
17 changes: 8 additions & 9 deletions pylot/plugins/cumulus_api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,14 @@ def main(action, target, output=None, **kwargs):
results = []
while True:
api_response = api_function(**kwargs)
api_response = error_handling(api_response, api_function, **kwargs)
record_count = api_response.get('meta', {}).get('count', 0)
api_results = api_response.get('results', [])
if api_results:
if isinstance(api_response, dict) and 'results' in api_response:
api_response = error_handling(api_response, api_function, **kwargs)
kwargs.update({'searchContext': api_response.get('meta', {}).get('searchContext', None)})
record_count = api_response.get('meta', {}).get('count', 0)
api_results = api_response.get('results', [])
results.extend(api_results[:limit - (len(results))])
if len(results) >= limit or len(results) >= record_count:
break
else:
kwargs.update({'searchContext': api_response.get('meta', {}).get('searchContext', None)})
else:
results = api_response
break
Expand All @@ -149,8 +148,9 @@ def main(action, target, output=None, **kwargs):
def error_handling(results, api_function, **kwargs):
ret = ''
if results.get('error', '') == 'Bad Request':
if 'Member must have length less than or equal to 8192' in results.get('message', ''):
print('Handling 8192 character limit error...')
error_message = results.get('message', '')
if 'Member must have length less than or equal to 8192' in error_message:
print(f'Handling error: {error_message}')
cli = boto3.client('s3')
stack_prefix = os.getenv('STACK_PREFIX')
if not stack_prefix:
Expand Down Expand Up @@ -208,5 +208,4 @@ def error_handling(results, api_function, **kwargs):
ec.put_targets(Rule=rule_name, Targets=res.get('Targets'))
else:
ret = results
print('Error handling complete')
return ret
8 changes: 4 additions & 4 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
mypy==0.961
flake8==3.8.4
pytest==7.1.2
coverage==6.4.1
mypy==1.10.1
flake8==7.1.0
pytest==8.2.2
coverage==7.5.4

0 comments on commit 537cd10

Please sign in to comment.