merge remote changes
This commit is contained in:
1 parent
9fcaf9d762
commit
6161f36ea4
7 files changed
+736
-354
No files matched your search
+29
-5
@@ -11,19 +11,43 @@ class SSHService:
|
||||
def __init__(self, host, user, ssh_key=None):
|
||||
self.host = host
|
||||
self.user = user
|
||||
self.ssh_key = ssh_key
|
||||
logger.info(f"SSHService initialized: {user}@{host}")
|
||||
self.ssh_key = self._resolve_ssh_key(ssh_key)
|
||||
key_status = self.ssh_key if self.ssh_key else 'default ssh identity/agent'
|
||||
logger.info(f"SSHService initialized: {user}@{host} using {key_status}")
|
||||
|
||||
def _resolve_ssh_key(self, ssh_key):
|
||||
if ssh_key:
|
||||
key = str(ssh_key).strip("'\"")
|
||||
if os.path.exists(key):
|
||||
return key
|
||||
|
||||
base_dir = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
|
||||
temp_dir = os.environ.get('TEMP') or os.environ.get('TMPDIR') or ('/tmp' if os.name != 'nt' else 'C:\\Temp')
|
||||
local_appdata = os.environ.get('LOCALAPPDATA', '')
|
||||
potential_paths = [
|
||||
os.path.join(temp_dir, 'dune-tunnel-key'),
|
||||
os.path.join(temp_dir, 'dune-awakening-server-sshKey'),
|
||||
os.path.join(base_dir, 'internal-scripts', 'ssh', 'sshKey'),
|
||||
os.path.join(os.path.dirname(base_dir), 'internal-scripts', 'ssh', 'sshKey'),
|
||||
]
|
||||
if local_appdata:
|
||||
potential_paths.insert(2, os.path.join(local_appdata, 'DuneAwakeningServer', 'sshKey'))
|
||||
|
||||
for path in potential_paths:
|
||||
if os.path.exists(path):
|
||||
return path
|
||||
return None
|
||||
|
||||
def run(self, command, timeout=30):
|
||||
args = [
|
||||
'ssh',
|
||||
'-i', self.ssh_key,
|
||||
'-o', 'StrictHostKeyChecking=accept-new',
|
||||
'-o', 'ConnectTimeout=10',
|
||||
'-o', 'BatchMode=yes',
|
||||
f'{self.user}@{self.host}',
|
||||
command
|
||||
]
|
||||
if self.ssh_key:
|
||||
args.extend(['-i', self.ssh_key])
|
||||
args.extend([f'{self.user}@{self.host}', command])
|
||||
logger.debug(f"SSH command: {command[:100]}...")
|
||||
try:
|
||||
result = subprocess.run(
|
||||
|
||||
Reference in new issue
Block a user