Commit 610e8c2
authored
refactor: consolidate guard policy env var names into constants, replace os.Getenv with envutil (#5546)
## ✨ Enhancement
The five guard-policy env var names were duplicated as string literals
across `flags_difc.go` and `guard_policy_parse.go`, and
`guard_policy_parse.go` mixed raw `os.Getenv` calls with
`envutil.GetEnvBool` — inconsistent with the rest of the codebase.
**What does this improve?**
- Single source of truth for env var names — adding or renaming a
variable is a one-line change
- Consistent `envutil.GetEnvString/Bool` usage throughout guard policy
code
**Implementation approach:**
- **New `internal/config/guard_policy_env.go`** — five exported
constants:
```go
const (
EnvGuardPolicyJSON = "MCP_GATEWAY_GUARD_POLICY_JSON"
EnvAllowOnlyScopePublic = "MCP_GATEWAY_ALLOWONLY_SCOPE_PUBLIC"
EnvAllowOnlyScopeOwner = "MCP_GATEWAY_ALLOWONLY_SCOPE_OWNER"
EnvAllowOnlyScopeRepo = "MCP_GATEWAY_ALLOWONLY_SCOPE_REPO"
EnvAllowOnlyMinIntegrity = "MCP_GATEWAY_ALLOWONLY_MIN_INTEGRITY"
)
```
- **`guard_policy_parse.go`** — replaced `os.Getenv(...)` with
`envutil.GetEnvString(Env..., "")`, replaced string literals with
constants, removed the `os` import
- **`flags_difc.go`** — replaced string literals with `config.EnvXxx`
constants3 files changed
Lines changed: 25 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
36 | 37 | | |
37 | 38 | | |
38 | 39 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
224 | 224 | | |
225 | 225 | | |
226 | 226 | | |
227 | | - | |
| 227 | + | |
228 | 228 | | |
229 | 229 | | |
230 | 230 | | |
231 | 231 | | |
232 | 232 | | |
233 | 233 | | |
234 | 234 | | |
235 | | - | |
236 | | - | |
237 | | - | |
238 | | - | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
239 | 239 | | |
240 | 240 | | |
241 | 241 | | |
242 | | - | |
243 | | - | |
244 | | - | |
245 | | - | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
246 | 246 | | |
247 | 247 | | |
248 | 248 | | |
| |||
0 commit comments