...

Source file src/edge-infra.dev/pkg/sds/emergencyaccess/rules/rulesengine.go

Documentation: edge-infra.dev/pkg/sds/emergencyaccess/rules

     1  package rulesengine
     2  
     3  import (
     4  	"context"
     5  )
     6  
     7  type Dataset interface {
     8  	// validation methods
     9  	EARoles(ctx context.Context, bannerID string, command Command) ([]string, error)
    10  
    11  	// admin methods
    12  	AddCommands(ctx context.Context, names []string) (AddNameResult, error)
    13  	AddPrivileges(ctx context.Context, names []string) (AddNameResult, error)
    14  	AddDefaultRules(ctx context.Context, rules []RuleSegment) (AddRuleResult, error)
    15  
    16  	DeleteCommand(ctx context.Context, name string) (DeleteResult, error)
    17  	DeletePrivilege(ctx context.Context, name string) (DeleteResult, error)
    18  	DeleteDefaultRule(ctx context.Context, commandName, privilegeName string) (DeleteResult, error)
    19  
    20  	ReadAllCommands(ctx context.Context) ([]Command, error)
    21  	ReadCommandsWithFilter(ctx context.Context, names []string) ([]Command, error)
    22  	ReadCommand(ctx context.Context, name string) (Command, error)
    23  	ReadAllPrivileges(ctx context.Context) ([]Privilege, error)
    24  	ReadPrivilegesWithFilter(ctx context.Context, filter []string) ([]Privilege, error)
    25  	ReadPrivilege(ctx context.Context, name string) (Privilege, error)
    26  	ReadAllDefaultRules(ctx context.Context) ([]RuleSegment, error)
    27  	ReadDefaultRulesForCommand(ctx context.Context, commandName string) ([]RuleSegment, error)
    28  
    29  	// banner admin methods
    30  	ReadRulesForAllBanners(ctx context.Context) ([]RuleSegment, error)
    31  	AddBannerRules(ctx context.Context, rules []RuleSegment) (feedback AddRuleResult, err error)
    32  	ReadRulesForBanner(ctx context.Context, bannerName string) ([]RuleSegment, error)
    33  	ReadBannerRulesForCommandAndBanner(ctx context.Context, bannerName string, commandName string) ([]RuleSegment, error)
    34  	ReadBannerRulesForCommand(ctx context.Context, commandName string) ([]RuleSegment, error)
    35  	DeletePrivilegeFromBannerRule(ctx context.Context, bannerName, commandName, privilegeName string) (DeleteResult, error)
    36  }
    37  
    38  const (
    39  	// maxCommands is the maximum number of commands that can be inserted as a single request.
    40  	maxCommands = 500
    41  
    42  	// maxPrivileges is the maximum number of privileges that can be inserted as a single request.
    43  	maxPrivileges = 500
    44  
    45  	// maxRules is the maximum number of rules that can be inserted as a single request.
    46  	maxRules = 500
    47  )
    48  
    49  type RulesEngine struct {
    50  	ds Dataset
    51  }
    52  
    53  func New(ds Dataset) RulesEngine {
    54  	return RulesEngine{ds: ds}
    55  }
    56  

View as plain text