//nolint:dupl package add import ( "fmt" "edge-infra.dev/pkg/edge/api/graph/model" "edge-infra.dev/pkg/edge/edgecli/flagutil" "edge-infra.dev/pkg/lib/cli/rags" ) type RuleMutation struct { UpdateOperatorInterventionRules struct { model.UpdateOperatorInterventionRuleResponse } `graphql:"updateOperatorInterventionRules(rules: $rules)"` } func (mut RuleMutation) Errors() []*model.OperatorInterventionErrorResponse { return mut.UpdateOperatorInterventionRules.Errors } type Rule struct { // Privilege associated with a rule to be updated on the db. // Initialized during the cli pkg's flag parse method. privilege string // Commands associated with a rule to be added to the rule on db. // Initialized during the cli pkg's flag parse method. commands []string } func (cmd *Rule) ShortUsageString() string { return "edgeadmin operatorintervention add rule [--privilege --command ]" } func (cmd *Rule) ShortHelpString() string { return "Add commands to the rule defined by the privilege" } func (cmd *Rule) LongHelpString() string { return fmt.Sprintf(longHelpTwoFlagsFormatStr, "rule", "privilege", "command") } func (cmd *Rule) Flags() []*rags.Rag { return []*rags.Rag{ { Name: flagutil.OIPrivilege, Usage: "privilege whose rule is to be updated", Value: &rags.String{ Var: &cmd.privilege, }, Required: true, }, { Name: flagutil.OICommand, Usage: "command to be added to the rule", Value: &rags.StringSet{ Var: &cmd.commands, }, Required: true, }, } } func (cmd *Rule) Variables() map[string]interface{} { var commandsInput []*model.OperatorInterventionCommandInput for _, command := range cmd.commands { commandsInput = append(commandsInput, &model.OperatorInterventionCommandInput{Name: command}) } return map[string]interface{}{ "rules": []model.UpdateOperatorInterventionRuleInput{ { Privilege: &model.OperatorInterventionPrivilegeInput{Name: cmd.privilege}, Commands: commandsInput, }, }, } } func (cmd *Rule) Mutation() OperatorInterventionMutation { return &RuleMutation{} } func (cmd *Rule) ResponseType() string { return "Rule" }