Skip to content
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
4 changes: 2 additions & 2 deletions samtranslator/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ def get_runtime_attr(self, attr_name):
if attr_name in self.runtime_attrs:
return self.runtime_attrs[attr_name](self)
else:
raise NotImplementedError(attr_name + " attribute is not implemented for resource " + self.resource_type)
raise NotImplementedError(f"{attr_name} attribute is not implemented for resource {self.resource_type}")

def get_passthrough_resource_attributes(self):
"""
Expand Down Expand Up @@ -447,7 +447,7 @@ def _check_tag(self, reserved_tag_name, tags):
if reserved_tag_name in tags:
raise InvalidResourceException(
self.logical_id,
reserved_tag_name + " is a reserved Tag key name and "
f"{reserved_tag_name} is a reserved Tag key name and "
"cannot be set on your resource. "
"Please change the tag key in the "
"input.",
Expand Down
4 changes: 2 additions & 2 deletions samtranslator/model/apigateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,13 +247,13 @@ def __init__(
if function_payload_type not in ApiGatewayAuthorizer._VALID_FUNCTION_PAYLOAD_TYPES:
raise InvalidResourceException(
api_logical_id,
name + " Authorizer has invalid " "'FunctionPayloadType': " + function_payload_type + ".",
f"{name} Authorizer has invalid 'FunctionPayloadType': {function_payload_type}.",
)

if function_payload_type == "REQUEST" and self._is_missing_identity_source(identity):
raise InvalidResourceException(
api_logical_id,
name + " Authorizer must specify Identity with at least one "
f"{name} Authorizer must specify Identity with at least one "
"of Headers, QueryStrings, StageVariables, or Context.",
)

Expand Down
10 changes: 5 additions & 5 deletions samtranslator/model/apigatewayv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,26 +151,26 @@ def _validate_input_parameters(self):
def _validate_jwt_authorizer(self):
if not self.jwt_configuration:
raise InvalidResourceException(
self.api_logical_id, self.name + " OAuth2 Authorizer must define 'JwtConfiguration'."
self.api_logical_id, f"{self.name} OAuth2 Authorizer must define 'JwtConfiguration'."
)
if not self.id_source:
raise InvalidResourceException(
self.api_logical_id, self.name + " OAuth2 Authorizer must define 'IdentitySource'."
self.api_logical_id, f"{self.name} OAuth2 Authorizer must define 'IdentitySource'."
)

def _validate_lambda_authorizer(self):
if not self.function_arn:
raise InvalidResourceException(
self.api_logical_id, self.name + " Lambda Authorizer must define 'FunctionArn'."
self.api_logical_id, f"{self.name} Lambda Authorizer must define 'FunctionArn'."
)
if not self.authorizer_payload_format_version:
raise InvalidResourceException(
self.api_logical_id, self.name + " Lambda Authorizer must define 'AuthorizerPayloadFormatVersion'."
self.api_logical_id, f"{self.name} Lambda Authorizer must define 'AuthorizerPayloadFormatVersion'."
)

if self.identity and not isinstance(self.identity, dict):
raise InvalidResourceException(
self.api_logical_id, self.name + " Lambda Authorizer property 'identity' is of invalid type."
self.api_logical_id, f"{self.name} Lambda Authorizer property 'identity' is of invalid type."
)

def generate_openapi(self):
Expand Down
6 changes: 2 additions & 4 deletions samtranslator/plugins/api/implicit_api_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,8 @@ def _add_api_to_swagger(self, event_id, event_properties, template):
if isinstance(api_id, dict) or is_referencing_http_from_api_event:
raise InvalidEventException(
event_id,
self.api_id_property
+ " must be a valid reference to an '"
+ self._get_api_resource_type_name()
+ "' resource in same template.",
f"{self.api_id_property} must be a valid reference to an '{self._get_api_resource_type_name()}'"
" resource in same template.",
)

# Make sure Swagger is valid
Expand Down
9 changes: 9 additions & 0 deletions tests/model/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from samtranslator.model import InvalidResourceException
from samtranslator.model.apigateway import ApiGatewayAuthorizer
from samtranslator.utils.py27hash_fix import Py27Dict


class TestApiGatewayAuthorizer(TestCase):
Expand All @@ -25,6 +26,14 @@ def test_create_authorizer_fails_with_missing_identity_values_and_not_cached(sel
function_payload_type="REQUEST",
)

def test_create_authorizer_fails_with_invalid_function_payload_type(self):
with self.assertRaises(InvalidResourceException):
ApiGatewayAuthorizer(
api_logical_id="logicalId",
name="authName",
function_payload_type=Py27Dict({"key": "value"}),
)

def test_create_authorizer_fails_with_empty_identity(self):
with pytest.raises(InvalidResourceException):
ApiGatewayAuthorizer(
Expand Down