//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 RoleMappingMutation struct { UpdateOperatorInterventionRoleMappings struct { model.UpdateOperatorInterventionRoleMappingResponse } `graphql:"updateOperatorInterventionRoleMappings(roleMappings: $roleMappings)"` } func (mut RoleMappingMutation) Errors() []*model.OperatorInterventionErrorResponse { return mut.UpdateOperatorInterventionRoleMappings.Errors } type RoleMapping struct { // Role associated with a role-mapping to be updated on the db. // Initialized during the cli pkg's flag parse method. role string // Privileges to be added to the role-mapping on db. // Initialized during the cli pkg's flag parse method. privileges []string } func (rm *RoleMapping) ShortUsageString() string { return "edgeadmin operatorintervention add role-mapping [--role --privilege ]" } func (rm *RoleMapping) ShortHelpString() string { return "Adds privileges to a specified role" } func (rm *RoleMapping) LongHelpString() string { return fmt.Sprintf(longHelpTwoFlagsFormatStr, "role-mapping", "role", "privilege") } func (rm *RoleMapping) Flags() []*rags.Rag { return []*rags.Rag{ { Name: flagutil.OIRole, Usage: "role whose mapping is to be updated", Value: &rags.String{ Var: &rm.role, }, Required: true, }, { Name: flagutil.OIPrivilege, Usage: "privilege to be added to the role-mapping", Value: &rags.StringSet{ Var: &rm.privileges, }, Required: true, }, } } func (rm *RoleMapping) Variables() map[string]interface{} { var privilegesInput []*model.OperatorInterventionPrivilegeInput for _, priv := range rm.privileges { privilegesInput = append(privilegesInput, &model.OperatorInterventionPrivilegeInput{Name: priv}) } return map[string]interface{}{ "roleMappings": []model.UpdateOperatorInterventionRoleMappingInput{ { Role: rm.role, Privileges: privilegesInput, }, }, } } func (rm *RoleMapping) Mutation() OperatorInterventionMutation { return &RoleMappingMutation{} } func (rm *RoleMapping) ResponseType() string { return "Role Mapping" }