-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrevoke_api_key.go
More file actions
55 lines (43 loc) · 1.13 KB
/
revoke_api_key.go
File metadata and controls
55 lines (43 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright (c) Codesphere Inc.
// SPDX-License-Identifier: Apache-2.0
package cmd
import (
"fmt"
"github.com/codesphere-cloud/cs-go/pkg/io"
"github.com/codesphere-cloud/oms/internal/portal"
"github.com/codesphere-cloud/oms/internal/util"
"github.com/spf13/cobra"
)
type RevokeAPIKeyCmd struct {
cmd *cobra.Command
Opts RevokeAPIKeyOpts
}
type RevokeAPIKeyOpts struct {
GlobalOptions
ID string
}
func (c *RevokeAPIKeyCmd) RunE(_ *cobra.Command, args []string) error {
p := portal.NewPortalClient()
return c.Revoke(p)
}
func (c *RevokeAPIKeyCmd) Revoke(p portal.Portal) error {
err := p.RevokeAPIKey(c.Opts.ID)
if err != nil {
return fmt.Errorf("failed to revoke API key: %w", err)
}
return nil
}
func AddRevokeAPIKeyCmd(list *cobra.Command, opts GlobalOptions) {
c := RevokeAPIKeyCmd{
cmd: &cobra.Command{
Use: "api-key",
Short: "Revoke an API key",
Long: io.Long(`Revoke an OMS portal API key.`),
},
Opts: RevokeAPIKeyOpts{GlobalOptions: opts},
}
c.cmd.Flags().StringVarP(&c.Opts.ID, "id", "i", "", "API key id to revoke")
util.MarkFlagRequired(c.cmd, "id")
c.cmd.RunE = c.RunE
list.AddCommand(c.cmd)
}