-
-
Notifications
You must be signed in to change notification settings - Fork 307
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
Support username and password from keyring #1734
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
from __future__ import annotations | ||
|
||
import keyring | ||
|
||
from hatch.utils.fs import Path | ||
|
||
|
||
|
@@ -44,12 +46,6 @@ def __get_password(self) -> str: | |
if password is not None: | ||
return password | ||
|
||
import keyring | ||
|
||
password = keyring.get_password(self._repo, self.username) | ||
if password is not None: | ||
return password | ||
|
||
if self._options['no_prompt']: | ||
self._app.abort('Missing required option: auth') | ||
|
||
|
@@ -62,6 +58,7 @@ def __get_username(self) -> str: | |
or self._repo_config.get('user') | ||
or self._read_pypirc() | ||
or self._read_previous_working_user_data() | ||
or self._read_keyring() | ||
) | ||
if username is not None: | ||
return username | ||
|
@@ -72,6 +69,14 @@ def __get_username(self) -> str: | |
self.__username_was_read = True | ||
return self._app.prompt(f"Username for '{self._repo_config['url']}' [__token__]") or '__token__' | ||
|
||
def _read_keyring(self) -> str | None: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this could also store the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are right, no need to run read the password again if we already have it. I pushed my changes. Thanks for the review |
||
creds = keyring.get_credential(self._repo, None) | ||
if not creds: | ||
return None | ||
self.__password = creds.password | ||
self.__password_was_read = True | ||
return creds.username | ||
|
||
def _read_previous_working_user_data(self) -> str | None: | ||
if self._pwu_path.is_file(): | ||
contents = self._pwu_path.read_text() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'm pretty sure @ofek prefers that to be imported only when it's needed in
_read_keyring
.