Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add error message when JwtConfiguration is not a map #3567

Merged
merged 3 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions samtranslator/model/apigatewayv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ def __init__( # type: ignore[no-untyped-def] # noqa: PLR0913
self.api_logical_id = api_logical_id
self.name = name
self.authorization_scopes = authorization_scopes
self.jwt_configuration: Optional[JwtConfiguration] = self._get_jwt_configuration(jwt_configuration)
self.jwt_configuration: Optional[JwtConfiguration] = self._get_jwt_configuration(
jwt_configuration, api_logical_id
)
self.id_source = id_source
self.function_arn = function_arn
self.function_invoke_role = function_invoke_role
Expand Down Expand Up @@ -344,7 +346,9 @@ def _get_identity_source(self, auth_identity: Dict[str, Any]) -> List[str]:
return identity_source

@staticmethod
def _get_jwt_configuration(props: Optional[Dict[str, Union[str, List[str]]]]) -> Optional[JwtConfiguration]:
def _get_jwt_configuration(
props: Optional[Dict[str, Union[str, List[str]]]], api_logical_id: str
) -> Optional[JwtConfiguration]:
"""Make sure that JWT configuration dict keys are lower case.

ApiGatewayV2Authorizer doesn't create `AWS::ApiGatewayV2::Authorizer` but generates
Expand All @@ -359,13 +363,14 @@ def _get_jwt_configuration(props: Optional[Dict[str, Union[str, List[str]]]]) ->

Parameters
----------
props
jwt configuration dict with the keys either lower case or capitalized
props: jwt configuration dict with the keys either lower case or capitalized
api_logical_id: logical id of the Serverless Api resource with the jwt configuration

Returns
-------
jwt configuration dict with low case keys
"""
if not props:
return None
sam_expect(props, api_logical_id, "JwtConfiguration").to_be_a_map()
return {k.lower(): v for k, v in props.items()}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
Resources:
MyApi:
Type: AWS::Serverless::HttpApi
Properties:
Tags:
Tag1: value1
Tag2: value2
Auth:
Authorizers:
MyLambdaAuth:
FunctionArn:
Fn::GetAtt:
- MyAuthFn
- Arn
FunctionInvokeRole:
Fn::GetAtt:
- MyAuthFnRole
- Arn
Identity:
Context:
- contextVar
Headers:
- Authorization
QueryStrings:
- petId
StageVariables:
- stageVar
ReauthorizeEvery: 23
EnableSimpleResponses: true
AuthorizerPayloadFormatVersion: 2.0
MyOAuth2Auth:
AuthorizationScopes:
- scope4
JwtConfiguration:
- issuer: https://openid-connect.onelogin.com/oidc
IdentitySource: $request.querystring.param
DefaultAuthorizer: MyOAuth2Auth
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"_autoGeneratedBreakdownErrorMessage": [
"Invalid Serverless Application Specification document. ",
"Number of errors found: 1. ",
"Resource with id [MyApi] is invalid. ",
"Property 'JwtConfiguration' should be a map."
],
"errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MyApi] is invalid. Property 'JwtConfiguration' should be a map."
}