Documentation
¶
Overview ¶
Package profiles contains business logic relating to the Profile entity in Minder
Index ¶
- func ComputeRuleName(rule *minderv1.Profile_Rule) string
- func GetRulesForEntity(p *pb.Profile, entity pb.Entity) ([]*pb.Profile_Rule, error)
- func MergeDatabaseGetIntoProfiles(ppl []db.GetProfileByProjectAndIDRow) map[string]*pb.Profile
- func MergeDatabaseListIntoProfiles[T db.ProfileRow](ppl []T) map[string]*pb.Profile
- func ParseJSON(r io.Reader) (*pb.Profile, error)
- func ParseYAML(r io.Reader) (*pb.Profile, error)
- func PopulateRuleNames(profile *minderv1.Profile)
- func ReadProfileFromFile(fpath string) (*pb.Profile, error)
- func TraverseAllRulesForPipeline(p *pb.Profile, fn func(*pb.Profile_Rule) error) error
- func TraverseRuleTypesForEntities(p *pb.Profile, fn func(pb.Entity, *pb.Profile_Rule) error) error
- func TraverseRules(rules []*pb.Profile_Rule, fn func(*pb.Profile_Rule) error) error
- type EntityAndRuleTuple
- type ProfileService
- type RuleMapping
- type RuleTypeAndNamePair
- type RuleValidationError
- type RuleValidator
- type Validator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ComputeRuleName ¶
func ComputeRuleName(rule *minderv1.Profile_Rule) string
ComputeRuleName returns the rule instance's name, or generates a default one
func GetRulesForEntity ¶ added in v0.0.52
GetRulesForEntity returns the rules for the given entity
func MergeDatabaseGetIntoProfiles ¶ added in v0.0.52
func MergeDatabaseGetIntoProfiles(ppl []db.GetProfileByProjectAndIDRow) map[string]*pb.Profile
MergeDatabaseGetIntoProfiles merges the database get profiles into the given profiles map. This assumes that the profiles belong to the same project.
TODO(jaosorior): This will have to consider the project tree once we migrate to that
func MergeDatabaseListIntoProfiles ¶ added in v0.0.52
func MergeDatabaseListIntoProfiles[T db.ProfileRow](ppl []T) map[string]*pb.Profile
MergeDatabaseListIntoProfiles merges the database list profiles into the given profiles map. This assumes that the profiles belong to the same project.
TODO(jaosorior): This will have to consider the project tree once we migrate to that
func PopulateRuleNames ¶
PopulateRuleNames fills in the rule name for all rule instances in a profile
func ReadProfileFromFile ¶ added in v0.0.52
ReadProfileFromFile reads a pipeline profile from a file and returns it as a protobuf
func TraverseAllRulesForPipeline ¶ added in v0.0.52
TraverseAllRulesForPipeline traverses all rules for the given pipeline profile
func TraverseRuleTypesForEntities ¶ added in v0.0.52
TraverseRuleTypesForEntities traverses the rules for the given entities and calls the given function
func TraverseRules ¶ added in v0.0.52
func TraverseRules(rules []*pb.Profile_Rule, fn func(*pb.Profile_Rule) error) error
TraverseRules traverses the rules and calls the given function for each rule TODO: do we want to collect and return _all_ errors, rather than just the first, to prevent whack-a-mole fixing?
Types ¶
type EntityAndRuleTuple ¶
EntityAndRuleTuple is a tuple that allows us track rule instantiations and the entity they're associated with
type ProfileService ¶ added in v0.0.36
type ProfileService interface {
// CreateProfile creates the profile in the specified project
// returns the updated profile structure on successful update
// subscriptionID should be set to nil when not calling
CreateProfile(
ctx context.Context,
projectID uuid.UUID,
subscriptionID uuid.UUID,
profile *minderv1.Profile,
qtx db.Querier,
) (*minderv1.Profile, error)
// UpdateProfile updates the profile in the specified project
// returns the updated profile structure on successful update
UpdateProfile(
ctx context.Context,
projectID uuid.UUID,
subscriptionID uuid.UUID,
profile *minderv1.Profile,
qtx db.Querier,
) (*minderv1.Profile, error)
// PatchProfile updates the profile in the specified project
// by applying the changes in the provided profile structure
// as specified by the updateMask
PatchProfile(
ctx context.Context,
projectID uuid.UUID,
profileID uuid.UUID,
profile *minderv1.Profile,
updateMask *fieldmaskpb.FieldMask,
qtx db.Querier,
) (*minderv1.Profile, error)
}
ProfileService encapsulates methods for creating and updating profiles TODO: other methods such as deletion and patch should be moved here
func NewProfileService ¶ added in v0.0.36
func NewProfileService(publisher events.Publisher) ProfileService
NewProfileService creates an instance of ProfileService
type RuleMapping ¶
type RuleMapping map[RuleTypeAndNamePair]EntityAndRuleTuple
RuleMapping is a mapping of rule instance info (name + type) to entity info (rule ID + entity type)
type RuleTypeAndNamePair ¶
RuleTypeAndNamePair is a tuple of a rule instance's name and rule type name
type RuleValidationError ¶ added in v0.0.52
RuleValidationError is used to report errors from evaluating a rule, including attribution of the particular error encountered.
func (*RuleValidationError) Error ¶ added in v0.0.52
func (e *RuleValidationError) Error() string
Error implements error.Error
func (*RuleValidationError) String ¶ added in v0.0.52
func (e *RuleValidationError) String() string
String implements fmt.Stringer
type RuleValidator ¶ added in v0.0.52
type RuleValidator struct {
// contains filtered or unexported fields
}
RuleValidator takes a rule type and validates an instance of it. The main purpose of this is to validate the schemas that are associated with the rule.
func NewRuleValidator ¶ added in v0.0.52
func NewRuleValidator(rt *minderv1.RuleType) (*RuleValidator, error)
NewRuleValidator creates a new rule validator
func (*RuleValidator) ValidateParamsAgainstSchema ¶ added in v0.0.52
func (r *RuleValidator) ValidateParamsAgainstSchema(params *structpb.Struct) error
ValidateParamsAgainstSchema validates the given parameters against the schema for this rule type
func (*RuleValidator) ValidateRuleDefAgainstSchema ¶ added in v0.0.52
func (r *RuleValidator) ValidateRuleDefAgainstSchema(contextualProfile map[string]any) error
ValidateRuleDefAgainstSchema validates the given contextual profile against the schema for this rule type
type Validator ¶
type Validator struct{}
Validator encapsulates the logic for validating profiles
func (*Validator) ValidateAndExtractRules ¶
func (v *Validator) ValidateAndExtractRules( ctx context.Context, qtx db.Querier, projectID uuid.UUID, profile *minderv1.Profile, ) (RuleMapping, error)
ValidateAndExtractRules validates a profile to ensure it is well-formed it also returns information about the rules in the profile
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package mock_profiles is a generated GoMock package.
|
Package mock_profiles is a generated GoMock package. |
|
fixtures
Package fixtures contains code for creating ProfileService fixtures and is used in various parts of the code.
|
Package fixtures contains code for creating ProfileService fixtures and is used in various parts of the code. |