Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/scmrepo/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def __init__(self, url: str) -> None:
class AuthError(SCMError):
def __init__(self, url: str) -> None:
self.url = url
super().__init__(f"HTTP Git authentication is not supported: '{url}'")
super().__init__(f"Authentication failed for: '{url}'")


class CloneError(SCMError):
Expand Down
8 changes: 4 additions & 4 deletions src/scmrepo/git/backend/dulwich/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,8 +531,8 @@ def iter_remote_refs(self, url: str, base: Optional[str] = None, **kwargs):
yield from (os.fsdecode(ref) for ref in client.get_refs(path))
except NotGitRepository as exc:
raise InvalidRemote(url) from exc
except HTTPUnauthorized:
raise AuthError(url)
except HTTPUnauthorized as exc:
raise AuthError(url) from exc

def get_refs_containing(self, rev: str, pattern: Optional[str] = None):
raise NotImplementedError
Expand Down Expand Up @@ -616,8 +616,8 @@ def update_refs(refs):
except (NotGitRepository, SendPackError) as exc:
src = [lh for (lh, _, _) in selected_refs]
raise SCMError(f"Git failed to push '{src}' to '{url}'") from exc
except HTTPUnauthorized:
raise AuthError(url)
except HTTPUnauthorized as exc:
raise AuthError(url) from exc
return change_result

def fetch_refspecs(
Expand Down
26 changes: 15 additions & 11 deletions src/scmrepo/git/backend/dulwich/asyncssh_vendor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from dulwich.client import SSHVendor

from scmrepo.asyn import BaseAsyncObject, sync_wrapper
from scmrepo.exceptions import AuthError

if TYPE_CHECKING:
from asyncssh.connection import SSHClientConnection
Expand Down Expand Up @@ -160,17 +161,20 @@ async def _run_command(
MSG_USERAUTH_PK_OK
] = _process_public_key_ok_gh

conn = await asyncssh.connect(
host,
port=port if port is not None else (),
username=username if username is not None else (),
password=password if password is not None else (),
client_keys=[key_filename] if key_filename else (),
ignore_encrypted=not key_filename,
known_hosts=None,
encoding=None,
)
proc = await conn.create_process(command, encoding=None)
try:
conn = await asyncssh.connect(
host,
port=port if port is not None else (),
username=username if username is not None else (),
password=password if password is not None else (),
client_keys=[key_filename] if key_filename else (),
ignore_encrypted=not key_filename,
known_hosts=None,
encoding=None,
)
proc = await conn.create_process(command, encoding=None)
except asyncssh.misc.PermissionDenied as exc:
raise AuthError(f"{username}@{host}:{port or 22}") from exc
return AsyncSSHWrapper(conn, proc)

run_command = sync_wrapper(_run_command)