|
5 | 5 | from dulwich.client import SSHVendor
|
6 | 6 |
|
7 | 7 | from scmrepo.asyn import BaseAsyncObject, sync_wrapper
|
| 8 | +from scmrepo.exceptions import AuthError |
8 | 9 |
|
9 | 10 | if TYPE_CHECKING:
|
10 | 11 | from asyncssh.connection import SSHClientConnection
|
@@ -160,17 +161,20 @@ async def _run_command(
|
160 | 161 | MSG_USERAUTH_PK_OK
|
161 | 162 | ] = _process_public_key_ok_gh
|
162 | 163 |
|
163 |
| - conn = await asyncssh.connect( |
164 |
| - host, |
165 |
| - port=port if port is not None else (), |
166 |
| - username=username if username is not None else (), |
167 |
| - password=password if password is not None else (), |
168 |
| - client_keys=[key_filename] if key_filename else (), |
169 |
| - ignore_encrypted=not key_filename, |
170 |
| - known_hosts=None, |
171 |
| - encoding=None, |
172 |
| - ) |
173 |
| - proc = await conn.create_process(command, encoding=None) |
| 164 | + try: |
| 165 | + conn = await asyncssh.connect( |
| 166 | + host, |
| 167 | + port=port if port is not None else (), |
| 168 | + username=username if username is not None else (), |
| 169 | + password=password if password is not None else (), |
| 170 | + client_keys=[key_filename] if key_filename else (), |
| 171 | + ignore_encrypted=not key_filename, |
| 172 | + known_hosts=None, |
| 173 | + encoding=None, |
| 174 | + ) |
| 175 | + proc = await conn.create_process(command, encoding=None) |
| 176 | + except asyncssh.misc.PermissionDenied as exc: |
| 177 | + raise AuthError(f"{username}@{host}:{port or 22}") from exc |
174 | 178 | return AsyncSSHWrapper(conn, proc)
|
175 | 179 |
|
176 | 180 | run_command = sync_wrapper(_run_command)
|
0 commit comments