Skip to content

Commit

Permalink
key: list, create, delete
Browse files Browse the repository at this point in the history
  • Loading branch information
sj14 committed Apr 30, 2024
1 parent 33f0777 commit fa29a24
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ VERSION:
COMMANDS:
activity List activities
system Manage system
system Manage the system
user Manage users
library Manage media libraries
key Manage API tokens
help, h Shows a list of commands or help for one command
GLOBAL OPTIONS:
Expand Down
35 changes: 35 additions & 0 deletions controller/key.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package controller

import (
"fmt"
"time"
)

func (c *Controller) KeyCreate(app string) error {
_, err := c.client.ApiKeyAPI.CreateKey(c.ctx).App(app).Execute()
return err
}

func (c *Controller) KeyDelete(key string) error {
_, err := c.client.ApiKeyAPI.RevokeKey(c.ctx, key).Execute()
return err
}

func (c *Controller) KeyList() error {
result, _, err := c.client.ApiKeyAPI.GetKeys(c.ctx).Execute()
if err != nil {
return err
}

fmt.Printf("Token Created Name\n")
fmt.Printf("---------------------------------|---------------------|-----\n")
for _, key := range result.Items {
fmt.Printf("%s %s %s\n",
key.GetAccessToken(),
key.GetDateCreated().Local().Format(time.DateTime),
key.GetAppName(),
)
}

return nil
}
37 changes: 37 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,43 @@ func main() {
},
},
},
{
Name: "key",
Usage: "Manage API tokens",
Subcommands: []*cli.Command{
{
Name: "list",
Usage: "Show keys",
Action: func(ctx *cli.Context) error {
return Exec(ctx, func(ctrl *controller.Controller) error {
return ctrl.KeyList()
})
},
},
{
Name: "create",
Usage: "Add a new key",
Args: true,
ArgsUsage: " <NAME>",
Action: func(ctx *cli.Context) error {
return Exec(ctx, func(ctrl *controller.Controller) error {
return ctrl.KeyCreate(ctx.Args().Get(0))
})
},
},
{
Name: "delete",
Usage: "Remove a key",
Args: true,
ArgsUsage: " <TOKEN>",
Action: func(ctx *cli.Context) error {
return Exec(ctx, func(ctrl *controller.Controller) error {
return ctrl.KeyDelete(ctx.Args().Get(0))
})
},
},
},
},
},
}

Expand Down

0 comments on commit fa29a24

Please sign in to comment.