...
1
2 package add
3
4 import (
5 "fmt"
6
7 "edge-infra.dev/pkg/edge/api/graph/model"
8 "edge-infra.dev/pkg/edge/edgecli/flagutil"
9 "edge-infra.dev/pkg/lib/cli/rags"
10 )
11
12 type RuleMutation struct {
13 UpdateOperatorInterventionRules struct {
14 model.UpdateOperatorInterventionRuleResponse
15 } `graphql:"updateOperatorInterventionRules(rules: $rules)"`
16 }
17
18 func (mut RuleMutation) Errors() []*model.OperatorInterventionErrorResponse {
19 return mut.UpdateOperatorInterventionRules.Errors
20 }
21
22 type Rule struct {
23
24
25 privilege string
26
27
28 commands []string
29 }
30
31 func (cmd *Rule) ShortUsageString() string {
32 return "edgeadmin operatorintervention add rule [--privilege <privilege> --command <command>]"
33 }
34
35 func (cmd *Rule) ShortHelpString() string {
36 return "Add commands to the rule defined by the privilege"
37 }
38
39 func (cmd *Rule) LongHelpString() string {
40 return fmt.Sprintf(longHelpTwoFlagsFormatStr, "rule", "privilege", "command")
41 }
42
43 func (cmd *Rule) Flags() []*rags.Rag {
44 return []*rags.Rag{
45 {
46 Name: flagutil.OIPrivilege,
47 Usage: "privilege whose rule is to be updated",
48 Value: &rags.String{
49 Var: &cmd.privilege,
50 },
51 Required: true,
52 },
53 {
54 Name: flagutil.OICommand,
55 Usage: "command to be added to the rule",
56 Value: &rags.StringSet{
57 Var: &cmd.commands,
58 },
59 Required: true,
60 },
61 }
62 }
63
64 func (cmd *Rule) Variables() map[string]interface{} {
65 var commandsInput []*model.OperatorInterventionCommandInput
66 for _, command := range cmd.commands {
67 commandsInput = append(commandsInput, &model.OperatorInterventionCommandInput{Name: command})
68 }
69 return map[string]interface{}{
70 "rules": []model.UpdateOperatorInterventionRuleInput{
71 {
72 Privilege: &model.OperatorInterventionPrivilegeInput{Name: cmd.privilege},
73 Commands: commandsInput,
74 },
75 },
76 }
77 }
78
79 func (cmd *Rule) Mutation() OperatorInterventionMutation {
80 return &RuleMutation{}
81 }
82
83 func (cmd *Rule) ResponseType() string {
84 return "Rule"
85 }
86
View as plain text