forked from Gitlink/gitlink-cli
73 lines
1.7 KiB
Go
73 lines
1.7 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",
|
|
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",
|
|
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",
|
|
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)
|
|
},
|
|
},
|
|
}
|
|
}
|