Skip to content

Commit

Permalink
Merge pull request #2857 from balena-io/key-to-ssh-key
Browse files Browse the repository at this point in the history
Add `ssh-key` as aliases for all `key` commands
  • Loading branch information
myarmolinsky authored Oct 18, 2024
2 parents 5d0d02a + 3044660 commit 388e02c
Show file tree
Hide file tree
Showing 15 changed files with 143 additions and 112 deletions.
2 changes: 1 addition & 1 deletion automation/capitanodoc/capitanodoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const commandHeadings: { [key: string]: string } = {
env: 'Environment Variables',
envs: 'Environment Variables',
help: 'Help and Version',
key: 'SSH Keys',
'ssh-key': 'SSH Keys',
orgs: 'Organizations',
os: 'OS',
util: 'Utilities',
Expand Down
10 changes: 5 additions & 5 deletions completion/_balena
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ _balena() {
local context state line curcontext="$curcontext"

# Valid top-level completions
main_commands=( api-key app block build config deploy device devices env envs fleet internal join key leave local login logout logs notes orgs os preload push release scan settings ssh support tag tags tunnel util version whoami )
main_commands=( api-key app block build config deploy device devices env envs fleet internal join leave local login logout logs notes orgs os preload push release scan settings ssh ssh-key support tag tags tunnel util version whoami )
# Sub-completions
api_key_cmds=( generate list revoke )
app_cmds=( create )
Expand All @@ -19,10 +19,10 @@ _balena() {
env_cmds=( add rename rm )
fleet_cmds=( create list pin purge rename restart rm track-latest )
internal_cmds=( osinit )
key_cmds=( add list rm )
local_cmds=( configure flash )
os_cmds=( build-config configure download initialize versions )
release_cmds=( finalize invalidate list validate )
ssh_key_cmds=( add list rm )
tag_cmds=( rm set )


Expand Down Expand Up @@ -69,9 +69,6 @@ _balena_sec_cmds() {
"internal")
_describe -t internal_cmds 'internal_cmd' internal_cmds "$@" && ret=0
;;
"key")
_describe -t key_cmds 'key_cmd' key_cmds "$@" && ret=0
;;
"local")
_describe -t local_cmds 'local_cmd' local_cmds "$@" && ret=0
;;
Expand All @@ -81,6 +78,9 @@ _balena_sec_cmds() {
"release")
_describe -t release_cmds 'release_cmd' release_cmds "$@" && ret=0
;;
"ssh-key")
_describe -t ssh_key_cmds 'ssh-key_cmd' ssh_key_cmds "$@" && ret=0
;;
"tag")
_describe -t tag_cmds 'tag_cmd' tag_cmds "$@" && ret=0
;;
Expand Down
10 changes: 5 additions & 5 deletions completion/balena-completion.bash
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ _balena_complete()
local cur prev

# Valid top-level completions
main_commands="api-key app block build config deploy device devices env envs fleet internal join key leave local login logout logs notes orgs os preload push release scan settings ssh support tag tags tunnel util version whoami"
main_commands="api-key app block build config deploy device devices env envs fleet internal join leave local login logout logs notes orgs os preload push release scan settings ssh ssh-key support tag tags tunnel util version whoami"
# Sub-completions
api_key_cmds="generate list revoke"
app_cmds="create"
Expand All @@ -18,10 +18,10 @@ _balena_complete()
env_cmds="add rename rm"
fleet_cmds="create list pin purge rename restart rm track-latest"
internal_cmds="osinit"
key_cmds="add list rm"
local_cmds="configure flash"
os_cmds="build-config configure download initialize versions"
release_cmds="finalize invalidate list validate"
ssh_key_cmds="add list rm"
tag_cmds="rm set"


Expand Down Expand Up @@ -63,9 +63,6 @@ _balena_complete()
internal)
COMPREPLY=( $(compgen -W "$internal_cmds" -- $cur) )
;;
key)
COMPREPLY=( $(compgen -W "$key_cmds" -- $cur) )
;;
local)
COMPREPLY=( $(compgen -W "$local_cmds" -- $cur) )
;;
Expand All @@ -75,6 +72,9 @@ _balena_complete()
release)
COMPREPLY=( $(compgen -W "$release_cmds" -- $cur) )
;;
ssh-key)
COMPREPLY=( $(compgen -W "$ssh_key_cmds" -- $cur) )
;;
tag)
COMPREPLY=( $(compgen -W "$tag_cmds" -- $cur) )
;;
Expand Down
54 changes: 38 additions & 16 deletions docs/balena-cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,10 +294,10 @@ are encouraged to regularly update the balena CLI to the latest version.

- SSH Keys

- [key add](#key-add)
- [key](#key)
- [key list](#key-list)
- [key rm](#key-rm)
- [ssh-key add](#ssh-key-add)
- [ssh-key](#ssh-key)
- [ssh-key list](#ssh-key-list)
- [ssh-key rm](#ssh-key-rm)

- Support

Expand Down Expand Up @@ -3664,7 +3664,14 @@ Examples:

# SSH Keys

## key add
## ssh-key add

### Aliases

- `key add`


To use one of the aliases, replace `ssh-key add` with the alias.

### Description

Expand All @@ -3688,10 +3695,10 @@ your balena account.

Examples:

$ balena key add Main ~/.ssh/id_rsa.pub
$ cat ~/.ssh/id_rsa.pub | balena key add Main
$ 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 key add Main %userprofile%.sshid_rsa.pub
$ balena ssh-key add Main %userprofile%.sshid_rsa.pub

### Arguments

Expand All @@ -3705,15 +3712,22 @@ the path to the public key file

### Options

## key
## ssh-key

### Aliases

- `key`


To use one of the aliases, replace `ssh-key` with the alias.

### Description

Display a single SSH key registered in balenaCloud for the logged in user.

Examples:

$ balena key 17
$ balena ssh-key 17

### Arguments

Expand All @@ -3723,26 +3737,34 @@ balenaCloud ID for the SSH key

### Options

## key list
## ssh-key list

### Aliases

- `keys`
- `key list`


To use one of the aliases, replace `key list` with the alias.
To use one of the aliases, replace `ssh-key list` with the alias.

### Description

List all SSH keys registered in balenaCloud for the logged in user.

Examples:

$ balena key list
$ balena ssh-key list

### Options

## key rm
## ssh-key rm

### Aliases

- `key rm`


To use one of the aliases, replace `ssh-key rm` with the alias.

### Description

Expand All @@ -3752,8 +3774,8 @@ The --yes option may be used to avoid interactive confirmation.

Examples:

$ balena key rm 17
$ balena key rm 17 --yes
$ balena ssh-key rm 17
$ balena ssh-key rm 17 --yes

### Arguments

Expand Down
12 changes: 6 additions & 6 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 7 additions & 5 deletions src/commands/key/add.ts → src/commands/ssh-key/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ import { ExpectedError } from '../../errors';
import * as cf from '../../utils/common-flags';
import { getBalenaSdk, stripIndent } from '../../utils/lazy';

export default class KeyAddCmd extends Command {
export default class SSHKeyAddCmd extends Command {
public static aliases = ['key add'];

public static description = stripIndent`
Add an SSH key to balenaCloud.
Expand All @@ -44,10 +46,10 @@ export default class KeyAddCmd extends Command {
`;

public static examples = [
'$ balena key add Main ~/.ssh/id_rsa.pub',
'$ cat ~/.ssh/id_rsa.pub | balena key add Main',
'$ 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 key add Main %userprofile%.sshid_rsa.pub',
'$ balena ssh-key add Main %userprofile%.sshid_rsa.pub',
];

public static args = {
Expand All @@ -67,7 +69,7 @@ export default class KeyAddCmd extends Command {
public static authenticated = true;

public async run() {
const { args: params } = await this.parse(KeyAddCmd);
const { args: params } = await this.parse(SSHKeyAddCmd);

let key: string;
if (params.path != null) {
Expand Down
8 changes: 5 additions & 3 deletions src/commands/key/index.ts → src/commands/ssh-key/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@ import * as cf from '../../utils/common-flags';
import { getBalenaSdk, getVisuals, stripIndent } from '../../utils/lazy';
import { parseAsInteger } from '../../utils/validation';

export default class KeyCmd extends Command {
export default class SSHKeyCmd extends Command {
public static aliases = ['key'];

public static description = stripIndent`
Display an SSH key.
Display a single SSH key registered in balenaCloud for the logged in user.
`;

public static examples = ['$ balena key 17'];
public static examples = ['$ balena ssh-key 17'];

public static args = {
id: Args.integer({
Expand All @@ -44,7 +46,7 @@ export default class KeyCmd extends Command {
public static authenticated = true;

public async run() {
const { args: params } = await this.parse(KeyCmd);
const { args: params } = await this.parse(SSHKeyCmd);

const key = await getBalenaSdk().models.key.get(params.id);

Expand Down
8 changes: 4 additions & 4 deletions src/commands/key/list.ts → src/commands/ssh-key/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ import { Command } from '@oclif/core';
import * as cf from '../../utils/common-flags';
import { getBalenaSdk, getVisuals, stripIndent } from '../../utils/lazy';

export default class KeyListCmd extends Command {
public static aliases = ['keys'];
export default class SSHKeyListCmd extends Command {
public static aliases = ['keys', 'key list'];

public static description = stripIndent`
List the SSH keys in balenaCloud.
List all SSH keys registered in balenaCloud for the logged in user.
`;
public static examples = ['$ balena key list'];
public static examples = ['$ balena ssh-key list'];

public static flags = {
help: cf.help,
Expand All @@ -36,7 +36,7 @@ export default class KeyListCmd extends Command {
public static authenticated = true;

public async run() {
await this.parse(KeyListCmd);
await this.parse(SSHKeyListCmd);

const keys = await getBalenaSdk().models.key.getAll();

Expand Down
11 changes: 8 additions & 3 deletions src/commands/key/rm.ts → src/commands/ssh-key/rm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ import * as cf from '../../utils/common-flags';
import { getBalenaSdk, stripIndent } from '../../utils/lazy';
import { parseAsInteger } from '../../utils/validation';

export default class KeyRmCmd extends Command {
export default class SSHKeyRmCmd extends Command {
public static aliases = ['key rm'];

public static description = stripIndent`
Remove an SSH key from balenaCloud.
Expand All @@ -29,7 +31,10 @@ export default class KeyRmCmd extends Command {
The --yes option may be used to avoid interactive confirmation.
`;

public static examples = ['$ balena key rm 17', '$ balena key rm 17 --yes'];
public static examples = [
'$ balena ssh-key rm 17',
'$ balena ssh-key rm 17 --yes',
];

public static args = {
id: Args.integer({
Expand All @@ -47,7 +52,7 @@ export default class KeyRmCmd extends Command {
public static authenticated = true;

public async run() {
const { args: params, flags: options } = await this.parse(KeyRmCmd);
const { args: params, flags: options } = await this.parse(SSHKeyRmCmd);

const patterns = await import('../../utils/patterns');

Expand Down
8 changes: 4 additions & 4 deletions tests/commands/help.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ ADDITIONAL COMMANDS
env rename <name> <value> change the value of a config or env var for an app, device or service
env rm <id> remove a config or env var from an application, device or service
envs list the environment or config variables of an application, device or service
key <id> display an SSH key
key add <name> [path] add an SSH key to balenaCloud
key list list the SSH keys in balenaCloud
key rm <id> remove an SSH key from balenaCloud
ssh-key <id> display an SSH key
ssh-key add <name> [path] add an SSH key to balenaCloud
ssh-key list list the SSH keys in balenaCloud
ssh-key rm <id> remove an SSH key from balenaCloud
local configure <target> (Re)configure a balenaOS drive or image
local flash <image> flash an image to a drive
logout logout from balena
Expand Down
Loading

0 comments on commit 388e02c

Please sign in to comment.