diff --git a/internal/db/domain.go b/internal/db/domain.go index 74159151de..75ab139d6c 100644 --- a/internal/db/domain.go +++ b/internal/db/domain.go @@ -32,6 +32,7 @@ func (p *Provider) CanImplement(impl ProviderType) bool { type ProfileRow interface { GetProfile() Profile GetEntityProfile() NullEntities + GetSelectors() []ProfileSelector GetContextualRules() pqtype.NullRawMessage } @@ -50,6 +51,11 @@ func (r ListProfilesByProjectIDAndLabelRow) GetContextualRules() pqtype.NullRawM return r.ProfilesWithEntityProfile.ContextualRules } +// GetSelectors returns the selectors +func (r ListProfilesByProjectIDAndLabelRow) GetSelectors() []ProfileSelector { + return r.ProfilesWithSelectors +} + // GetProfile returns the profile func (r ListProfilesByProjectIDRow) GetProfile() Profile { return r.Profile @@ -65,6 +71,11 @@ func (r ListProfilesByProjectIDRow) GetContextualRules() pqtype.NullRawMessage { return r.ProfilesWithEntityProfile.ContextualRules } +// GetSelectors returns the selectors +func (r ListProfilesByProjectIDRow) GetSelectors() []ProfileSelector { + return r.ProfilesWithSelectors +} + // LabelsFromFilter parses the filter string and populates the IncludeLabels and ExcludeLabels fields func (lp *ListProfilesByProjectIDAndLabelParams) LabelsFromFilter(filter string) { // If s does not contain sep and sep is not empty, Split returns a diff --git a/internal/profiles/util.go b/internal/profiles/util.go index 766b42913b..6eb336d26c 100644 --- a/internal/profiles/util.go +++ b/internal/profiles/util.go @@ -212,6 +212,8 @@ func MergeDatabaseListIntoProfiles[T db.ProfileRow](ppl []T) map[string]*pb.Prof } else { profiles[p.GetProfile().Name].Alert = proto.String(string(db.ActionTypeOn)) } + + selectorsToProfile(profiles[p.GetProfile().Name], p.GetSelectors()) } if pm := rowInfoToProfileMap( profiles[p.GetProfile().Name], p.GetEntityProfile(), @@ -266,6 +268,8 @@ func MergeDatabaseGetIntoProfiles(ppl []db.GetProfileByProjectAndIDRow) map[stri } else { profiles[p.Profile.Name].Alert = proto.String(string(db.ActionTypeOn)) } + + selectorsToProfile(profiles[p.Profile.Name], p.ProfilesWithSelectors) } if pm := rowInfoToProfileMap( profiles[p.Profile.Name], @@ -325,3 +329,18 @@ func rowInfoToProfileMap( return profile } + +func selectorsToProfile( + profile *pb.Profile, + selectors []db.ProfileSelector, +) { + profile.Selection = make([]*pb.Profile_Selector, 0, len(selectors)) + for _, s := range selectors { + profile.Selection = append(profile.Selection, &pb.Profile_Selector{ + Id: s.ID.String(), + Entity: string(s.Entity.Entities), + Selector: s.Selector, + Comment: s.Comment, + }) + } +}