Skip to content

Commit 4650ad7

Browse files
samuelsellecksamsfcomputesigmachiralityclaude
authored
fix: [PR-1697] correctly parse v2/ssh endpoint fields (#250)
* accept v2 field names for ssh and image endpoints * feat: parse `v2/ssh` fields correctly and coerce `v0/ssh` response to `v2` Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * perf: avoid unnecessary object construction Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * style: run biome Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Samuel Selleck <samuel@sfcompute.com> Co-authored-by: Daniel Tao <danieltaox@gmail.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 3ae610e commit 4650ad7

1 file changed

Lines changed: 25 additions & 8 deletions

File tree

src/lib/nodes/ssh.ts

Lines changed: 25 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,7 @@ Examples:
8894
);
8995

9096
if (v2Response.ok) {
91-
data = await v2Response.json();
97+
data = (await v2Response.json()) as SshInfo;
9298
hostKeyAlias = `${nodeOrVmId}.v2.nodes.sfcompute.dev`;
9399
}
94100
}
@@ -136,7 +142,18 @@ Examples:
136142
process.exit(1);
137143
}
138144

139-
data = sshData;
145+
// Coerce v0 response to v2 shape
146+
data = {
147+
hostname: sshData.ssh_hostname,
148+
port: sshData.ssh_port,
149+
host_keys: (sshData.ssh_host_keys ?? []).map((k) => ({
150+
key_type: k.key_type,
151+
key: k.base64_encoded_key,
152+
})),
153+
last_successful_key_update:
154+
sshData.last_successful_key_update ?? null,
155+
last_attempted_key_update: sshData.last_attempted_key_update ?? null,
156+
};
140157
hostKeyAlias = `${vmId}.vms.sfcompute.dev`;
141158
}
142159

@@ -147,9 +164,9 @@ Examples:
147164
return;
148165
}
149166

150-
const sshHostname = data.ssh_hostname;
151-
const sshPort = data.ssh_port;
152-
const sshHostKeys = data.ssh_host_keys || [];
167+
const sshHostname = data.hostname;
168+
const sshPort = data.port;
169+
const sshHostKeys = data.host_keys;
153170

154171
let sshDestination = sshHostname;
155172
if (sshUsername !== undefined) {
@@ -168,7 +185,7 @@ Examples:
168185
knownHostsCommand = knownHostsCommand.concat([
169186
hostKeyAlias,
170187
sshHostKey.key_type,
171-
sshHostKey.base64_encoded_key,
188+
sshHostKey.key,
172189
]);
173190
}
174191
// Escape all characters for proper pass through

0 commit comments

Comments
 (0)