/** * SSH Private key subcommands for CLI — all go through SDK. * * @module */ import { runAction, runList, runGet, chalk, getCliSdk } from "../actions.js"; import type { ICoolifyPrivateKey } from "../../coolify/types.js"; /** List all private keys. */ export const keysListCommand = () => runList("key(s)", (s) => s.keys.list(), [ { header: "UUID", value: (k) => k.uuid }, { header: "Name", value: (k) => k.name || "-" }, { header: "Git?", value: (k) => (k.is_git_related ? "Yes" : "No") }, { header: "Created", value: (k) => k.created_at ? new Date(k.created_at).toLocaleDateString() : "-", }, ]); /** Get private key details. */ export const keysGetCommand = (uuid: string) => runGet( uuid, "private key", (s, u) => s.keys.get(u), (key) => { console.log(chalk.cyan("Private Key Details:")); console.log(chalk.gray("UUID: ") + key.uuid); console.log(chalk.gray("Name: ") + key.name); console.log( chalk.gray("Git-related:") + (key.is_git_related ? " Yes" : " No"), ); }, ); /** Create a private key. */ export async function keysCreateCommand( name: string, options: { key?: string; file?: string; description?: string }, ): Promise { try { let privateKey = options.key || ""; if (options.file) { const { readFileSync } = await import("node:fs"); privateKey = readFileSync(options.file, "utf-8"); } if (!privateKey) { console.error(chalk.red("Error: Provide --key or --file ")); return; } const result = await getCliSdk().keys.create({ name, private_key: privateKey, description: options.description, }); console.log( chalk.green(`Private key created! UUID: ${chalk.cyan(result.uuid)}`), ); } catch (error) { console.error( chalk.red( `Error: ${error instanceof Error ? error.message : String(error)}`, ), ); } } /** Delete a private key. */ export const keysDeleteCommand = (uuid: string) => runAction( uuid, "Deleting private key", (s, u) => s.keys.delete(u), (u) => `Private key deleted: ${u}`, );