Skip to content

Commit

Permalink
Try keyring in non-verbose mode. Close #523
Browse files Browse the repository at this point in the history
  • Loading branch information
frostming committed Jul 2, 2021
1 parent a9d2830 commit 3034516
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
1 change: 1 addition & 0 deletions news/523.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix the handling of auth prompting: will try keyring in non-verbose mode.
19 changes: 13 additions & 6 deletions pdm/models/auth.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from typing import Any, List
from typing import List, Optional, Tuple

import click
from pip._vendor.requests.models import Response

from pdm._types import Source
from pdm.exceptions import PdmException
Expand All @@ -20,13 +19,21 @@ class PdmBasicAuth(MultiDomainBasicAuth):
- It shows an error message when credentials are not provided or correect.
"""

def handle_401(self, resp: Response, **kwargs: Any) -> Response:
if resp.status_code == 401 and not self.prompting:
def __init__(
self, prompting: bool = True, index_urls: Optional[List[str]] = None
) -> None:
super().__init__(prompting=True, index_urls=index_urls)
self._real_prompting = prompting

def _prompt_for_password(
self, netloc: str
) -> Tuple[Optional[str], Optional[str], bool]:
if not self._real_prompting:
raise PdmException(
f"The credentials for {resp.request.url} are not provided or correct. "
f"The credentials for {netloc} are incorrect. "
"Please run the command with `-v` option."
)
return super().handle_401(resp, **kwargs)
return super()._prompt_for_password(netloc)

def _should_save_password_to_keyring(self) -> bool:
if keyring is None:
Expand Down

0 comments on commit 3034516

Please sign in to comment.