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

fix(weave): netrc entry handling in Weave JS SDK login method #3069

Merged
merged 4 commits into from
Nov 26, 2024

Conversation

thanos-wandb
Copy link
Contributor

@thanos-wandb thanos-wandb commented Nov 25, 2024

Description

This PR resolves an issue in the Weave JS SDK's login method where the .netrc file was being modified or created incorrectly if the apiKey arg was empty.

Changes:

  • Added a validation check to ensure the apiKey is provided and non-empty
  • Throws an error if the apiKey is missing
  • Prevents overwriting existing .netrc entries unless both host and apiKey are valid and non-empty

Key fixes:

  • Ensures that .netrc entries remain intact and prevent removal of the password line for existing entries
  • Avoids introducing extra blank lines between machine blocks in the .netrc file

Testing

To reproduce the issue:

  • Start with an existing .netrc file containing valid machine entries
  • Execute the following JS script where login method is missing the apiKey arg
import * as weave from 'weave';
async function main() {
    await weave.login()
    await weave.init('examples');
    console.log('Hello there, Weave JS');
}
main().catch(console.error);
  • The .netrc file gets modified incorrectly (password line of api.wandb.ai is removed and blank lines are introduced between machine blocks)

Fix testing:

  • Verified that .netrc won't be created, if doesn't already exist, and no apiKey is provided
  • Verified that previous valid entries in .netrc remain intact when weave.login() is invoked

@thanos-wandb thanos-wandb requested a review from a team as a code owner November 25, 2024 10:55
@thanos-wandb thanos-wandb changed the title Fix netrc entry handling in Weave JS SDK login method fix(weave): netrc entry handling in Weave JS SDK login method Nov 25, 2024
@circle-job-mirror
Copy link

circle-job-mirror bot commented Nov 25, 2024

@thanos-wandb thanos-wandb self-assigned this Nov 25, 2024
@@ -24,6 +24,9 @@ export async function login(apiKey: string, host?: string) {
console.warn('No host provided, using default host:', defaultHost);
host = defaultHost;
}
if (!apiKey) {
Copy link
Collaborator

@andrewtruong andrewtruong Nov 25, 2024

Choose a reason for hiding this comment

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

This is specifically for apiKey === ''?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@andrewtruong yes if apiKey is either null or not provided at all as an arg

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think apiKey is required

Copy link
Contributor Author

@thanos-wandb thanos-wandb Nov 25, 2024

Choose a reason for hiding this comment

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

I think there was no validation in place to enforce this requirement at runtime before, but should raise an error now by adding that !apiKey check. I had tested with this script:

import * as weave from 'weave';
async function main() {
    await weave.login()
    await weave.init('examples');
    console.log('Hello there, Weave JS');
}
main().catch(console.error);

@thanos-wandb thanos-wandb merged commit 7cadf0c into master Nov 26, 2024
116 checks passed
@thanos-wandb thanos-wandb deleted the fix-netrc branch November 26, 2024 10:17
@github-actions github-actions bot locked and limited conversation to collaborators Nov 26, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants