-
Notifications
You must be signed in to change notification settings - Fork 55
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
Support SSH proxy command #493
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,6 +45,7 @@ | |
tar_compress=True, | ||
look_for_keys=True, | ||
execute_command=None, | ||
proxy_command=None, | ||
): | ||
self.hostname = hostname | ||
self.username = username | ||
|
@@ -59,6 +60,7 @@ | |
self.look_for_keys = look_for_keys | ||
self.execute_command = execute_command | ||
self._keyboard_interactive_auth = False | ||
self.proxy_command = proxy_command | ||
self._setup_ssh() | ||
|
||
# @classmethod | ||
|
@@ -141,12 +143,16 @@ | |
# ) | ||
# assert(self.ssh.get_transport().is_active()) | ||
# transport = self.ssh.get_transport() | ||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | ||
sock.settimeout(self.timeout) | ||
sock.connect((self.hostname, self.port)) | ||
if self.proxy_command is not None: | ||
sock = paramiko.ProxyCommand(self.proxy_command) | ||
sock.settimeout(self.timeout) | ||
else: | ||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | ||
sock.settimeout(self.timeout) | ||
sock.connect((self.hostname, self.port)) | ||
|
||
# Make a Paramiko Transport object using the socket | ||
ts = paramiko.Transport(sock) | ||
Check failure on line 155 in dpdispatcher/contexts/ssh_context.py GitHub Actions / pyright
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you ignore this line before python/typeshed#12697 is accepted? |
||
ts.banner_timeout = 60 | ||
ts.auth_timeout = self.timeout + 20 | ||
ts.use_compression(compress=True) | ||
|
@@ -343,6 +349,7 @@ | |
"enable searching for discoverable private key files in ~/.ssh/" | ||
) | ||
doc_execute_command = "execute command after ssh connection is established." | ||
doc_proxy_command = "The command of proxy." | ||
ssh_remote_profile_args = [ | ||
Argument("hostname", str, optional=False, doc=doc_hostname), | ||
Argument("username", str, optional=False, doc=doc_username), | ||
|
@@ -391,6 +398,13 @@ | |
default=None, | ||
doc=doc_execute_command, | ||
), | ||
Argument( | ||
"proxy_command", | ||
str, | ||
optional=True, | ||
default=None, | ||
doc=doc_proxy_command, | ||
), | ||
Comment on lines
+401
to
+407
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Ensure consistency in argument definitions The |
||
] | ||
ssh_remote_profile_format = Argument( | ||
"ssh_session", dict, ssh_remote_profile_args | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add unit tests for the
proxy_command
functionalityThe newly added code handling the
proxy_command
is not covered by existing tests. To ensure reliability and prevent future regressions, please add unit tests that verify the behavior when aproxy_command
is provided.🧰 Tools
GitHub Check: codecov/patch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with the AI. A unit test should be added.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@njzjz, I'll proceed to add unit tests for the
proxy_command
functionality as requested. Here's a test case that verifies the behavior when aproxy_command
is provided:Explanation:
test_setup_ssh_with_proxy_command
): Verifies that when aproxy_command
is provided,paramiko.ProxyCommand
is used, and the standard socket connection is not invoked.test_setup_ssh_without_proxy_command
): Verifies that when noproxy_command
is provided, the standard socket connection is used.This should ensure that the
proxy_command
functionality is properly tested and prevent future regressions.Let me know if you'd like any further adjustments!