Skip to content

Commit a0325b2

Browse files
committed
ssh client: implement password_auth_requested
1 parent 3e0917c commit a0325b2

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

src/scmrepo/git/backend/dulwich/asyncssh_vendor.py

+16-17
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ async def _read_all(read: Callable[[int], Coroutine], n: Optional[int] = None) -
4040
return b"".join(result)
4141

4242

43+
async def _getpass(*args, **kwargs) -> str:
44+
from getpass import getpass
45+
46+
return await asyncio.to_thread(getpass, *args, **kwargs)
47+
48+
4349
class _StderrWrapper:
4450
def __init__(self, stderr: "SSHReader", loop: asyncio.AbstractEventLoop) -> None:
4551
self.stderr = stderr
@@ -202,8 +208,6 @@ async def public_key_auth_requested( # noqa: C901
202208
return None
203209

204210
async def _read_private_key_interactive(self, path: "FilePath") -> "SSHKey":
205-
from getpass import getpass
206-
207211
from asyncssh.public_key import (
208212
KeyEncryptionError,
209213
KeyImportError,
@@ -217,9 +221,7 @@ async def _read_private_key_interactive(self, path: "FilePath") -> "SSHKey":
217221

218222
loop = asyncio.get_running_loop()
219223
for _ in range(3):
220-
passphrase = await loop.run_in_executor(
221-
None, getpass, f"Enter passphrase for key '{path}': "
222-
)
224+
passphrase = await _getpass(f"Enter passphrase for key {path!r}: ")
223225
if passphrase:
224226
try:
225227
key = read_private_key(path, passphrase=passphrase)
@@ -239,23 +241,20 @@ async def kbdint_challenge_received( # pylint: disable=invalid-overridden-metho
239241
lang: str,
240242
prompts: "KbdIntPrompts",
241243
) -> Optional["KbdIntResponse"]:
242-
from getpass import getpass
243-
244244
if os.environ.get("GIT_TERMINAL_PROMPT") == "0":
245245
return None
246246

247-
def _getpass(prompt: str) -> str:
248-
return getpass(prompt=prompt).rstrip()
249-
250247
if instructions:
251248
pass
252-
loop = asyncio.get_running_loop()
253-
return [
254-
await loop.run_in_executor(
255-
None, _getpass, f"({name}) {prompt}" if name else prompt
256-
)
257-
for prompt, _ in prompts
258-
]
249+
250+
response: list[str] = []
251+
for prompt, _echo in prompts:
252+
p = await _getpass(f"({name}) {prompt}" if name else prompt)
253+
response.append(p.rstrip())
254+
return response
255+
256+
async def password_auth_requested(self) -> str:
257+
return await _getpass()
259258

260259

261260
class AsyncSSHVendor(BaseAsyncObject, SSHVendor):

0 commit comments

Comments
 (0)