-
Notifications
You must be signed in to change notification settings - Fork 2
[LFXV2-932] Add CommitteeMemberSensitive enricher object #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mauriciozanettisalomao
wants to merge
4
commits into
linuxfoundation:main
Choose a base branch
from
mauriciozanettisalomao:feat/lfxv2-932-committee-member-sensitive-data
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+903
−21
Open
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
25077d1
(feat): Add CommitteeMemberSensitiveEnricher and update object types …
mauriciozanettisalomao 3bc794f
feat: Add unit and integration tests for CommitteeMemberSensitiveEnri…
mauriciozanettisalomao 9fb528f
chore: Bump chart version to 0.4.13
mauriciozanettisalomao 92f8980
feat: Update comments for CommitteeMemberSensitiveEnricher and its co…
mauriciozanettisalomao File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
140 changes: 140 additions & 0 deletions
140
internal/enrichers/committee_member_sensitive_enricher.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| // Copyright The Linux Foundation and each contributor to LFX. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| // Package enrichers provides data enrichment functionality for different object types. | ||
| package enrichers | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "regexp" | ||
| "strings" | ||
|
|
||
| "github.com/linuxfoundation/lfx-v2-indexer-service/internal/domain/contracts" | ||
| "github.com/linuxfoundation/lfx-v2-indexer-service/pkg/constants" | ||
| ) | ||
|
|
||
| // CommitteeMemberEnricher handles committee-specific enrichment logic | ||
| type CommitteeMemberSensitiveEnricher struct { | ||
mauriciozanettisalomao marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| defaultEnricher Enricher | ||
| } | ||
|
|
||
| // ObjectType returns the object type this enricher handles. | ||
| func (e *CommitteeMemberSensitiveEnricher) ObjectType() string { | ||
| return e.defaultEnricher.ObjectType() | ||
| } | ||
|
|
||
| // EnrichData enriches committee-specific data | ||
| func (e *CommitteeMemberSensitiveEnricher) EnrichData(body *contracts.TransactionBody, transaction *contracts.LFXTransaction) error { | ||
| return e.defaultEnricher.EnrichData(body, transaction) | ||
| } | ||
|
|
||
| // setAccessControl provides committee-member-sensitive-specific access control logic | ||
| // overrides the default access control logic | ||
| // Since it's a sensitive object, the access control logic is set to auditor/writer on the committee level | ||
| func (e *CommitteeMemberSensitiveEnricher) setAccessControl(body *contracts.TransactionBody, data map[string]any, objectType, objectID string) { | ||
|
|
||
| committeeLevelPermission := func(data map[string]any) string { | ||
| if value, ok := data["committee_uid"]; ok { | ||
| if committeeUID, ok := value.(string); ok { | ||
| return fmt.Sprintf("%s:%s", constants.ObjectTypeCommittee, committeeUID) | ||
| } | ||
| } | ||
| return fmt.Sprintf("%s:%s", objectType, objectID) | ||
| } | ||
|
|
||
| // Build access control values | ||
| var accessObject, accessRelation string | ||
| var historyObject, historyRelation string | ||
|
|
||
| // Set access control with committee-member-specific logic | ||
| // This logic represents the access via endpoint where the committee member is retrieved | ||
| // when the user has access to the committee. | ||
| if accessCheckObject, ok := data["accessCheckObject"].(string); ok { | ||
| // Field exists in data (even if empty) - use data value | ||
| accessObject = accessCheckObject | ||
| } else if _, exists := data["accessCheckObject"]; !exists { | ||
| accessObject = committeeLevelPermission(data) | ||
| } | ||
|
|
||
| // Access check relation | ||
| if accessCheckRelation, ok := data["accessCheckRelation"].(string); ok { | ||
| accessRelation = accessCheckRelation | ||
| } else if _, exists := data["accessCheckRelation"]; !exists { | ||
| accessRelation = "auditor" | ||
| } | ||
|
|
||
| // History check object | ||
| if historyCheckObject, ok := data["historyCheckObject"].(string); ok { | ||
| historyObject = historyCheckObject | ||
| } else if _, exists := data["historyCheckObject"]; !exists { | ||
| historyObject = committeeLevelPermission(data) | ||
| } | ||
|
|
||
| // History check relation | ||
| if historyCheckRelation, ok := data["historyCheckRelation"].(string); ok { | ||
| historyRelation = historyCheckRelation | ||
| } else if _, exists := data["historyCheckRelation"]; !exists { | ||
| historyRelation = "writer" | ||
| } | ||
|
|
||
| // Assign to body fields (deprecated fields) | ||
| body.AccessCheckObject = accessObject | ||
| body.AccessCheckRelation = accessRelation | ||
| body.HistoryCheckObject = historyObject | ||
| body.HistoryCheckRelation = historyRelation | ||
|
|
||
| // Build and assign the query strings | ||
| if accessObject != "" && accessRelation != "" { | ||
| body.AccessCheckQuery = contracts.JoinFgaQuery(accessObject, accessRelation) | ||
| } | ||
| if historyObject != "" && historyRelation != "" { | ||
| body.HistoryCheckQuery = contracts.JoinFgaQuery(historyObject, historyRelation) | ||
| } | ||
| } | ||
|
|
||
| // setExtractNameAndAliases extracts the name and aliases from the committee member data | ||
| // overrides the default name and aliases extraction logic | ||
| func (e *CommitteeMemberSensitiveEnricher) setExtractNameAndAliases(data map[string]any) []string { | ||
| var nameAndAliases []string | ||
| seen := make(map[string]bool) // Deduplicate names | ||
| // Compile regex pattern for name-like fields | ||
| aliasRegex := regexp.MustCompile(`(?i)^(email)$`) | ||
|
|
||
| for key, value := range data { | ||
| if aliasRegex.MatchString(key) { | ||
| if strValue, ok := value.(string); ok && strValue != "" { | ||
| trimmed := strings.TrimSpace(strValue) | ||
| if trimmed != "" && !seen[trimmed] { | ||
| nameAndAliases = append(nameAndAliases, trimmed) | ||
| seen[trimmed] = true | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return nameAndAliases | ||
| } | ||
|
|
||
| // extractSortName extracts the sort name from the committee member data | ||
| // overrides the default sort name extraction logic | ||
| func (e *CommitteeMemberSensitiveEnricher) extractSortName(data map[string]any) string { | ||
| if value, ok := data["email"]; ok { | ||
| if strValue, isString := value.(string); isString && strValue != "" { | ||
| return strings.TrimSpace(strValue) | ||
| } | ||
| } | ||
| return "" | ||
| } | ||
|
|
||
| // NewCommitteeEnricher creates a new committee enricher | ||
mauriciozanettisalomao marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| func NewCommitteeMemberSensitiveEnricher() Enricher { | ||
| cme := &CommitteeMemberSensitiveEnricher{} | ||
| cme.defaultEnricher = newDefaultEnricher( | ||
| constants.ObjectTypeCommitteeMemberSensitive, | ||
| WithAccessControl(cme.setAccessControl), | ||
| WithNameAndAliases(cme.setExtractNameAndAliases), | ||
| WithSortName(cme.extractSortName), | ||
| ) | ||
| return cme | ||
|
|
||
| } | ||
mauriciozanettisalomao marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.