-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SSH - 18588 - Updated dependencies | Updated SDK to the latest version (
- Loading branch information
1 parent
7c593e9
commit 7ac9e7e
Showing
15 changed files
with
152 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DEFAULT_ENCODING = "UTF-8" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from paramiko import MissingHostKeyPolicy, PKey, SSHClient | ||
|
||
|
||
class CustomMissingKeyPolicy(MissingHostKeyPolicy): | ||
def missing_host_key(self, client: SSHClient, hostname: str, key: PKey) -> None: | ||
client.get_host_keys().add(hostname, key.get_name(), key) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from abc import ABC, abstractmethod | ||
from base64 import b64decode | ||
from io import StringIO | ||
from logging import Logger | ||
|
||
from paramiko import RSAKey, SSHClient | ||
|
||
from .constants import DEFAULT_ENCODING | ||
|
||
|
||
class SSHConnectionStrategy(ABC): | ||
def __init__(self, client: SSHClient, logger: Logger) -> None: | ||
self.client = client | ||
self.logger = logger | ||
|
||
@abstractmethod | ||
def connect(self, host: str, port: int, username: str, password: str, key: str = None) -> SSHClient: | ||
pass | ||
|
||
|
||
class ConnectUsingPasswordStrategy(SSHConnectionStrategy): | ||
def connect(self, host: str, port: int, username: str, password: str, key: str = None) -> SSHClient: | ||
self.logger.info("Connecting to SSH server via password...") | ||
self.client.connect(host, port, username, password) | ||
return self.client | ||
|
||
|
||
class ConnectUsingRSAKeyStrategy(SSHConnectionStrategy): | ||
def connect(self, host: str, port: int, username: str, password: str, key: str = None) -> SSHClient: | ||
self.logger.info("Connecting to SSH server via RSA key...") | ||
key = b64decode(key).decode(DEFAULT_ENCODING) | ||
rsa_key = RSAKey.from_private_key(StringIO(key), password=password) | ||
self.client.connect(host, port, username, password, pkey=rsa_key) | ||
return self.client |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# List third-party dependencies here, separated by newlines. | ||
# All dependencies must be version-pinned, eg. requests==1.2.0 | ||
# See: https://pip.pypa.io/en/stable/user_guide/#requirements-files | ||
paramiko==3.4.1 | ||
paramiko==3.5.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.