refactor: use NewLabeledResource constructor instead of inline struct literals#8344
Merged
Conversation
… literals
Replace all inline `&difc.LabeledResource{}` constructions with calls to
`difc.NewLabeledResource()` to use the canonical constructor consistently:
- internal/guard/noop.go: Replace inline struct with NewLabeledResource
- internal/guard/wasm_parse.go (2 sites): Replace empty struct literals
- internal/guard/write_sink.go: Replace inline struct, override Secrecy after
Fixes #8319
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors DIFC guard code to consistently initialize difc.LabeledResource via the canonical difc.NewLabeledResource() constructor instead of inline struct literals, reducing duplicated initialization logic and centralizing defaults.
Changes:
- Refactor
NoopGuardto construct its labeled resource viadifc.NewLabeledResource(...). - Refactor WASM guard response parsing to start from a constructor-created
LabeledResourcebefore populating fields from decoded JSON. - Refactor
WriteSinkGuardto usedifc.NewLabeledResource(...)and then overrideSecrecywith configured accept tags.
Show a summary per file
| File | Description |
|---|---|
| internal/guard/noop.go | Switches noop resource construction to difc.NewLabeledResource(...). |
| internal/guard/wasm_parse.go | Uses difc.NewLabeledResource("") as the base object before filling labels from WASM response maps. |
| internal/guard/write_sink.go | Uses difc.NewLabeledResource(...) then overrides Secrecy with NewSecrecyLabelWithTags(...). |
Review details
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 3/3 changed files
- Comments generated: 3
- Review effort level: Low
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Replace all inline
&difc.LabeledResource{}constructions with calls to the canonicaldifc.NewLabeledResource()constructor, reducing code duplication and ensuring consistent initialization.Changes
internal/guard/noop.godifc.NewLabeledResource("noop resource (no restrictions)")internal/guard/wasm_parse.go(line 403)&difc.LabeledResource{}withdifc.NewLabeledResource("")beforefillLabeledResourceFromMapinternal/guard/wasm_parse.go(line 442)internal/guard/write_sink.godifc.NewLabeledResource(...)then overrideSecrecywith custom tagsRationale
difc.NewLabeledResource()already initializesDescription,Secrecy,Integrity, andStructurewith proper defaults. Bypassing it with inline struct literals duplicates that logic and risks inconsistency if the constructor defaults change.For
write_sink.go, the constructor is used for default initialization, thenSecrecyis overridden withNewSecrecyLabelWithTagssince that case requires custom accept tags.For
wasm_parse.go, the constructor defaults are immediately overwritten byfillLabeledResourceFromMap, but using the constructor ensures all fields start with valid defaults rather than zero values.Fixes #8319