Skip to content

Commit

Permalink
Switch to defining get_password
Browse files Browse the repository at this point in the history
  • Loading branch information
judahrand committed Nov 9, 2022
1 parent 6ec0af5 commit f5c96b1
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions src/pip/_internal/network/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@ class Credentials(NamedTuple):
password: str


class KeyRingCredential(NamedTuple):
username: Optional[str]
password: str


class KeyRingCli:
"""Mirror the parts of keyring's API which pip uses
Expand All @@ -47,17 +42,14 @@ class KeyRingCli:
"""

@classmethod
def get_credential(
cls, service_name: str, username: Optional[str]
) -> Optional[KeyRingCredential]:
cmd = ["keyring", "get", service_name, str(username)]
def get_password(cls, service_name: str, username: str) -> Optional[str]:
cmd = ["keyring", "get", service_name, username]
res = subprocess.run(
cmd, capture_output=True, env=dict(PYTHONIOENCODING="utf-8")
)
if res.returncode:
return None
password = res.stdout.decode("utf-8").strip("\n")
return KeyRingCredential(username=username, password=password)
return res.stdout.decode("utf-8").strip("\n")

@classmethod
def set_password(cls, service_name: str, username: str, password: str) -> None:
Expand Down

0 comments on commit f5c96b1

Please sign in to comment.