Skip to content

refactor: improve HttpApi authorizer validation#3899

Open
vicheey wants to merge 2 commits intodevelopfrom
fix/3817-identitysource-request-authorizer
Open

refactor: improve HttpApi authorizer validation#3899
vicheey wants to merge 2 commits intodevelopfrom
fix/3817-identitysource-request-authorizer

Conversation

@vicheey
Copy link
Copy Markdown
Contributor

@vicheey vicheey commented Mar 28, 2026

Issue #, if available

Close #3817

Description of changes

Refactor HttpApi authorizer property validation in apigatewayv2.py from repetitive if/raise blocks to a data-driven approach using two declarative dicts (ALLOWED_PROPERTIES and PROPERTY_DISPLAY). This replaces
~40 lines of repetitive validation with a 4-line loop, making it easier to maintain and extend when new authorizer types or properties are added.

No behavior change — same properties are blocked for the same authorizer types. The only user-facing difference is improved error messages:

Description of how you validated changes

  • All 17 existing unit tests in tests/model/test_api_v2.py pass (error message strings updated to match)
  • make pr passes: black, ruff, mypy --strict, cfn-lint, schema generation all clean
  • Manually deployed a REQUEST authorizer using the Identity property workaround and verified the authorizer was created with correct identitySource: ["$request.header.Authorization"] via aws apigatewayv2
    get-authorizers

Checklist

Examples?

Please reach out in the comments if you want to add an example. Examples will be
added to sam init through aws/aws-sam-cli-app-templates (https://github.com/aws/aws-sam-cli-app-templates).

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@vicheey vicheey requested a review from a team as a code owner March 28, 2026 00:50
@licjun
Copy link
Copy Markdown
Contributor

licjun commented Mar 28, 2026

For this #3817 (comment), it seems customer is using the schema defined for cloudformation apigatewayv2, not SAM's schema for http api, since sam http api doesn't support AuthorizerResultTtlInSeconds, rather this cache config is embedded into Identity's ReauthorizeEvery

@licjun
Copy link
Copy Markdown
Contributor

licjun commented Mar 28, 2026

There is still some tests failed. Otherwise LGTM.

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.

Bug: "IdentitySource must be defined only for OAuth2 Authorizer."

2 participants