Skip to content

Commit

Permalink
Merge branch 'develop' into stepfunctions-callback-policy-template
Browse files Browse the repository at this point in the history
  • Loading branch information
GavinZZ authored May 31, 2024
2 parents e4eee25 + c4f3746 commit 0469134
Show file tree
Hide file tree
Showing 61 changed files with 33,571 additions and 4,127 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ black-check:
make format-check

lint:
ruff samtranslator bin schema_source integration tests
ruff check samtranslator bin schema_source integration tests
# mypy performs type check
mypy --strict samtranslator bin schema_source
# cfn-lint to make sure generated CloudFormation makes sense
bin/run_cfn_lint.sh

lint-fix:
ruff --fix samtranslator bin schema_source integration tests
ruff check --fix samtranslator bin schema_source integration tests

prepare-companion-stack:
pytest -v --no-cov integration/setup -m setup
Expand Down
1 change: 1 addition & 0 deletions bin/_file_formatter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Formatter base class for JSONFormatter and YamlFormatter."""

import argparse
import os
import sys
Expand Down
16 changes: 9 additions & 7 deletions bin/public_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,15 @@ def _print(signature: Dict[str, inspect.Signature], variables: Set[str]) -> None
result: Dict[str, Any] = {"routines": {}, "variables": sorted(variables)}
for key, value in signature.items():
result["routines"][key] = [
{
"name": parameter.name,
"kind": parameter.kind.name,
"default": parameter.default,
}
if parameter.default != inspect.Parameter.empty
else {"name": parameter.name, "kind": parameter.kind.name}
(
{
"name": parameter.name,
"kind": parameter.kind.name,
"default": parameter.default,
}
if parameter.default != inspect.Parameter.empty
else {"name": parameter.name, "kind": parameter.kind.name}
)
for parameter in value.parameters.values()
]
print(json.dumps(result, indent=2, sort_keys=True))
Expand Down
6 changes: 3 additions & 3 deletions integration/combination/test_function_with_all_event_types.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from unittest.case import skipIf

from integration.config.service_names import IOT, SCHEDULE_EVENT
from integration.config.service_names import IOT, LOGS, SCHEDULE_EVENT
from integration.helpers.base_test import BaseTest
from integration.helpers.resource import current_region_does_not_support, generate_suffix


@skipIf(
current_region_does_not_support([IOT, SCHEDULE_EVENT]),
"IoT, ScheduleEvent is not supported in this testing region",
current_region_does_not_support([IOT, SCHEDULE_EVENT, LOGS]),
"IoT, ScheduleEvent or a Logs resource is not supported in this testing region",
)
class TestFunctionWithAllEventTypes(BaseTest):
def test_function_with_all_event_types(self):
Expand Down
8 changes: 8 additions & 0 deletions integration/combination/test_function_with_cloudwatch_log.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
from unittest.case import skipIf

from integration.config.service_names import LOGS
from integration.helpers.base_test import BaseTest
from integration.helpers.resource import current_region_does_not_support


@skipIf(
current_region_does_not_support([LOGS]),
"A Logs resource that is a part of this test is not supported in this testing region",
)
class TestFunctionWithCloudWatchLog(BaseTest):
def test_function_with_cloudwatch_log(self):
self.create_and_verify_stack("combination/function_with_cloudwatch_log")
Expand Down
1 change: 1 addition & 0 deletions integration/config/service_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@
API_KEY = "ApiKey"
APP_SYNC = "AppSync"
SNS_FILTER_POLICY_SCOPE = "SnsFilterPolicyScope"
LOGS = "Logs"
6 changes: 3 additions & 3 deletions integration/helpers/deployer/deployer.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,9 @@ def describe_changeset(self, change_set_id, stack_name, **kwargs):
{
"LogicalResourceId": resource_props.get("LogicalResourceId"),
"ResourceType": resource_props.get("ResourceType"),
"Replacement": "N/A"
if resource_props.get("Replacement") is None
else resource_props.get("Replacement"),
"Replacement": (
"N/A" if resource_props.get("Replacement") is None else resource_props.get("Replacement")
),
}
)

Expand Down
1 change: 1 addition & 0 deletions integration/helpers/deployer/utils/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Wrapper to generated colored messages for printing in Terminal
This was ported over from the sam-cli repo
"""

from typing import Dict, Literal

SupportedColor = Literal["red", "green", "yellow"]
Expand Down
1 change: 1 addition & 0 deletions integration/helpers/deployer/utils/retry.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Retry decorator to retry decorated function based on Exception with exponential backoff and number of attempts built-in.
"""

import math
import random
import time
Expand Down
1 change: 1 addition & 0 deletions integration/helpers/deployer/utils/table_print.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Utilities for table pretty printing
This was ported over from the sam-cli repo
"""

import shutil
import textwrap
from functools import wraps
Expand Down
1 change: 1 addition & 0 deletions integration/helpers/s3_uploader.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Client for uploading files to s3
"""

import logging
from typing import Any

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ Resources:

MyTopic:
Type: AWS::SNS::Topic
Properties:
KmsMasterKeyId: alias/aws/sns

MyConnector:
Type: AWS::Serverless::Connector
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ Resources:
Type: AWS::Kinesis::Stream
Properties:
ShardCount: 1
StreamEncryption:
EncryptionType: KMS
KeyId: alias/aws/kinesis

# What an irony the I can't use AWS::Serverless::SimpleTable here because it doesn't support streams specification
MyTable:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ Resources:
Condition: MyCondition
Properties:
ShardCount: 1
StreamEncryption:
EncryptionType: KMS
KeyId: alias/aws/kinesis

MyDynamoDB:
UpdateReplacePolicy: Delete
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ Resources:
Condition: MyCondition
Properties:
ShardCount: 1
StreamEncryption:
EncryptionType: KMS
KeyId: alias/aws/kinesis

MyDynamoDB:
Type: AWS::DynamoDB::Table
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,8 @@ Resources:
Type: AWS::Kinesis::Stream
Properties:
ShardCount: 1
StreamEncryption:
EncryptionType: KMS
KeyId: alias/aws/kinesis
Metadata:
SamTransformTest: true
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,8 @@ Resources:
Type: AWS::Kinesis::Stream
Properties:
ShardCount: 1
StreamEncryption:
EncryptionType: KMS
KeyId: alias/aws/kinesis
Metadata:
SamTransformTest: true
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ Resources:

MyTopic:
Type: AWS::SNS::Topic
Properties:
KmsMasterKeyId: alias/aws/sns
Metadata:
SamTransformTest: true
10 changes: 5 additions & 5 deletions integration/ruff.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# black formatter takes care of the line length
line-length = 999

# Mininal python version we support is 3.8
target-version = "py38"

# The code quality of tests can be a bit lower compared to samtranslator
select = [
lint.select = [
"E", # Pyflakes
"F", # Pyflakes
"PL", # pylint
Expand All @@ -15,10 +18,7 @@ select = [
"UP", # pyupgrade
]

# Mininal python version we support is 3.8
target-version = "py38"

[per-file-ignores]
[lint.per-file-ignores]

# The code quality of tests can be a bit lower:
"**/*.py" = [
Expand Down
4 changes: 2 additions & 2 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pytest-xdist>=2.5,<4
pytest-env>=0.6,<1
pytest-rerunfailures>=9.1,<12
pyyaml~=6.0
ruff~=0.1.0
ruff~=0.4.5

# Test requirements
pytest>=6.2,<8
Expand All @@ -19,7 +19,7 @@ tenacity~=8.0
requests~=2.28

# formatter
black==23.10.1
black==24.3.0
ruamel.yaml==0.17.21 # It can parse yaml while perserving comments

# type check
Expand Down
14 changes: 7 additions & 7 deletions ruff.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# black formatter takes care of the line length
line-length = 999

select = [
# Mininal python version we support is 3.8
target-version = "py38"

lint.select = [
"E", # pycodestyle
"W", # pycodestyle
"F", # Pyflakes
Expand All @@ -27,7 +30,7 @@ select = [
"T20", # flake8-print
]

ignore = [
lint.ignore = [
"UP006", # https://github.com/charliermarsh/ruff/pull/4427
"UP007", # https://github.com/charliermarsh/ruff/pull/4427
# Mutable class attributes should be annotated with `typing.ClassVar`
Expand All @@ -37,10 +40,7 @@ ignore = [
"G004",
]

# Mininal python version we support is 3.8
target-version = "py38"

[per-file-ignores]
[lint.per-file-ignores]
# python scripts in bin/ needs some python path configurations before import
"bin/*.py" = [
# E402: module-import-not-at-top-of-file
Expand All @@ -53,5 +53,5 @@ target-version = "py38"
"T201",
]

[pylint]
[lint.pylint]
max-args = 6 # We have many functions reaching 6 args
2 changes: 1 addition & 1 deletion samtranslator/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.85.0"
__version__ = "1.89.0"
1 change: 1 addition & 0 deletions samtranslator/internal/deprecation_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
If external packages import deprecated interfaces,
it is their responsibility to detect and remove them.
"""

import warnings
from functools import wraps
from typing import Callable, Optional, TypeVar
Expand Down
9 changes: 5 additions & 4 deletions samtranslator/metrics/method_decorator.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Method decorator for execution latency collection
"""

import functools
import logging
from datetime import datetime
Expand Down Expand Up @@ -84,13 +85,13 @@ def _send_cw_metric(prefix, name, execution_time_ms, func, args): # type: ignor
@overload
def cw_timer(
*, name: Optional[str] = None, prefix: Optional[str] = None
) -> Callable[[Callable[_PT, _RT]], Callable[_PT, _RT]]:
...
) -> Callable[[Callable[_PT, _RT]], Callable[_PT, _RT]]: ...


@overload
def cw_timer(_func: Callable[_PT, _RT], name: Optional[str] = None, prefix: Optional[str] = None) -> Callable[_PT, _RT]:
...
def cw_timer(
_func: Callable[_PT, _RT], name: Optional[str] = None, prefix: Optional[str] = None
) -> Callable[_PT, _RT]: ...


def cw_timer(
Expand Down
1 change: 1 addition & 0 deletions samtranslator/model/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
""" CloudFormation Resource serialization, deserialization, and validation """

import inspect
import re
from abc import ABC, ABCMeta, abstractmethod
Expand Down
17 changes: 13 additions & 4 deletions samtranslator/model/api/api_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from dataclasses import dataclass
from typing import Any, Dict, List, Optional, Set, Tuple, Union, cast

from samtranslator.feature_toggle.feature_toggle import FeatureToggle
from samtranslator.metrics.method_decorator import cw_timer
from samtranslator.model import Resource
from samtranslator.model.apigateway import (
Expand Down Expand Up @@ -40,6 +41,8 @@

LOG = logging.getLogger(__name__)

FEATURE_FLAG_NORMALIZED_OPENAPI_VERSION = "normalized_open_api_version"

_CORS_WILDCARD = "'*'"
CorsProperties = namedtuple(
"CorsProperties", ["AllowMethods", "AllowHeaders", "AllowOrigin", "MaxAge", "AllowCredentials"]
Expand Down Expand Up @@ -205,6 +208,7 @@ def __init__( # noqa: PLR0913
mode: Optional[Intrinsicable[str]] = None,
api_key_source_type: Optional[Intrinsicable[str]] = None,
always_deploy: Optional[bool] = False,
feature_toggle: Optional[FeatureToggle] = None,
):
"""Constructs an API Generator class that generates API Gateway resources
Expand Down Expand Up @@ -261,6 +265,7 @@ def __init__( # noqa: PLR0913
self.mode = mode
self.api_key_source_type = api_key_source_type
self.always_deploy = always_deploy
self.feature_toggle = feature_toggle

def _construct_rest_api(self) -> ApiGatewayRestApi:
"""Constructs and returns the ApiGateway RestApi.
Expand Down Expand Up @@ -1125,11 +1130,15 @@ def _openapi_postprocess(self, definition_body: Dict[str, Any]) -> Dict[str, Any
if definition_body.get("swagger") is not None:
return definition_body

if definition_body.get("openapi") is not None and self.open_api_version is None:
self.open_api_version = definition_body.get("openapi")
if self.feature_toggle and self.feature_toggle.is_enabled(FEATURE_FLAG_NORMALIZED_OPENAPI_VERSION):
normalized_open_api_version = definition_body.get("openapi", self.open_api_version)
elif definition_body.get("openapi") is not None and self.open_api_version is None:
normalized_open_api_version = definition_body.get("openapi")
else:
normalized_open_api_version = self.open_api_version

if self.open_api_version and SwaggerEditor.safe_compare_regex_with_string(
SwaggerEditor._OPENAPI_VERSION_3_REGEX, self.open_api_version
if normalized_open_api_version and SwaggerEditor.safe_compare_regex_with_string(
SwaggerEditor._OPENAPI_VERSION_3_REGEX, normalized_open_api_version
):
if definition_body.get("securityDefinitions"):
components = definition_body.get("components", Py27Dict())
Expand Down
7 changes: 2 additions & 5 deletions samtranslator/model/api/http_api_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,8 +633,7 @@ def _get_authorizers(
if "OpenIdConnectUrl" in authorizer:
raise InvalidResourceException(
self.logical_id,
"'OpenIdConnectUrl' is no longer a supported property for authorizer '%s'. Please refer to the AWS SAM documentation."
% (authorizer_name),
f"'OpenIdConnectUrl' is no longer a supported property for authorizer '{authorizer_name}'. Please refer to the AWS SAM documentation.",
)
authorizers[authorizer_name] = ApiGatewayV2Authorizer( # type: ignore[no-untyped-call]
api_logical_id=self.logical_id,
Expand Down Expand Up @@ -777,9 +776,7 @@ def _add_title(self) -> None:
self.definition_body = open_api_editor.openapi

@cw_timer(prefix="Generator", name="HttpApi")
def to_cloudformation(
self, route53_record_set_groups: Dict[str, Route53RecordSetGroup]
) -> Tuple[
def to_cloudformation(self, route53_record_set_groups: Dict[str, Route53RecordSetGroup]) -> Tuple[
ApiGatewayV2HttpApi,
Optional[ApiGatewayV2Stage],
Optional[ApiGatewayV2DomainName],
Expand Down
Loading

0 comments on commit 0469134

Please sign in to comment.