Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update RC files instead of overwriting them #652

Merged
merged 20 commits into from
Jul 12, 2024

Conversation

garlic-os
Copy link
Contributor

@garlic-os garlic-os commented Jun 10, 2024

Description

This changes the behavior RAiDER.models.credentials.check_api to only update the one set of credentials in a .netrc file pertinent to RAiDER's operation instead of overwriting the file.

Motivation and Context

Fixes issue #638 where other credentials in .netrc can be lost.

How Has This Been Tested?

Unit tests were added that excerise check_api for every supported weather model to ensure check_api is behaving correctly, and crucially, that it no longer modifies unrelated .netrc credentials.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • I have added an explanation of what your changes do and why you'd like us to include them.
  • I have written new tests for your core changes, as applicable.
  • I have successfully ran tests with your changes locally.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.

- autopep8
- Added type annotations where the language server wasn't inferring them
- Turned the check for api_filename into a guard clause
- Use a match statement in _check_envs where appropriate
- Refer to API credential files as rc files
- Switch non-const variable names to lowercase
Behavior of this function changed so that it will no longer overwrite .netrc. .netrc may contain more than one set of credentials, so we have to take care not to destroy them while updating the one relevant to RAiDER/GMAO. The more simple RC files that only ever hold one set of credentials will still just be overwritten, but now RAiDER will know when it's dealing with .netrc/GMAO and parse it and only replace the part that pertains to GMAO's host URL.
- test_credentials.py moved to credentials/test_createFile.py
- credentials/test_updateFalse.py: verifies behavior of credentials.check_api while update flag is False
- (STAR OF THE SHOW) credentials/test_updateTrue.py: verifies correct behavior while update flag is True, including that .netrc credentials are NOT CLOBBERED
- Reduces code redundancy
- Makes it trivial to add new models to the tests, and as such ERA5T and MERRA2 are now tested explicitly along with the others in the update flag tests
@garlic-os garlic-os marked this pull request as ready for review July 6, 2024 02:29
Copy link
Collaborator

@jlmaurer jlmaurer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jlmaurer jlmaurer requested a review from jhkennedy July 9, 2024 19:12
@jlmaurer
Copy link
Collaborator

jlmaurer commented Jul 9, 2024

@jhkennedy do you want to take a quick look at this before I merge?

@jlmaurer jlmaurer merged commit 701d788 into dbekaert:dev Jul 12, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants