Refactor DIFC label constructors to eliminate duplication#696
Merged
Conversation
Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Refactor duplicate code in DIFC module and configuration validation
Refactor DIFC label constructors to eliminate duplication
Feb 5, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors DIFC (Decentralized Information Flow Control) label constructors to eliminate code duplication by introducing a shared helper function. The refactoring extracts common label initialization logic that was duplicated across NewSecrecyLabelWithTags() and NewIntegrityLabelWithTags().
Changes:
- Introduced
newLabelWithTags()helper function to centralize label-with-tags creation logic - Simplified
NewSecrecyLabelWithTags()andNewIntegrityLabelWithTags()to use the shared helper - Reduced ~8 lines of duplicated code in the DIFC module
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Duplicate code analysis identified ~54 lines of duplication across 2 patterns in the DIFC and config validation modules.
Changes
DIFC Label Constructors
Extracted common label-with-tags creation pattern into
newLabelWithTags()helper:Eliminates ~8 lines of duplication in
internal/difc/labels.go.Docker Inspect Wrappers
Analysis confirmed
checkPortMapping(),checkStdinInteractive(), andcheckLogDirMounted()already share therunDockerInspect()helper. Each function has distinct domain logic and return types. No further abstraction warranted.Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
example.com/tmp/go-build4007704820/b274/launcher.test /tmp/go-build4007704820/b274/launcher.test -test.testlogfile=/tmp/go-build4007704820/b274/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true ache/go/1.25.6/x64/src/runtime/cgo .cfg 64/pkg/tool/linux_amd64/vet -p vendor/golang.or-unsafeptr=false -lang=go1.25 64/pkg/tool/linux_amd64/vet -I 8340911/b183/ -I rgo/bin/as -g" "-lresolv" --64 -o 8340911/b183/(dns block)invalid-host-that-does-not-exist-12345.com/tmp/go-build3364410036/b001/config.test /tmp/go-build3364410036/b001/config.test -test.testlogfile=/tmp/go-build3364410036/b001/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true go ps140/fips140.go-imultiarch 64/pkg/tool/linux86_64-linux-gnu(dns block)nonexistent.local/tmp/go-build4007704820/b274/launcher.test /tmp/go-build4007704820/b274/launcher.test -test.testlogfile=/tmp/go-build4007704820/b274/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true ache/go/1.25.6/x64/src/runtime/cgo .cfg 64/pkg/tool/linux_amd64/vet -p vendor/golang.or-unsafeptr=false -lang=go1.25 64/pkg/tool/linux_amd64/vet -I 8340911/b183/ -I rgo/bin/as -g" "-lresolv" --64 -o 8340911/b183/(dns block)slow.example.com/tmp/go-build4007704820/b274/launcher.test /tmp/go-build4007704820/b274/launcher.test -test.testlogfile=/tmp/go-build4007704820/b274/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true ache/go/1.25.6/x64/src/runtime/cgo .cfg 64/pkg/tool/linux_amd64/vet -p vendor/golang.or-unsafeptr=false -lang=go1.25 64/pkg/tool/linux_amd64/vet -I 8340911/b183/ -I rgo/bin/as -g" "-lresolv" --64 -o 8340911/b183/(dns block)this-host-does-not-exist-12345.com/tmp/go-build4007704820/b283/mcp.test /tmp/go-build4007704820/b283/mcp.test -test.testlogfile=/tmp/go-build4007704820/b283/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true 64/src/net red-by: lpcox <15877973+lpcox@users.noreply.github.com> ache/go/1.25.6/x64/pkg/tool/linux_amd64/vet -p crypto/internal/-unsafeptr=false -lang=go1.25 01.o(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.