profiles

package
v0.0.68 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 17, 2024 License: Apache-2.0 Imports: 36 Imported by: 0

Documentation

Overview

Package profiles contains business logic relating to the Profile entity in Minder

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComputeRuleName

func ComputeRuleName(rule *minderv1.Profile_Rule, ruleTypeDisplayName string) string

ComputeRuleName returns the rule instance's name, or generates a default one

func DeriveProfileNameFromDisplayName

func DeriveProfileNameFromDisplayName(
	profile *pb.Profile,
	existingProfileNames []string,
) (name string)

DeriveProfileNameFromDisplayName generates a unique profile name based on the display name and existing profiles.

func GetRulesForEntity

func GetRulesForEntity(p *pb.Profile, entity pb.Entity) ([]*pb.Profile_Rule, error)

GetRulesForEntity returns the rules for the given entity

func GetRulesFromProfileOfType added in v0.0.67

func GetRulesFromProfileOfType(p *pb.Profile, rt *pb.RuleType) ([]*pb.Profile_Rule, error)

GetRulesFromProfileOfType returns the rules from the profile of the given type

func MergeDatabaseGetByNameIntoProfiles

func MergeDatabaseGetByNameIntoProfiles(ppl []db.GetProfileByProjectAndNameRow) map[string]*pb.Profile

MergeDatabaseGetByNameIntoProfiles merges the database get profiles into the given profiles map. This assumes that the profiles belong to the same project.

TODO: This will have to consider the project tree once we migrate to that

func MergeDatabaseGetIntoProfiles

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

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 ParseJSON

func ParseJSON(r io.Reader) (*pb.Profile, error)

ParseJSON parses a JSON pipeline profile and validates it

func ParseYAML

func ParseYAML(r io.Reader) (*pb.Profile, error)

ParseYAML parses a YAML pipeline profile and validates it

func PopulateRuleNames

func PopulateRuleNames(profile *minderv1.Profile, rules RuleMapping)

PopulateRuleNames fills in the rule name for all rule instances in a profile

func ReadProfileFromFile

func ReadProfileFromFile(fpath string) (*pb.Profile, error)

ReadProfileFromFile reads a pipeline profile from a file and returns it as a protobuf

func TraverseAllRulesForPipeline

func TraverseAllRulesForPipeline(p *pb.Profile, fn func(*pb.Profile_Rule) error) error

TraverseAllRulesForPipeline traverses all rules for the given pipeline profile

func TraverseRuleTypesForEntities

func TraverseRuleTypesForEntities(p *pb.Profile, fn func(pb.Entity, *pb.Profile_Rule) error) error

TraverseRuleTypesForEntities traverses the rules for the given entities and calls the given function

func TraverseRules

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 ProfileService

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

func NewProfileService(
	publisher events.Publisher,
	selChecker selectors.SelectionChecker,
) ProfileService

NewProfileService creates an instance of ProfileService

type ProfileStore

type ProfileStore interface {
	GetProfilesForEvaluation(
		ctx context.Context,
		projectID uuid.UUID,
		entityType db.Entities,
	) ([]models.ProfileAggregate, error)
}

ProfileStore encapsulates operations for fetching ProfileAggregates

func NewProfileStore

func NewProfileStore(store db.Store) ProfileStore

NewProfileStore creates an instance of ProfileStore

type RuleIdAndNamePair

type RuleIdAndNamePair struct {
	RuleID          uuid.UUID
	DerivedRuleName string
}

RuleIdAndNamePair is a tuple of a rule's instance ID and the name derived from the rule's descriptive name and rule type name

type RuleMapping

type RuleMapping map[RuleTypeAndNamePair]RuleIdAndNamePair

RuleMapping is a mapping of rule instance info (name + type) to entity info (rule ID + entity type)

type RuleTypeAndNamePair

type RuleTypeAndNamePair struct {
	RuleType string
	RuleName string
}

RuleTypeAndNamePair is a tuple of a rule instance's name and rule type name

type RuleValidationError

type RuleValidationError struct {
	Err string
	// RuleType is a rule name
	RuleType string
}

RuleValidationError is used to report errors from evaluating a rule, including attribution of the particular error encountered.

func (*RuleValidationError) Error

func (e *RuleValidationError) Error() string

Error implements error.Error

func (*RuleValidationError) String

func (e *RuleValidationError) String() string

String implements fmt.Stringer

type RuleValidator

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

func NewRuleValidator(rt *minderv1.RuleType) (*RuleValidator, error)

NewRuleValidator creates a new rule validator

func (*RuleValidator) ValidateParamsAgainstSchema

func (r *RuleValidator) ValidateParamsAgainstSchema(params map[string]any) error

ValidateParamsAgainstSchema validates the given parameters against the schema for this rule type

func (*RuleValidator) ValidateRuleDefAgainstSchema

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 {
	// contains filtered or unexported fields
}

Validator encapsulates the logic for validating profiles

func NewValidator

func NewValidator(selBld selectors.SelectionChecker) *Validator

NewValidator creates a new profile validator

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

func (*Validator) ValidateSelection

func (v *Validator) ValidateSelection(
	selection []*minderv1.Profile_Selector,
) error

ValidateSelection validates the selectors in a profile

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.
Package models contains domain models for profiles
Package models contains domain models for profiles

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL