Commit 1a75624
authored
refactor(guard): extract validateIntegrityField to eliminate triplicated switch blocks (#4944)
The integrity-level validation switch
(`none|unapproved|approved|merged`) was inlined identically three times
in `buildStrictLabelAgentPayload`, meaning any new integrity level
required three synchronized edits.
## Changes
- **`internal/guard/wasm_validate.go`** *(new)*: single
`validateIntegrityField(fieldName string, raw interface{}) error` helper
— handles both the `string` type assertion and the validity switch in
one place
- **`internal/guard/wasm_payload.go`**: replaces the three duplicate
blocks for `integrity`, `disapproval-integrity`, and
`endorser-min-integrity` with calls to the helper
```go
// before — repeated verbatim three times
disInt, ok := disIntRaw.(string)
if !ok {
return nil, fmt.Errorf("invalid disapproval-integrity value: ...")
}
switch strings.ToLower(strings.TrimSpace(disInt)) {
case "none", "unapproved", "approved", "merged":
default:
return nil, fmt.Errorf("invalid disapproval-integrity value: ...")
}
// after
if err := validateIntegrityField("disapproval-integrity", disIntRaw); err != nil {
return nil, err
}
```
> [!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-build3106413706/b513/launcher.test
/tmp/go-build3106413706/b513/launcher.test
-test.testlogfile=/tmp/go-build3106413706/b513/testlog.txt
-test.paniconexit0 -test.timeout=10m0s -o .cfg 3753103/b314/ x_amd64/vet
-p github.com/githu--version -lang=go1.25 x_amd64/vet .cfg��
3753103/b364/_pkg_.a
ache/go/1.25.9/x64/src/net/http/internal/httpcommon/httpcommon.ggoogle.golang.org/protobuf/types-qE
x_amd64/vet --gdwarf-5 --64 -o 42W3fCn/gP4cHa5aRI3EQQAZUMxk` (dns block)
> - `invalid-host-that-does-not-exist-12345.com`
> - Triggering command: `/tmp/go-build3106413706/b495/config.test
/tmp/go-build3106413706/b495/config.test
-test.testlogfile=/tmp/go-build3106413706/b495/testlog.txt
-test.paniconexit0 -test.timeout=10m0s
/tmp/go-build3106413706/b393/vet.cfg 1.80.0/resolver/dns/dns_resolver.go
64/src/crypto/x509/cert_pool.go x_amd64/vet --gdwarf-5 --64 -o
x_amd64/vet -o g_.a -trimpath x_amd64/vet -p gzip -lang=go1.25
x_amd64/vet` (dns block)
> - `nonexistent.local`
> - Triggering command: `/tmp/go-build3106413706/b513/launcher.test
/tmp/go-build3106413706/b513/launcher.test
-test.testlogfile=/tmp/go-build3106413706/b513/testlog.txt
-test.paniconexit0 -test.timeout=10m0s -o .cfg 3753103/b314/ x_amd64/vet
-p github.com/githu--version -lang=go1.25 x_amd64/vet .cfg��
3753103/b364/_pkg_.a
ache/go/1.25.9/x64/src/net/http/internal/httpcommon/httpcommon.ggoogle.golang.org/protobuf/types-qE
x_amd64/vet --gdwarf-5 --64 -o 42W3fCn/gP4cHa5aRI3EQQAZUMxk` (dns block)
> - `slow.example.com`
> - Triggering command: `/tmp/go-build3106413706/b513/launcher.test
/tmp/go-build3106413706/b513/launcher.test
-test.testlogfile=/tmp/go-build3106413706/b513/testlog.txt
-test.paniconexit0 -test.timeout=10m0s -o .cfg 3753103/b314/ x_amd64/vet
-p github.com/githu--version -lang=go1.25 x_amd64/vet .cfg��
3753103/b364/_pkg_.a
ache/go/1.25.9/x64/src/net/http/internal/httpcommon/httpcommon.ggoogle.golang.org/protobuf/types-qE
x_amd64/vet --gdwarf-5 --64 -o 42W3fCn/gP4cHa5aRI3EQQAZUMxk` (dns block)
> - `this-host-does-not-exist-12345.com`
> - Triggering command: `/tmp/go-build3106413706/b522/mcp.test
/tmp/go-build3106413706/b522/mcp.test
-test.testlogfile=/tmp/go-build3106413706/b522/testlog.txt
-test.paniconexit0 -test.timeout=10m0s -I .cfg -I x_amd64/vet --gdwarf-5
--64 -o x_amd64/vet .cfg�� 3753103/b400/_pkg_.a -dynimport x_amd64/vet
-dynout g/grpc/internal//usr/bin/runc p/bin/git x_amd64/vet` (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>3 files changed
Lines changed: 47 additions & 26 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
92 | 92 | | |
93 | 93 | | |
94 | 94 | | |
| 95 | + | |
95 | 96 | | |
96 | 97 | | |
| 98 | + | |
97 | 99 | | |
98 | 100 | | |
99 | 101 | | |
| |||
114 | 116 | | |
115 | 117 | | |
116 | 118 | | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
| 119 | + | |
| 120 | + | |
126 | 121 | | |
127 | 122 | | |
128 | 123 | | |
| |||
199 | 194 | | |
200 | 195 | | |
201 | 196 | | |
202 | | - | |
203 | | - | |
204 | | - | |
205 | | - | |
206 | | - | |
207 | | - | |
208 | | - | |
209 | | - | |
| 197 | + | |
| 198 | + | |
210 | 199 | | |
211 | 200 | | |
212 | 201 | | |
213 | 202 | | |
214 | 203 | | |
215 | | - | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
220 | | - | |
221 | | - | |
222 | | - | |
| 204 | + | |
| 205 | + | |
223 | 206 | | |
224 | 207 | | |
225 | 208 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
358 | 358 | | |
359 | 359 | | |
360 | 360 | | |
361 | | - | |
| 361 | + | |
362 | 362 | | |
363 | 363 | | |
364 | 364 | | |
| |||
| 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 | + | |
| 37 | + | |
| 38 | + | |
0 commit comments