Skip to content

Commit

Permalink
Fix to port 3306 in tests and for paramiko.
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeZiminski committed Apr 19, 2024
1 parent b28937c commit 3e09136
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions datashuttle/utils/ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from pathlib import Path

from datashuttle.configs.config_class import Configs

import fnmatch
import getpass
import stat
import sys
from pathlib import Path
from typing import Any, List, Optional, Tuple

import paramiko
Expand All @@ -31,14 +30,19 @@ def connect_client_core(
password: Optional[str] = None,
):
client.get_host_keys().load(cfg.hostkeys_path.as_posix())
client.set_missing_host_key_policy(
paramiko.AutoAddPolicy()
) # TODO: ADDBACK IN!! RejectPolicy
client.set_missing_host_key_policy(paramiko.RejectPolicy())

client.connect(
cfg["central_host_id"],
username=cfg["central_host_username"],
password="password", # TODO: ADDBACK IN!! RejectPolicy
password=password,
key_filename=(
cfg.ssh_key_path.as_posix()
if isinstance(cfg.ssh_key_path, Path)
else None
),
look_for_keys=True,
port=3306,
)


Expand Down Expand Up @@ -80,15 +84,17 @@ def get_remote_server_key(central_host_id: str):
connection.
"""
transport: paramiko.Transport
with paramiko.Transport(central_host_id) as transport:
with paramiko.Transport((central_host_id, 3306)) as transport:
transport.connect()
key = transport.get_remote_server_key()
return key


def save_hostkey_locally(key, central_host_id, hostkeys_path) -> None:
client = paramiko.SSHClient()
client.get_host_keys().add(central_host_id, key.get_name(), key)
client.get_host_keys().add(
f"[{central_host_id}]:3306", key.get_name(), key
)
client.get_host_keys().save(hostkeys_path.as_posix())


Expand Down

0 comments on commit 3e09136

Please sign in to comment.