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: revert the handling of 403 and 404 #75

Merged
merged 5 commits into from
Oct 11, 2023
Merged

fix: revert the handling of 403 and 404 #75

merged 5 commits into from
Oct 11, 2023

Conversation

frostming
Copy link
Owner

@frostming frostming commented Oct 10, 2023

Signed-off-by: Frost Ming [email protected]

This PR reverts some changes made by #70 but uses a different way, so that:

Before sending request to the index, the credentials in netrc will be read to authenticate the request. And only when the request fails with 401 error, the keyring will be queried and then prompt in the console.

This means if your index returns 403 or even 404 on unauthorized requests, you must rely on the credentials provided via netrc. Otherwise the error response will be returned without any atttempt to load other credentials.

This behavior is also the same as pip.

Signed-off-by: Frost Ming <[email protected]>
Signed-off-by: Frost Ming <[email protected]>
Signed-off-by: Frost Ming <[email protected]>
Copy link
Contributor

@logangrado logangrado left a comment

Choose a reason for hiding this comment

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

It seems like we should target behavior where:

  • for any of 401, 403, 404, we attempt to get credentials from netrc (or other non-prompting methods)
  • If we still don't have credentials:
    • 401: prompt
    • 403/404: Error

However, if I understand this PR correctly, it looks like it doesn't do this. Instead:

  • it immediately errors out on 403/404 - no attempt to read netrc
  • Even for 401, we won't check netrc.

EDIT:

I totally missed that you're using the netrc for the initial request. I think this is a good solution. Ignore my comment above

@logangrado
Copy link
Contributor

logangrado commented Oct 10, 2023

I would only suggest that we add allow_netrc=True to this call here:

username, password = self._get_new_credentials(original_url)

That way we are not only relying on the default value in _get_new_credentials, but also encoding it here. This would make it clear that we always want to use netrc for the initial call.

Signed-off-by: Frost Ming <[email protected]>
@frostming
Copy link
Owner Author

it clear that we always want to use netrc for the initial call.

Good point, done.

@frostming frostming merged commit eca170d into main Oct 11, 2023
19 checks passed
@frostming frostming deleted the fix/handle-401 branch October 11, 2023 01:01
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.

unearth asks for the username whereas provided in the index url
2 participants