Skip to content

Commit c5c6b3d

Browse files
feat: parse v2/ssh fields correctly and coerce v0/ssh response to v2
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 59a2b29 commit c5c6b3d

1 file changed

Lines changed: 35 additions & 8 deletions

File tree

src/lib/nodes/ssh.ts

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,16 @@ import {
1313
logSessionTokenExpiredAndQuit,
1414
} from "../../helpers/errors.ts";
1515
import { handleNodesError, nodesClient } from "../../nodesClient.ts";
16-
import type { components } from "../../schema.ts";
1716
import { jsonOption } from "./utils.ts";
1817

19-
type SshInfo = components["schemas"]["vmorch_GetSshResponse"];
18+
// Canonical SSH info shape (v2 NodeSshInfo format)
19+
type SshInfo = {
20+
hostname: string;
21+
port: number;
22+
host_keys: { key_type: string; key: string }[];
23+
last_successful_key_update: number | null;
24+
last_attempted_key_update: number | null;
25+
};
2026

2127
const ssh = new Command("ssh")
2228
.description(`SSH into a VM on a node.
@@ -88,7 +94,16 @@ Examples:
8894
);
8995

9096
if (v2Response.ok) {
91-
data = await v2Response.json();
97+
const v2Data = await v2Response.json();
98+
data = {
99+
hostname: v2Data.hostname,
100+
port: v2Data.port,
101+
host_keys: v2Data.host_keys ?? [],
102+
last_successful_key_update:
103+
v2Data.last_successful_key_update ?? null,
104+
last_attempted_key_update:
105+
v2Data.last_attempted_key_update ?? null,
106+
};
92107
hostKeyAlias = `${nodeOrVmId}.v2.nodes.sfcompute.dev`;
93108
}
94109
}
@@ -136,7 +151,19 @@ Examples:
136151
process.exit(1);
137152
}
138153

139-
data = sshData;
154+
// Coerce v0 response to v2 shape
155+
data = {
156+
hostname: sshData.ssh_hostname,
157+
port: sshData.ssh_port,
158+
host_keys: (sshData.ssh_host_keys ?? []).map((k) => ({
159+
key_type: k.key_type,
160+
key: k.base64_encoded_key,
161+
})),
162+
last_successful_key_update:
163+
sshData.last_successful_key_update ?? null,
164+
last_attempted_key_update:
165+
sshData.last_attempted_key_update ?? null,
166+
};
140167
hostKeyAlias = `${vmId}.vms.sfcompute.dev`;
141168
}
142169

@@ -147,9 +174,9 @@ Examples:
147174
return;
148175
}
149176

150-
const sshHostname = data.hostname ?? data.ssh_hostname;
151-
const sshPort = data.port ?? data.ssh_port;
152-
const sshHostKeys = data.host_keys ?? data.ssh_host_keys ?? [];
177+
const sshHostname = data.hostname;
178+
const sshPort = data.port;
179+
const sshHostKeys = data.host_keys;
153180

154181
let sshDestination = sshHostname;
155182
if (sshUsername !== undefined) {
@@ -168,7 +195,7 @@ Examples:
168195
knownHostsCommand = knownHostsCommand.concat([
169196
hostKeyAlias,
170197
sshHostKey.key_type,
171-
sshHostKey.key ?? sshHostKey.base64_encoded_key,
198+
sshHostKey.key,
172199
]);
173200
}
174201
// Escape all characters for proper pass through

0 commit comments

Comments
 (0)