...

Source file src/edge-infra.dev/pkg/edge/edgeadmin/commands/operatorintervention/add/role_mapping.go

Documentation: edge-infra.dev/pkg/edge/edgeadmin/commands/operatorintervention/add

     1  //nolint:dupl
     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 RoleMappingMutation struct {
    13  	UpdateOperatorInterventionRoleMappings struct {
    14  		model.UpdateOperatorInterventionRoleMappingResponse
    15  	} `graphql:"updateOperatorInterventionRoleMappings(roleMappings: $roleMappings)"`
    16  }
    17  
    18  func (mut RoleMappingMutation) Errors() []*model.OperatorInterventionErrorResponse {
    19  	return mut.UpdateOperatorInterventionRoleMappings.Errors
    20  }
    21  
    22  type RoleMapping struct {
    23  	// Role associated with a role-mapping to be updated on the db.
    24  	// Initialized during the cli pkg's flag parse method.
    25  	role string
    26  	// Privileges to be added to the role-mapping on db.
    27  	// Initialized during the cli pkg's flag parse method.
    28  	privileges []string
    29  }
    30  
    31  func (rm *RoleMapping) ShortUsageString() string {
    32  	return "edgeadmin operatorintervention add role-mapping [--role <role> --privilege <privilege>]"
    33  }
    34  
    35  func (rm *RoleMapping) ShortHelpString() string {
    36  	return "Adds privileges to a specified role"
    37  }
    38  
    39  func (rm *RoleMapping) LongHelpString() string {
    40  	return fmt.Sprintf(longHelpTwoFlagsFormatStr, "role-mapping", "role", "privilege")
    41  }
    42  
    43  func (rm *RoleMapping) Flags() []*rags.Rag {
    44  	return []*rags.Rag{
    45  		{
    46  			Name:  flagutil.OIRole,
    47  			Usage: "role whose mapping is to be updated",
    48  			Value: &rags.String{
    49  				Var: &rm.role,
    50  			},
    51  			Required: true,
    52  		},
    53  		{
    54  			Name:  flagutil.OIPrivilege,
    55  			Usage: "privilege to be added to the role-mapping",
    56  			Value: &rags.StringSet{
    57  				Var: &rm.privileges,
    58  			},
    59  			Required: true,
    60  		},
    61  	}
    62  }
    63  
    64  func (rm *RoleMapping) Variables() map[string]interface{} {
    65  	var privilegesInput []*model.OperatorInterventionPrivilegeInput
    66  	for _, priv := range rm.privileges {
    67  		privilegesInput = append(privilegesInput, &model.OperatorInterventionPrivilegeInput{Name: priv})
    68  	}
    69  	return map[string]interface{}{
    70  		"roleMappings": []model.UpdateOperatorInterventionRoleMappingInput{
    71  			{
    72  				Role:       rm.role,
    73  				Privileges: privilegesInput,
    74  			},
    75  		},
    76  	}
    77  }
    78  
    79  func (rm *RoleMapping) Mutation() OperatorInterventionMutation {
    80  	return &RoleMappingMutation{}
    81  }
    82  
    83  func (rm *RoleMapping) ResponseType() string {
    84  	return "Role Mapping"
    85  }
    86  

View as plain text