--- a/access/cmd.go Fri Nov 13 23:36:08 2020 -0600
+++ b/access/cmd.go Sat Nov 14 00:07:54 2020 -0600
@@ -3,4 +3,5 @@
Create CreateCmd `kong:"cmd,help='Creates a new api key.'"`
Delete DeleteCmd `kong:"cmd,help='Deletes the given access key.'"`
+ List ListCmd `kong:"cmd,help='Lists the available api keys.'"` --- a/access/delete.go Fri Nov 13 23:36:08 2020 -0600
+++ b/access/delete.go Sat Nov 14 00:07:54 2020 -0600
@@ -8,7 +8,7 @@
- AccessKey string `kong:"arg,help='The access key to delete.'"`
+ AccessKeys []string `kong:"arg,help='The access key to delete.'"` func (c *DeleteCmd) Run() error {
@@ -17,15 +17,20 @@
- AccessKey: c.AccessKey,
- if err := apiKey.Delete(); err != nil {
+ for _, accessKey := range c.AccessKeys { + if err := apiKey.Delete(); err != nil { + fmt.Printf("Failed to remove api key %s: %v\n", accessKey, err) - fmt.Printf("Removed api keys %q\n", c.AccessKey)
+ fmt.Printf("Removed %d api keys\n", removed) --- a/db/apikey.go Fri Nov 13 23:36:08 2020 -0600
+++ b/db/apikey.go Sat Nov 14 00:07:54 2020 -0600
@@ -1,5 +1,9 @@
AccessKey string `db:"access_key"`
SecretKey string `db:"secret_key"`
@@ -26,7 +30,30 @@
func (a APIKey) Delete() error {
query := `DELETE FROM api_keys WHERE access_key=$1;`
- _, err := _db.Exec(query, a.AccessKey)
+ res, err := _db.Exec(query, a.AccessKey) + rows, err := res.RowsAffected() + return fmt.Errorf("access key %s not found", a.AccessKey)
+func ListAPIKeys() ([]APIKey, error) { + query := `SELECT access_key, description FROM api_keys ORDER BY access_key ASC` + if err := _db.Select(&api_keys, query); err != nil {