balena-cli
Version:
The official balena Command Line Interface
60 lines (56 loc) • 2.36 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@oclif/core");
const lazy_1 = require("../../utils/lazy");
class SSHKeyAddCmd extends core_1.Command {
async run() {
const { args: params } = await this.parse(SSHKeyAddCmd);
const { readFile } = (await Promise.resolve().then(() => require('fs'))).promises;
let key;
try {
key = await readFile(params.path, 'utf8');
}
catch (_a) {
key = params.path;
}
await (0, lazy_1.getBalenaSdk)().models.key.create(params.name, key);
}
}
SSHKeyAddCmd.aliases = ['key add'];
SSHKeyAddCmd.deprecateAliases = true;
SSHKeyAddCmd.description = (0, lazy_1.stripIndent) `
Add an SSH key to balenaCloud.
Add an SSH key to the balenaCloud account of the logged in user.
If \`path\` is omitted, the command will attempt to read the SSH key from stdin.
About SSH keys
An "SSH key" actually consists of a public/private key pair. A typical name
for the private key file is "id_rsa", and a typical name for the public key
file is "id_rsa.pub". Both key files are saved to your computer (with the
private key optionally protected by a password), but only the public key is
saved to your balena account. This means that if you change computers or
otherwise lose the private key, you cannot recover the private key through
your balena account. You can however add new keys, and delete the old ones.
To generate a new SSH key pair, a nice guide can be found in GitHub's docs:
https://help.github.com/en/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent
Skip the step about adding the key to a GitHub account, and instead add it to
your balena account.
`;
SSHKeyAddCmd.examples = [
'$ balena ssh-key add Main ~/.ssh/id_rsa.pub',
'$ cat ~/.ssh/id_rsa.pub | balena ssh-key add Main',
'# Windows 10 (cmd.exe prompt) example',
'$ balena ssh-key add Main %userprofile%.sshid_rsa.pub',
];
SSHKeyAddCmd.args = {
name: core_1.Args.string({
description: 'the SSH key name',
required: true,
}),
path: core_1.Args.string({
description: `the path to the public key file`,
required: true,
}),
};
SSHKeyAddCmd.authenticated = true;
exports.default = SSHKeyAddCmd;
//# sourceMappingURL=add.js.map