import { sdk } from '../sdk' import { promises as fs } from 'fs' import * as path from 'path' export const showPublicKey = sdk.Action.withoutInput( 'show-public-key', async () => ({ name: 'Show Public Key', description: 'Display the SSH public key. Paste it into ~/.ssh/authorized_keys on each Spark to grant access.', warning: null, visibility: 'enabled', allowedStatuses: 'any', group: null, }), async () => { // The container generates the key under /data/ssh/id_ed25519.pub on first boot. // The volume "main" is mounted at the host path that StartOS exposes via `sdk.volumes.main`. // For an Action running in the host, we read the file directly through the volume path. const pubKeyPath = path.join( sdk.volumes.main.path, 'ssh', 'id_ed25519.pub', ) let key: string try { key = (await fs.readFile(pubKeyPath, 'utf8')).trim() } catch (e) { return { version: '1' as const, title: 'Public Key Not Found', message: 'The container has not yet generated its SSH keypair. Start the service, wait a few seconds, and try again.', result: null, } } return { version: '1' as const, title: 'SSH Public Key', message: 'Append this single line to ~/.ssh/authorized_keys on EACH Spark ( user):\n\n' + key, result: { type: 'single' as const, name: 'Public Key', description: 'Copy this line to each Spark.', value: key, masked: false, copyable: true, qr: false, }, } }, )