-
Notifications
You must be signed in to change notification settings - Fork 20
Refactor duplicated DIFC pipeline decisions and logger level wrappers #4301
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
Merged
+150
−42
Merged
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| package difc | ||
|
|
||
| // ShouldBypassCoarseDeny returns true when a coarse-grained deny should still | ||
| // proceed to backend execution so Phase 5 can enforce per-item policy. | ||
| func ShouldBypassCoarseDeny(operation OperationType) bool { | ||
| return operation == OperationRead | ||
| } | ||
|
|
||
| // ShouldCallLabelResponse returns true when guards should label response data | ||
| // for possible fine-grained filtering. | ||
| func ShouldCallLabelResponse(operation OperationType, enforcementMode EnforcementMode) bool { | ||
| isPureWrite := operation == OperationWrite | ||
| return !isPureWrite && (operation != OperationReadWrite || enforcementMode != EnforcementStrict) | ||
| } | ||
|
|
||
| // ShouldBlockFilteredResponse returns true when filtered items should block the | ||
| // whole response instead of returning a partially filtered result. | ||
| func ShouldBlockFilteredResponse(enforcementMode EnforcementMode, filteredCount int) bool { | ||
| return enforcementMode == EnforcementStrict && filteredCount > 0 | ||
| } | ||
|
|
||
| // ShouldAccumulateReadLabels returns true when read labels should be | ||
| // accumulated back into the agent label set. | ||
| func ShouldAccumulateReadLabels(operation OperationType, enforcementMode EnforcementMode) bool { | ||
| return operation != OperationWrite && enforcementMode == EnforcementPropagate | ||
| } |
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,36 @@ | ||
| package difc | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func TestShouldBypassCoarseDeny(t *testing.T) { | ||
| assert.True(t, ShouldBypassCoarseDeny(OperationRead)) | ||
| assert.False(t, ShouldBypassCoarseDeny(OperationWrite)) | ||
| assert.False(t, ShouldBypassCoarseDeny(OperationReadWrite)) | ||
| } | ||
|
|
||
| func TestShouldCallLabelResponse(t *testing.T) { | ||
| assert.False(t, ShouldCallLabelResponse(OperationWrite, EnforcementStrict)) | ||
| assert.False(t, ShouldCallLabelResponse(OperationReadWrite, EnforcementStrict)) | ||
| assert.True(t, ShouldCallLabelResponse(OperationRead, EnforcementStrict)) | ||
| assert.True(t, ShouldCallLabelResponse(OperationReadWrite, EnforcementFilter)) | ||
| assert.True(t, ShouldCallLabelResponse(OperationReadWrite, EnforcementPropagate)) | ||
| } | ||
|
|
||
| func TestShouldBlockFilteredResponse(t *testing.T) { | ||
| assert.True(t, ShouldBlockFilteredResponse(EnforcementStrict, 1)) | ||
| assert.False(t, ShouldBlockFilteredResponse(EnforcementStrict, 0)) | ||
| assert.False(t, ShouldBlockFilteredResponse(EnforcementFilter, 3)) | ||
| assert.False(t, ShouldBlockFilteredResponse(EnforcementPropagate, 2)) | ||
| } | ||
|
|
||
| func TestShouldAccumulateReadLabels(t *testing.T) { | ||
| assert.True(t, ShouldAccumulateReadLabels(OperationRead, EnforcementPropagate)) | ||
| assert.True(t, ShouldAccumulateReadLabels(OperationReadWrite, EnforcementPropagate)) | ||
| assert.False(t, ShouldAccumulateReadLabels(OperationWrite, EnforcementPropagate)) | ||
| assert.False(t, ShouldAccumulateReadLabels(OperationRead, EnforcementStrict)) | ||
| assert.False(t, ShouldAccumulateReadLabels(OperationRead, EnforcementFilter)) | ||
| } |
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
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The large block comment immediately above this helper says the per-level one-liner wrappers are “intentionally kept” and instructs adding new wrappers in each file when adding a LogLevel. With this refactor, that guidance is now outdated/misleading. Please update or remove that section to reflect the new pattern (and, if you keep exported wrappers as
funcs, document thatmakeLevelLoggeris meant for internal delegation rather than replacing exported functions with mutable vars).