From 2f0fdf5f91e906c96e593941aa3eb7c82782de1d Mon Sep 17 00:00:00 2001 From: Michael Hall Date: Wed, 10 Jul 2024 13:11:51 -0500 Subject: [PATCH 1/2] - Fixed mishandling of list response from the api and updated requirements. --- pylot/plugins/cumulus_api/main.py | 11 +++++------ requirements-dev.txt | 8 ++++---- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/pylot/plugins/cumulus_api/main.py b/pylot/plugins/cumulus_api/main.py index df505b6..a5fa262 100644 --- a/pylot/plugins/cumulus_api/main.py +++ b/pylot/plugins/cumulus_api/main.py @@ -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 diff --git a/requirements-dev.txt b/requirements-dev.txt index 8a99e45..7609991 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -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 From 0987d9e662ed911c3b39b30226d2385fd32f6e26 Mon Sep 17 00:00:00 2001 From: Michael Hall Date: Thu, 18 Jul 2024 11:38:26 -0500 Subject: [PATCH 2/2] - Error handling message will now only print if an error is generated and handled --- pylot/plugins/cumulus_api/main.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pylot/plugins/cumulus_api/main.py b/pylot/plugins/cumulus_api/main.py index a5fa262..191db1e 100644 --- a/pylot/plugins/cumulus_api/main.py +++ b/pylot/plugins/cumulus_api/main.py @@ -148,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: @@ -207,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