...
1 package delete
2
3 import (
4 "context"
5
6 "github.com/peterbourgon/ff/v3"
7
8 "edge-infra.dev/pkg/edge/api/graph/model"
9 "edge-infra.dev/pkg/edge/edgeadmin/commands/operatorintervention/edgeextension"
10 "edge-infra.dev/pkg/edge/edgecli"
11 "edge-infra.dev/pkg/edge/edgecli/flagutil"
12 "edge-infra.dev/pkg/lib/cli/command"
13 "edge-infra.dev/pkg/lib/cli/rags"
14 )
15
16 func NewDeleteRoleMapping(cfg *edgecli.Config) *command.Command {
17 var (
18 edge = &edgeextension.Ext{Cfg: cfg}
19 )
20
21 var cmd *command.Command
22 cmd = &command.Command{
23 ShortUsage: "edge operatorintervention delete role-mapping",
24 ShortHelp: "Deletes a single privilege from an existing role mapping",
25 Options: []ff.Option{},
26 Flags: []*rags.Rag{
27 {
28 Name: flagutil.OIRole,
29 Usage: "Role whose mapping is to be updated",
30 Value: &rags.String{},
31 Required: true,
32 },
33 {
34 Name: flagutil.OIPrivilege,
35 Usage: "Privilege to be removed from the role mapping",
36 Value: &rags.String{},
37 Required: true,
38 },
39 },
40
41 Extensions: []command.Extension{edge},
42
43 Exec: func(ctx context.Context, _ []string) error {
44 var mutation struct {
45 DeleteOperatorInterventionRoleMapping struct {
46 model.DeleteOperatorInterventionResponse
47 } `graphql:"deleteOperatorInterventionRoleMapping(mapping: $mapping)"`
48 }
49
50 var variables = map[string]interface{}{
51 "mapping": model.DeleteOperatorInterventionMappingInput{
52 Role: flagutil.GetStringFlag(cmd.Rags, flagutil.OIRole),
53 Privilege: &model.OperatorInterventionPrivilegeInput{Name: flagutil.GetStringFlag(cmd.Rags, flagutil.OIPrivilege)},
54 },
55 }
56
57 err := edge.Client.Mutate(ctx, &mutation, variables)
58 if err != nil {
59 return err
60 }
61
62 return handleResponseFormatting(
63 "Role Mapping",
64 mutation.DeleteOperatorInterventionRoleMapping.Errors,
65 )
66 },
67 }
68 return cmd
69 }
70
View as plain text