Skip to content
← Public packages

@cameronpak/box

Full Box Public API v1 client: lifecycle, prompts, files, commands, snapshots, environments, webhooks, desktop, hosting, and account.

src/configure-ssh-key.ts

26 lines · 774 B · TypeScript
import { assertBoxId, boxRequest, failure, type Result } from './client.ts'

export type ConfigureSshKeyInput = {
	boxId: string
	/** Public SSH key in OpenSSH format. Private keys are rejected. */
	key: string
}

export type ConfigureSshKeyOutput = {
	success: boolean
	machineIp?: string | null
	sshUser?: string
}

/** Add an OpenSSH public key to the running box so the caller can SSH as user `user`. */
export default async function configureSshKey(
	input: ConfigureSshKeyInput,
): Promise<Result<ConfigureSshKeyOutput>> {
	const invalid = assertBoxId(input?.boxId)
	if (invalid) return failure<ConfigureSshKeyOutput>(invalid)
	return boxRequest<ConfigureSshKeyOutput>({
		path: '/boxes/' + input.boxId + '/sshkey',
		method: 'POST',
		body: { key: input.key },
	})
}