Refactor: Dynamically Set Start Date & Enhance Credential Validation #34
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request makes several improvements to the audit export client:
Dynamic Start Date:
The start date is now automatically calculated as 30 days before the current UTC time instead of a hard-coded static date. This change ensures that the script always fetches recent audit data without requiring manual updates to the configuration.
Enhanced Configuration Loading:
The configuration loader now checks for file existence, emptiness, and preserves key casing. It logs clear error messages if any required keys (API_TOKEN and API_TOKEN_ID) are missing or empty.
Improved Credential Validation:
The credential validation function has been updated to use the dynamically calculated start date (or a fixed date window based on it) so that the request parameters (query string and headers) are consistent. This helps ensure that the signature is generated correctly and prevents misleading 403 responses.
Robust Error Handling & Logging:
The script now logs detailed messages during retries and stops further retries immediately for 403 errors. A global error flag or immediate exception raising can be implemented to prevent false success messages when errors occur.
Terminal Print Message:
Commented the print statement displayed at the end of the script execution. This will provide a cleaner terminal. Once uncommented, the print statements also provides clearer guidance on locating the audit log. The updated message now explicitly instructs users to check the audit_output path and ensures they understand that the audit data corresponds with the date file.
These changes improve the flexibility and robustness of the audit export client, making it easier to maintain and ensuring that only valid credentials are used to fetch data.