mirror of
https://github.com/balena-io/balena-cli.git
synced 2024-12-18 21:27:51 +00:00
Merge pull request #2881 from balena-io/fix-ssh-key-add-piping
Restore ability to cat key into `ssh-key add`
This commit is contained in:
commit
aaf4625abb
@ -16,7 +16,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { Args, Command } from '@oclif/core';
|
import { Args, Command } from '@oclif/core';
|
||||||
import { ExpectedError } from '../../errors';
|
|
||||||
import { getBalenaSdk, stripIndent } from '../../utils/lazy';
|
import { getBalenaSdk, stripIndent } from '../../utils/lazy';
|
||||||
|
|
||||||
export default class SSHKeyAddCmd extends Command {
|
export default class SSHKeyAddCmd extends Command {
|
||||||
@ -59,6 +58,7 @@ export default class SSHKeyAddCmd extends Command {
|
|||||||
}),
|
}),
|
||||||
path: Args.string({
|
path: Args.string({
|
||||||
description: `the path to the public key file`,
|
description: `the path to the public key file`,
|
||||||
|
required: true,
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -67,12 +67,12 @@ export default class SSHKeyAddCmd extends Command {
|
|||||||
public async run() {
|
public async run() {
|
||||||
const { args: params } = await this.parse(SSHKeyAddCmd);
|
const { args: params } = await this.parse(SSHKeyAddCmd);
|
||||||
|
|
||||||
|
const { readFile } = (await import('fs')).promises;
|
||||||
let key: string;
|
let key: string;
|
||||||
if (params.path != null) {
|
try {
|
||||||
const { readFile } = (await import('fs')).promises;
|
|
||||||
key = await readFile(params.path, 'utf8');
|
key = await readFile(params.path, 'utf8');
|
||||||
} else {
|
} catch {
|
||||||
throw new ExpectedError('No public key file or path provided.');
|
key = params.path;
|
||||||
}
|
}
|
||||||
|
|
||||||
await getBalenaSdk().models.key.create(params.name, key);
|
await getBalenaSdk().models.key.create(params.name, key);
|
||||||
|
Loading…
Reference in New Issue
Block a user