-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathrbac_delete_subject.go
More file actions
55 lines (46 loc) · 1.38 KB
/
rbac_delete_subject.go
File metadata and controls
55 lines (46 loc) · 1.38 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
//nolint:dupl
package rbac
import (
"github.com/spf13/cobra"
"github.com/stackvista/stackstate-cli/generated/stackstate_api"
"github.com/stackvista/stackstate-cli/internal/common"
"github.com/stackvista/stackstate-cli/internal/di"
)
type DeleteSubjectArgs struct {
Subject string
}
func DeleteSubjectCommand(deps *di.Deps) *cobra.Command {
args := &DeleteSubjectArgs{}
cmd := &cobra.Command{
Use: "delete-subject",
Short: "Delete a security subject",
Long: "Delete a security subject and revoke all its permissions. This operation cannot be undone.",
Example: `# delete a subject
sts rbac delete-subject --subject my-team`,
RunE: deps.CmdRunEWithApi(RunDeleteSubjectCommand(args)),
}
cmd.Flags().StringVar(&args.Subject, Subject, "", SubjectUsage)
cmd.MarkFlagRequired(Subject) //nolint:errcheck
return cmd
}
func RunDeleteSubjectCommand(args *DeleteSubjectArgs) di.CmdWithApiFn {
return func(
cmd *cobra.Command,
cli *di.Deps,
api *stackstate_api.APIClient,
serverInfo *stackstate_api.ServerInfo,
) common.CLIError {
resp, err := api.SubjectApi.DeleteSubject(cli.Context, args.Subject).Execute()
if err != nil {
return common.NewResponseError(err, resp)
}
if cli.IsJson() {
cli.Printer.PrintJson(map[string]interface{}{
"deleted-subject": args.Subject,
})
} else {
cli.Printer.Successf("Deleted subject '%s'", args.Subject)
}
return nil
}
}