Skip to content

Commit

Permalink
fix: update asyncssh arg handling
Browse files Browse the repository at this point in the history
  • Loading branch information
carlmontanari committed Jul 8, 2023
1 parent 180952b commit 0128d37
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
38 changes: 28 additions & 10 deletions scrapli_netconf/transport/plugins/asyncssh/transport.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""scrapli_netconf.transport.plugins.asyncssh.transport"""
import asyncio
from typing import Any, Dict

from asyncssh.connection import SSHClientConnection, connect
from asyncssh.misc import ChannelOpenError, PermissionDenied
Expand Down Expand Up @@ -38,8 +39,13 @@ async def open_netconf(self) -> None:

# we already fetched host/port/user from the user input and/or the ssh config file, so we
# want to use those explicitly. likewise we pass config file we already found. set known
# hosts and agent to None so we can not have an agent and deal w/ known hosts ourselves
common_args = {
# hosts and agent to None so we can not have an agent and deal w/ known hosts ourselves.
# to use ssh-agent either pass an empty tuple (to pick up ssh-agent socket from
# SSH_AUTH_SOCK), or pass an explicit path to ssh-agent socket should be provided as part
# of transport_options -- in either case these get merged into the dict *after* we set the
# default value of `None`, so users options override our defaults.

common_args: Dict[str, Any] = {

Check warning on line 48 in scrapli_netconf/transport/plugins/asyncssh/transport.py

View check run for this annotation

Codecov / codecov/patch

scrapli_netconf/transport/plugins/asyncssh/transport.py#L48

Added line #L48 was not covered by tests
"host": self._base_transport_args.host,
"port": self._base_transport_args.port,
"username": self.plugin_transport_args.auth_username,
Expand All @@ -48,17 +54,29 @@ async def open_netconf(self) -> None:
"config": self.plugin_transport_args.ssh_config_file,
}

# Allow passing `transport_options` to asyncssh
common_args.update(self._base_transport_args.transport_options.get("asyncssh", {}))

Check warning on line 58 in scrapli_netconf/transport/plugins/asyncssh/transport.py

View check run for this annotation

Codecov / codecov/patch

scrapli_netconf/transport/plugins/asyncssh/transport.py#L58

Added line #L58 was not covered by tests

# Common authentication args
auth_args: Dict[str, Any] = {

Check warning on line 61 in scrapli_netconf/transport/plugins/asyncssh/transport.py

View check run for this annotation

Codecov / codecov/patch

scrapli_netconf/transport/plugins/asyncssh/transport.py#L61

Added line #L61 was not covered by tests
"client_keys": self.plugin_transport_args.auth_private_key,
"password": self.plugin_transport_args.auth_password,
"preferred_auth": (
"publickey",
"keyboard-interactive",
"password",
),
}

# The session args to use in connect() - to merge the dicts in
# the order to have transport options preference over predefined auth args
conn_args = {**auth_args, **common_args}

Check warning on line 73 in scrapli_netconf/transport/plugins/asyncssh/transport.py

View check run for this annotation

Codecov / codecov/patch

scrapli_netconf/transport/plugins/asyncssh/transport.py#L73

Added line #L73 was not covered by tests

try:
self.session: SSHClientConnection = await asyncio.wait_for(
connect(
client_keys=self.plugin_transport_args.auth_private_key,
password=self.plugin_transport_args.auth_password,
preferred_auth=(
"publickey",
"keyboard-interactive",
"password",
),
**common_args,
connect(**conn_args),
timeout=self._base_transport_args.timeout_socket,
),
timeout=self._base_transport_args.timeout_socket,
)
Expand Down
2 changes: 0 additions & 2 deletions tests/unit/channel/test_sync_channel.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import pytest

from scrapli_netconf.constants import NetconfClientCapabilities


def test_open_netconf():
pass
Expand Down

0 comments on commit 0128d37

Please sign in to comment.