Commit 1c41e8a
authored
Refactor duplicated DIFC pipeline decisions and logger level wrappers (#4301)
This PR addresses the duplicate-code report by extracting repeated DIFC
enforcement decisions shared between unified MCP tool calls and proxy
REST handling, and by collapsing repeated logger wrapper patterns. The
goal is to reduce drift risk in policy behavior and simplify maintenance
of level-based logging APIs.
- **DIFC pipeline decision logic centralized**
- Added `internal/difc/pipeline_decisions.go` with shared predicates
for:
- coarse-deny bypass on reads
- `LabelResponse` eligibility by operation/mode
- strict-mode blocking on filtered collections
- propagate-mode label accumulation rules
- Replaced inline condition blocks in:
- `internal/server/unified.go`
- `internal/proxy/handler.go`
- **Logger 4-wrapper pattern consolidated**
- Added generic wrapper constructors in `internal/logger/common.go`:
- `makeLevelLogger(...)`
- `makeServerLevelLogger(...)`
- Replaced repetitive per-level one-liner wrappers with generated
wrappers while preserving public API names/signatures in:
- `internal/logger/file_logger.go`
- `internal/logger/markdown_logger.go`
- `internal/logger/server_file_logger.go`
- **Focused DIFC helper coverage**
- Added `internal/difc/pipeline_decisions_test.go` to lock behavior of
shared predicates across operation/mode combinations.
```go
// internal/difc/pipeline_decisions.go
func ShouldCallLabelResponse(operation OperationType, enforcementMode EnforcementMode) bool {
isPureWrite := operation == OperationWrite
return !isPureWrite && (operation != OperationReadWrite || enforcementMode != EnforcementStrict)
}
```
> [!WARNING]
>
> <details>
> <summary>Firewall rules blocked me from connecting to one or more
addresses (expand for details)</summary>
>
> #### I tried to connect to the following addresses, but was blocked by
firewall rules:
>
> - `example.com`
> - Triggering command: `/tmp/go-build3351015982/b509/launcher.test
/tmp/go-build3351015982/b509/launcher.test
-test.testlogfile=/tmp/go-build3351015982/b509/testlog.txt
-test.paniconexit0 -test.timeout=10m0s -test.v=true g_.a -I x_amd64/vet
--gdwarf-5 pickfirst/intern-atomic -o x_amd64/vet -E 3Uglm7fcz
9224174/b287/ x_amd64/vet -I . -imultiarch x_amd64/vet` (dns block)
> - Triggering command: `/tmp/go-build1206797649/b513/launcher.test
/tmp/go-build1206797649/b513/launcher.test
-test.testlogfile=/tmp/go-build1206797649/b513/testlog.txt
-test.paniconexit0 -test.timeout=10m0s` (dns block)
> - `invalid-host-that-does-not-exist-12345.com`
> - Triggering command: `/tmp/go-build3351015982/b491/config.test
/tmp/go-build3351015982/b491/config.test
-test.testlogfile=/tmp/go-build3351015982/b491/testlog.txt
-test.paniconexit0 -test.timeout=10m0s -test.v=true g_.a -I x_amd64/vet
--gdwarf-5 ternal/engine/wa-atomic -o x_amd64/vet -I piOAqIlI1 -I
x_amd64/vet --gdwarf-5 re/xxhash/v2 -o x_amd64/vet` (dns block)
> - Triggering command: `/tmp/go-build1206797649/b495/config.test
/tmp/go-build1206797649/b495/config.test
-test.testlogfile=/tmp/go-build1206797649/b495/testlog.txt
-test.paniconexit0 -test.timeout=10m0s go1.25.9 -c=4 -nolocalimports
-importcfg /tmp/go-build2876961135/b477/importcfg -pack
/home/REDACTED/work/gh-aw-mcpg/gh-aw-mcpg/internal/auth/header.go
/home/REDACTED/work/gh-aw-mcpg/gh-aw-mcpg/internal/auth/header_test.go`
(dns block)
> - `nonexistent.local`
> - Triggering command: `/tmp/go-build3351015982/b509/launcher.test
/tmp/go-build3351015982/b509/launcher.test
-test.testlogfile=/tmp/go-build3351015982/b509/testlog.txt
-test.paniconexit0 -test.timeout=10m0s -test.v=true g_.a -I x_amd64/vet
--gdwarf-5 pickfirst/intern-atomic -o x_amd64/vet -E 3Uglm7fcz
9224174/b287/ x_amd64/vet -I . -imultiarch x_amd64/vet` (dns block)
> - Triggering command: `/tmp/go-build1206797649/b513/launcher.test
/tmp/go-build1206797649/b513/launcher.test
-test.testlogfile=/tmp/go-build1206797649/b513/testlog.txt
-test.paniconexit0 -test.timeout=10m0s` (dns block)
> - `slow.example.com`
> - Triggering command: `/tmp/go-build3351015982/b509/launcher.test
/tmp/go-build3351015982/b509/launcher.test
-test.testlogfile=/tmp/go-build3351015982/b509/testlog.txt
-test.paniconexit0 -test.timeout=10m0s -test.v=true g_.a -I x_amd64/vet
--gdwarf-5 pickfirst/intern-atomic -o x_amd64/vet -E 3Uglm7fcz
9224174/b287/ x_amd64/vet -I . -imultiarch x_amd64/vet` (dns block)
> - Triggering command: `/tmp/go-build1206797649/b513/launcher.test
/tmp/go-build1206797649/b513/launcher.test
-test.testlogfile=/tmp/go-build1206797649/b513/testlog.txt
-test.paniconexit0 -test.timeout=10m0s` (dns block)
> - `this-host-does-not-exist-12345.com`
> - Triggering command: `/tmp/go-build3351015982/b518/mcp.test
/tmp/go-build3351015982/b518/mcp.test
-test.testlogfile=/tmp/go-build3351015982/b518/testlog.txt
-test.paniconexit0 -test.timeout=10m0s -test.v=true .cfg
elemetry.io/otel-ifaceassert x_amd64/vet . --gdwarf2 --64 x_amd64/vet
-qui�� .cfg om/grpc-ecosystem/grpc-gateway/v2@v2.28.0/runtime/convert.go
x_amd64/vet /tmp/go-build370bash g/grpc/internal//usr/bin/runc
x86_64-linux-gnu--version x_amd64/vet` (dns block)
> - Triggering command: `/tmp/go-build1206797649/b522/mcp.test
/tmp/go-build1206797649/b522/mcp.test
-test.testlogfile=/tmp/go-build1206797649/b522/testlog.txt
-test.paniconexit0 -test.timeout=10m0s -uns�� tion_pool.go _monitor.go
x_amd64/compile` (dns block)
>
> If you need me to access, download, or install something from one of
these locations, you can either:
>
> - Configure [Actions setup
steps](https://gh.io/copilot/actions-setup-steps) to set up my
environment, which run before the firewall is enabled
> - Add the appropriate URLs or hosts to the custom allowlist in this
repository's [Copilot coding agent
settings](https://github.com/github/gh-aw-mcpg/settings/copilot/coding_agent)
(admins only)
>
> </details>8 files changed
Lines changed: 150 additions & 42 deletions
File tree
- internal
- difc
- logger
- proxy
- server
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
183 | 183 | | |
184 | 184 | | |
185 | 185 | | |
186 | | - | |
187 | | - | |
188 | | - | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
189 | 189 | | |
190 | 190 | | |
191 | | - | |
| 191 | + | |
192 | 192 | | |
193 | 193 | | |
194 | | - | |
| 194 | + | |
195 | 195 | | |
196 | 196 | | |
197 | 197 | | |
198 | 198 | | |
199 | 199 | | |
200 | | - | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
201 | 208 | | |
202 | | - | |
203 | | - | |
| 209 | + | |
| 210 | + | |
204 | 211 | | |
205 | 212 | | |
206 | 213 | | |
207 | 214 | | |
208 | 215 | | |
209 | 216 | | |
210 | 217 | | |
211 | | - | |
| 218 | + | |
| 219 | + | |
212 | 220 | | |
213 | 221 | | |
214 | 222 | | |
215 | 223 | | |
216 | 224 | | |
217 | 225 | | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
218 | 244 | | |
219 | 245 | | |
220 | 246 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
113 | 113 | | |
114 | 114 | | |
115 | 115 | | |
116 | | - | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
117 | 124 | | |
118 | | - | |
| 125 | + | |
119 | 126 | | |
120 | 127 | | |
121 | | - | |
| 128 | + | |
122 | 129 | | |
123 | | - | |
| 130 | + | |
124 | 131 | | |
125 | 132 | | |
126 | | - | |
| 133 | + | |
127 | 134 | | |
128 | | - | |
| 135 | + | |
129 | 136 | | |
130 | 137 | | |
131 | | - | |
| 138 | + | |
132 | 139 | | |
133 | | - | |
| 140 | + | |
134 | 141 | | |
135 | 142 | | |
136 | 143 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
180 | 180 | | |
181 | 181 | | |
182 | 182 | | |
183 | | - | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
184 | 191 | | |
185 | | - | |
| 192 | + | |
186 | 193 | | |
187 | 194 | | |
188 | | - | |
| 195 | + | |
189 | 196 | | |
190 | | - | |
| 197 | + | |
191 | 198 | | |
192 | 199 | | |
193 | | - | |
| 200 | + | |
194 | 201 | | |
195 | | - | |
| 202 | + | |
196 | 203 | | |
197 | 204 | | |
198 | | - | |
| 205 | + | |
199 | 206 | | |
200 | | - | |
| 207 | + | |
201 | 208 | | |
202 | 209 | | |
203 | 210 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
155 | 155 | | |
156 | 156 | | |
157 | 157 | | |
158 | | - | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
159 | 166 | | |
160 | | - | |
| 167 | + | |
161 | 168 | | |
162 | 169 | | |
163 | | - | |
| 170 | + | |
164 | 171 | | |
165 | | - | |
| 172 | + | |
166 | 173 | | |
167 | 174 | | |
168 | | - | |
| 175 | + | |
169 | 176 | | |
170 | | - | |
| 177 | + | |
171 | 178 | | |
172 | 179 | | |
173 | | - | |
| 180 | + | |
174 | 181 | | |
175 | | - | |
| 182 | + | |
176 | 183 | | |
177 | 184 | | |
178 | 185 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
178 | 178 | | |
179 | 179 | | |
180 | 180 | | |
181 | | - | |
| 181 | + | |
182 | 182 | | |
183 | 183 | | |
184 | 184 | | |
| |||
266 | 266 | | |
267 | 267 | | |
268 | 268 | | |
269 | | - | |
| 269 | + | |
270 | 270 | | |
271 | 271 | | |
272 | 272 | | |
| |||
318 | 318 | | |
319 | 319 | | |
320 | 320 | | |
321 | | - | |
| 321 | + | |
322 | 322 | | |
323 | 323 | | |
324 | 324 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
531 | 531 | | |
532 | 532 | | |
533 | 533 | | |
534 | | - | |
| 534 | + | |
535 | 535 | | |
536 | 536 | | |
537 | 537 | | |
| |||
603 | 603 | | |
604 | 604 | | |
605 | 605 | | |
606 | | - | |
607 | | - | |
| 606 | + | |
608 | 607 | | |
609 | 608 | | |
610 | 609 | | |
| |||
631 | 630 | | |
632 | 631 | | |
633 | 632 | | |
634 | | - | |
| 633 | + | |
635 | 634 | | |
636 | 635 | | |
637 | 636 | | |
| |||
664 | 663 | | |
665 | 664 | | |
666 | 665 | | |
667 | | - | |
| 666 | + | |
668 | 667 | | |
669 | 668 | | |
670 | 669 | | |
| |||
675 | 674 | | |
676 | 675 | | |
677 | 676 | | |
678 | | - | |
| 677 | + | |
679 | 678 | | |
680 | 679 | | |
681 | 680 | | |
| |||
0 commit comments