Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 5x 1x 1x 4x 4x 4x 4x 4x 4x 2x 2x 2x 1x 1x 1x 1x 193x 193x | import { todo_addSshKey as addSshKey } from '@clevercloud/client/esm/api/v2/user.js';
import fs from 'node:fs';
import { z } from 'zod';
import { defineArgument } from '../../lib/define-argument.js';
import { defineCommand } from '../../lib/define-command.js';
import { Logger } from '../../logger.js';
import { sendToApi } from '../../models/send-to-api.js';
import { sshKeyNameArg } from './ssh-keys.args.js';
export const sshKeysAddCommand = defineCommand({
description: 'Add a new SSH key to the current user',
since: '3.13.0',
options: {},
args: [
sshKeyNameArg,
defineArgument({
schema: z.string(),
description: 'SSH public key path (.pub)',
placeholder: 'ssh-key-path',
}),
],
async handler(_options, keyName, filePath) {
if (!fs.existsSync(filePath)) {
throw new Error(`File ${filePath} does not exist`);
}
const pubKeyContent = fs.readFileSync(filePath, 'utf8').trim();
Logger.debug(`SSH key file content: ${pubKeyContent}`);
try {
await addSshKey({ key: encodeURIComponent(keyName) }, JSON.stringify(pubKeyContent)).then(sendToApi);
Logger.printSuccess(`SSH key ${keyName} added successfully`);
} catch (e) {
if (e?.responseBody?.id === 505) {
throw new Error("This SSH key is not valid, please make sure you're pointing to the public key file");
}
throw e;
}
},
});
|