Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Postpone ssh config parsing file when connecting to device for doing … #812

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
16 changes: 4 additions & 12 deletions suzieq/poller/worker/nodes/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,11 +557,6 @@ async def _init_jump_host_connection(
options=jump_host_options,
known_hosts=None
)
if self.ssh_config_file:
jump_host_options = asyncssh.SSHClientConnectionOptions(
options=jump_host_options,
config_file=[self.ssh_config_file]
)
else:
jump_host_options = options

Expand All @@ -573,7 +568,8 @@ async def _init_jump_host_connection(
)
self._tunnel = await asyncssh.connect(
self.jump_host, port=self.jump_port,
options=jump_host_options, username=self.jump_user)
options=jump_host_options, username=self.jump_user,
config=[self.ssh_config_file])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't work if no ssh config file is provided as we would pass a list containing None to the connect() function, causing it to fail.
I suggest to directly provide the string and, if empty or None, an empty tuple (as according to the docs explicitly passing None, asyncssh won't get the default configuration in .ssh/config).

Suggested change
config=[self.ssh_config_file])
config=self.ssh_config_file or ())

self.logger.info(
'Connection to jump host %s succeeded', self.jump_host)

Expand Down Expand Up @@ -605,11 +601,6 @@ def _init_ssh_options(self) -> asyncssh.SSHClientConnectionOptions:
options=options,
known_hosts=None,
)
if self.ssh_config_file:
options = asyncssh.SSHClientConnectionOptions(
options=options,
config=[self.ssh_config_file],
)

return options

Expand Down Expand Up @@ -729,7 +720,8 @@ async def _ssh_connect(self):
self.address,
username=self.username,
port=self.port,
options=options)
options=options,
config=[self.ssh_config_file])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the comment before:

Suggested change
config=[self.ssh_config_file])
config=self.ssh_config_file or ())

self.logger.info(
f"Connected to {self.address}:{self.port} at "
f"{time.time()}")
Expand Down