Skip to content

US1094711:- Add httpMethods field to L7Api PortalMeta for per-API HTTP method restriction - #100

Open
ksaladi wants to merge 2 commits into
develop/portalfrom
ks_http
Open

US1094711:- Add httpMethods field to L7Api PortalMeta for per-API HTTP method restriction#100
ksaladi wants to merge 2 commits into
develop/portalfrom
ks_http

Conversation

@ksaladi

@ksaladi ksaladi commented Jul 16, 2026

Copy link
Copy Markdown

What

Adds an httpMethods field to PortalMeta on the L7Api CRD so Portal API authors can
restrict which HTTP verbs a published API accepts (e.g. GET only), instead of the Gateway
unconditionally allowing all 7 verbs.

Changes

  • api/v1alpha1/l7api_types.go: new HttpMethod enum type (8 consts) + HttpMethods []HttpMethod
    on PortalMeta.
  • internal/templategen/templategen.go: mirrored HttpMethods []string on PortalAPI (required
    for the PortalMetaPortalAPI JSON round-trip in deployL7ApiToGateway).
  • internal/templategen/portal-api-restman-template.qtpl (+ regenerated .qtpl.go): <l7:Verbs>
    now emits from HttpMethods when set, falling back to the existing hardcoded 7-verb list when
    unset — fully backward compatible.
  • CRD schema regenerated in all 3 locations (config/crd/bases/, bundle/manifests/,
    charts/layer7-operator/crds/).
  • Added a test case covering the restricted-methods path in 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.
  • Verified live on a kind cluster: patched an L7Api CR with httpMethods: ["GET"], confirmed
    via the Gateway's Graphman API that methodsAllowed matched, and confirmed POST/DELETE
    are rejected with "HTTP method ... not allowed" while GET passes through to policy.

@ksaladi ksaladi changed the title US1094711:- Change to have httpMethods in L7Api US1094711:- Add httpMethods field to L7Api PortalMeta for per-API HTTP method restriction Jul 16, 2026
@ksaladi
ksaladi requested a review from jb683638 July 16, 2026 19:25
Comment thread internal/templategen/templategen.go Outdated
Comment on lines +22 to +26
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"`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed — ran gofmt -w.

Comment thread api/v1alpha1/l7api_types.go
Comment thread api/v1alpha1/l7api_types.go
@ksaladi
ksaladi requested a review from jb683638 July 21, 2026 08:57
@ksaladi
ksaladi changed the base branch from main to develop/portal August 16, 2026 15:22

@jb683638 jb683638 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

}
})

t.Run("HttpMethods Test", func(t *testing.T) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants