forked from Gitlink/gitlink-cli
94 lines
2.5 KiB
Go
94 lines
2.5 KiB
Go
package sshkey
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/gitlink-org/gitlink-cli/shortcuts/common"
|
|
)
|
|
|
|
func Shortcuts() []*common.Shortcut {
|
|
return []*common.Shortcut{
|
|
{
|
|
Name: "list",
|
|
Description: "List your SSH public keys",
|
|
Long: `List your SSH public keys.
|
|
|
|
Shows all SSH public keys associated with your account, including
|
|
key ID, title, fingerprint, and creation date.
|
|
Supports pagination with --page and --limit flags.`,
|
|
Example: ` # List all SSH keys
|
|
gitlink sshkey +list
|
|
|
|
# List with pagination
|
|
gitlink sshkey +list -p 2 -l 10`,
|
|
Flags: []common.Flag{
|
|
{Name: "page", Short: "p", Usage: "Page number", Default: "1"},
|
|
{Name: "limit", Short: "l", Usage: "Items per page", Default: "20"},
|
|
},
|
|
Run: func(ctx *common.RuntimeContext) error {
|
|
env, err := ctx.CallAPI("GET", "/public_keys", nil)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return ctx.Output(env)
|
|
},
|
|
},
|
|
{
|
|
Name: "create",
|
|
Description: "Add a new SSH public key",
|
|
Long: `Add a new SSH public key.
|
|
|
|
Registers a new SSH public key to your account. The key content must
|
|
be a valid public key in ssh-rsa or ssh-ed25519 format.`,
|
|
Example: ` # Add an SSH key
|
|
gitlink sshkey +create -t "My Laptop" -k "ssh-rsa AAAAB3..."`,
|
|
Flags: []common.Flag{
|
|
{Name: "title", Short: "t", Usage: "Key title", Required: true},
|
|
{Name: "key", Short: "k", Usage: "Public key content (ssh-rsa/ed25519 ...)", Required: true},
|
|
},
|
|
Run: func(ctx *common.RuntimeContext) error {
|
|
title, err := ctx.RequireArg("title")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
key, err := ctx.RequireArg("key")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
payload := map[string]string{
|
|
"title": title,
|
|
"key": key,
|
|
}
|
|
env, err := ctx.CallAPI("POST", "/public_keys", payload)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return ctx.Output(env)
|
|
},
|
|
},
|
|
{
|
|
Name: "delete",
|
|
Description: "Delete an SSH public key",
|
|
Long: `Delete an SSH public key.
|
|
|
|
Removes an SSH public key from your account by its ID. This action cannot be undone.`,
|
|
Example: ` # Delete an SSH key by ID
|
|
gitlink sshkey +delete -i 123`,
|
|
Flags: []common.Flag{
|
|
{Name: "id", Short: "i", Usage: "Key ID to delete", Required: true},
|
|
},
|
|
Run: func(ctx *common.RuntimeContext) error {
|
|
id, err := ctx.RequireArg("id")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
env, err := ctx.CallAPI("DELETE", fmt.Sprintf("/public_keys/%s", id), nil)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return ctx.Output(env)
|
|
},
|
|
},
|
|
}
|
|
}
|