US1094711:- Add httpMethods field to L7Api PortalMeta for per-API HTTP method restriction - #100
US1094711:- Add httpMethods field to L7Api PortalMeta for per-API HTTP method restriction#100ksaladi wants to merge 2 commits into
Conversation
| PublishedTs int `json:"publishedTs"` | ||
| CreateTs int `json:"createTs"` | ||
| ModifyTs int `json:"modifyTs"` | ||
| SsgServiceType string `json:"ssgServiceType"` | ||
| SsgServiceType string `json:"ssgServiceType"` | ||
| HttpMethods []string `json:"httpMethods,omitempty"` |
There was a problem hiding this comment.
[Nit] ❌ gofmt reports this block as misformatted: running gofmt -l internal/templategen/templategen.go on this branch flags this file. The struct-tag column padding on PublishedTs/CreateTs/ModifyTs/SsgServiceType doesn't match what gofmt would produce after adding the HttpMethods field.
✅ Run gofmt -w internal/templategen/templategen.go (or make lint-fix) before merge so CI's fmt check doesn't drift.
| } | ||
| }) | ||
|
|
||
| t.Run("HttpMethods Test", func(t *testing.T) { |
There was a problem hiding this comment.
[Suggestion]
❌ Issue: This test only exercises the new restricted-methods branch. The modified conditional in the qtpl template (if len(portalApi.HttpMethods) > 0 { ... } elseif isSoapApi == "true" { 2 verbs } else { 7 verbs }) also touches the pre-existing default and SOAP branches, but there's no test asserting those still produce the original verb counts now that HttpMethods is unset/empty for them (the existing "Template Test" above only checks the output is non-empty).
✅ Suggestion: Add an assertion (e.g. strings.Count(got, "<l7:Verb>") == 7 for the default portalApi case, and a SOAP-API case with isSoapApi == "true" expecting 2) so a future change to this shared conditional can't silently regress the backward-compatible default path this PR's description calls out as important.
What
Adds an
httpMethodsfield toPortalMetaon theL7ApiCRD so Portal API authors canrestrict which HTTP verbs a published API accepts (e.g.
GETonly), instead of the Gatewayunconditionally allowing all 7 verbs.
Changes
api/v1alpha1/l7api_types.go: newHttpMethodenum type (8 consts) +HttpMethods []HttpMethodon
PortalMeta.internal/templategen/templategen.go: mirroredHttpMethods []stringonPortalAPI(requiredfor the
PortalMeta→PortalAPIJSON round-trip indeployL7ApiToGateway).internal/templategen/portal-api-restman-template.qtpl(+ regenerated.qtpl.go):<l7:Verbs>now emits from
HttpMethodswhen set, falling back to the existing hardcoded 7-verb list whenunset — fully backward compatible.
config/crd/bases/,bundle/manifests/,charts/layer7-operator/crds/).templategen_test.go.Enforcement itself is native to the Gateway via Graphman's
WebApiServiceInput.MethodsAllowed—no new assertion logic.
Testing
go build,go vet,go test ./internal/templategen/...— all pass.L7ApiCR withhttpMethods: ["GET"], confirmedvia the Gateway's Graphman API that
methodsAllowedmatched, and confirmedPOST/DELETEare rejected with
"HTTP method ... not allowed"whileGETpasses through to policy.