Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: aws/serverless-application-model
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.36.0
Choose a base ref
...
head repository: aws/serverless-application-model
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 4 commits
  • 521 files changed
  • 26 contributors

Commits on Jul 6, 2021

  1. Release/v1.37.0 (#2079)

    * Release/v1.37.0 (#2069)
    * chore: bump version to 1.37.0 (#2068)
    
    * fix: Increase PageSize of ListPolicies Paginator (#2033)
    Co-authored-by: Jacob Fuss <32497805+jfuss@users.noreply.github.com>
    Co-authored-by: Jacob Fuss <jfuss@users.noreply.github.com>
    
    * feat: Support VIRTUAL_HOST as Type for SourceAccessConfiguration for MQ events (#76) (#2078)
    Co-authored-by: Renato Valenzuela <37676028+valerena@users.noreply.github.com>
    mgrandis authored Jul 6, 2021
    Copy the full SHA
    25fa8a8 View commit details

Commits on Jul 19, 2021

  1. Release/v1.38.0 (#2082) (#2095)

    * test: New test group to test for side effects (#2046)
    
    * test: New test group to test for side effects
    
    * refactor: Updated to use _compare_transform and test CN and GOV partitions
    
    * docs: fix dead link (#2045)
    
    * Percentage-based Enablement for Feature Toggle (#1952)
    
    * Percentage-based Enablement for Feature Toggle
    
    * Update Feature Toggle to accept stage, account_id and region during instanciation
    
    * remove unnecessary uses of dict.get method
    
    * Refactor feature toggle methods
    
    * Update test names
    
    * black reformat
    
    * Update FeatureToggle to require stage, region and account_id to instanciate
    
    * Update log message
    
    * Implement calculating account percentile based on hash of account_id and feature_name
    
    * Refactor _is_feature_enabled_for_region_config
    
    * Refactor dialup logic into its own classes
    
    * Add comments for dialup classes
    
    * Rename NeverEnabledDialup to DisabledDialup
    
    * chore(tests): Adding any tests (#2053)
    
    * Adding api_request_model any tests
    
    * Add any to api_request_model_openapi_3 cases
    
    * Add rest of relevant any test cases
    
    * Fix hashing to match python2
    
    * add api_with_swagger_authorizer_none to be run
    
    * fix py2 hashes in api_with_swagger_authorizer_none tests
    
    Co-authored-by: Jacob Fuss <jfuss@users.noreply.github.com>
    
    * Add modes support for RestApi (#2055)
    
    * Adding Mode passthrough property to RestApi with unit tests.
    
    * Adding integration test for Mode
    
    * Fixing sam-translate for manual translation.
    
    * running black formatting
    
    * Running black formatting, again.
    
    * Clearing pip-wheel-metadata.
    
    * Clearing tmp folder created by integ test.
    
    Co-authored-by: Tarun Mall <tarun@amazon.noreply.github.com>
    
    * chore: bump version to 1.38.0 (#2081)
    
    Co-authored-by: Mathieu Grandis <73313235+mgrandis@users.noreply.github.com>
    Co-authored-by: Chris Rehn <crehn@outlook.com>
    Co-authored-by: Wing Fung Lau <4760060+hawflau@users.noreply.github.com>
    Co-authored-by: Jacob Fuss <32497805+jfuss@users.noreply.github.com>
    Co-authored-by: Jacob Fuss <jfuss@users.noreply.github.com>
    Co-authored-by: Tarun Mall <tarun@amazon.noreply.github.com>
    Co-authored-by: Raymond Wang <14915548+wchengru@users.noreply.github.com>
    
    Co-authored-by: Mathieu Grandis <73313235+mgrandis@users.noreply.github.com>
    Co-authored-by: Chris Rehn <crehn@outlook.com>
    Co-authored-by: Wing Fung Lau <4760060+hawflau@users.noreply.github.com>
    Co-authored-by: Jacob Fuss <32497805+jfuss@users.noreply.github.com>
    Co-authored-by: Jacob Fuss <jfuss@users.noreply.github.com>
    Co-authored-by: Tarun Mall <tarun@amazon.noreply.github.com>
    Co-authored-by: Raymond Wang <14915548+wchengru@users.noreply.github.com>
    8 people authored Jul 19, 2021
    Copy the full SHA
    4ef6093 View commit details

Commits on Sep 29, 2021

  1. Release/v1.39.0 (#2165)

    * Release/v1.39.0 (#2141)
    
    * chore: don't install integration tests (#1964)
    
    * Remove unnecessary use of comprehension (#1805)
    
    * fix: Grammatical error in README.md (#1965)
    
    * fix: Added SAR Support Check (#1972)
    
    * Added SAR Support Check
    
    * Added docstring and Removed Instance Initialization for Class Method
    
    * update pyyaml version to get the security update (#1974)
    
    * fix the request parameter parsing, the value can contain dots (#1975)
    
    * fix the request parameter parsing, the value can contain dots
    
    * fix the unit test for python 2.7
    
    * use built in split, instead of concatenating the string
    
    * Documentation: fix incorrect header (#1979)
    
    Fixed the incorrectly formatted header for HTTP API section
    
    * fix: mutable default values in method definitions (#1997)
    
    * fix: remove explicit logging level set in single module (#1998)
    
    * fix: Fail when Intrinsics are in SourceVPC list instead of IntrinsicsSourceVPC (#1999)
    
    * feat: Adding support for metric publishing. (#2062)
    
    * Adding support for metric publishing, manually tested and tests pending.
    
    * Adding make action for running test with html coverage.
    
    * Adding unit tests for metrics.
    
    * Writing integration tests for metrics publishing.
    
    * Black reformatting
    
    * Fixing unit test.
    
    * Addressing PR comments.
    
    * Clearing __init__py from test module.
    
    * Updating documentation for publish method.
    
    Co-authored-by: Tarun Mall <tarun@amazon.noreply.github.com>
    
    * Update AppConfig boto3 client config to shorten timeout (#2070)
    
    * Update AppConfig boto3 client config to shorten timeout
    
    * Update timeout config of AppConfig boto3 client
    
    * feat: Add ValidateBody/ValidateParameters attribute to API models (#2026)
    
    * Added validators to the swagger definitions when a model is required
    
    * Remove approach of trying an extra field for validators
    
    * WIP - tests deps not working
    
    * Finished and fixed all tests to make pr command was complaining. Fixed case where a validator could have a / only and changed it to translate as 'root'
    
    * py2.7 complaint
    
    * Fix py2.7 order of validators on output folder
    
    * WIP - adding validator fields
    
    * Set another strategy to set the validators without affect existent clients with model required
    
    * Set another strategy to set the validators without affect existent clients with model required
    
    * Remove mistaken file pushed
    
    * Remove mistaken file pushed
    
    * Partial coments fixes
    
    * Implemented case where we can set a only limited combinations on the specs
    
    * Fix case test when multiple path are using same validator
    
    * Added openapi3 specific tests
    
    * Added openapi3 specific tests
    
    * Fix requested changes from review: Renamed from ValidateRequest -> ValidateParameters also renamed everything from validator_request. Moved validators names according with the comum use.
    
    * new approach to not cause KeyErrors
    
    * Setting validator to the only given method not all methods on the path
    
    * removed extra space on comment - lint
    
    * Normalized method name path that comes from the template
    
    Co-authored-by: Rondineli Gomes de Araujo <rgomesdearaujo@rgomesdearaujo-mbp.ad.shuttercorp.net>
    Co-authored-by: Rondineli <rondineli.gomes.araujo@gmail.com>
    Co-authored-by: Rondineli <rgomesdearaujo@yahoo.com.br>
    
    * fix: fail with invalid resource, when RetentionPolicy has unresolved intrinsic value (#2074)
    
    * fix: fail with invalid resource, when RetentionPolicy has unresolved intrinsic value
    
    * make black
    
    * remove extra formatting
    
    * add test case for !ref
    
    * test: Migration of combination integration tests (#1970)
    
    * fix: Compare integration tests results using hash of file content instead of image compare (#2086)
    
    * change yaml.load to yaml.safe_load for the security best practice
    
    * use yaml_parse for consistant style
    
    * remove pillow library for image comparing, use hash instead
    
    * make it compatible with py2
    
    * Remove logging of SAR service call response (#2064)
    
    * Test CloudWatchEvent Properties With Intrinsic Functions (#2090)
    
    * Add headers whenever cors is set
    
    * Add cw event success cases
    
    * Replace GetAtt with condition
    
    * Cleanup test yaml
    
    * Cleanup test yaml
    
    * Remove files
    
    * Add intrinsic to pattern field
    
    * Fix wrong files committed
    
    * test: Added intrinsic tests for Function SNS Event (#2101)
    
    * fix: Validate Trigger field and test Cognito properties with intrinsic functions (#2092)
    
    * Add headers whenever cors is set
    
    * Fix Cognito trigger validation
    
    * Make templates deployable
    
    * Removed trigger value validation
    
    * Fix Python2 string matching test issue
    
    * Use PropertyType mechanism to exclude intrinsics
    
    * Remove unused import
    
    * feat(Intrinsic Tests): Added Tests for Kinesis Event Source with Intrinsics (#2103)
    
    * Added Tests for Kinesis EventSource with Intrinsics
    
    * Fixed Formatting with Black
    
    * fix: Don't attempt to refetch a swagger method object by its name as we already have it (#2031)
    
    * Fix a bad logic where a hash key is modified then refetched which results in KeyError
    
    * add unit tests and update other instance of same usage on line 534
    
    * fix: Fix the same code in open_api.py
    
    Co-authored-by: Mehmet Nuri Deveci <5735811+mndeveci@users.noreply.github.com>
    Co-authored-by: Mathieu Grandis <grmathie@amazon.com>
    
    * test: Adding intrinsic tests for Function S3 Event (#2100)
    
    * fix(bug): Check if Identity.ReauthorizeEvery equals zero (#2105)
    
    * Revert "Revert "Issue 1508 remove check requiring identity ... (#1577)" (#2038)"
    
    This reverts commit ed3c283.
    
    * Update implementation to support intrinsics/ add more tests to validate changes
    
    * Fixing hashes for py2
    
    * Run make black
    
    * Handle pr feedback
    
    * Add another unit tests to cover the original issue
    
    Co-authored-by: Jacob Fuss <jfuss@users.noreply.github.com>
    
    * chore: Update PR Checklist to include writing intrinsic tests (#2106)
    
    * Update PR Checklist to include writing intrinsic tests
    
    * Handle pr feedback
    
    Co-authored-by: Jacob Fuss <jfuss@users.noreply.github.com>
    
    * Delete .travis.yml (#2102)
    
    * fix: Correct grammar in the waiting for changeset message (#2027)
    
    * chore: bump version to 1.39.0 (#2128)
    
    Co-authored-by: Chih-Hsuan Yen <yan12125@gmail.com>
    Co-authored-by: Harsh Mishra <erbeusgriffincasper@gmail.com>
    Co-authored-by: Pranav <54665036+Pranav016@users.noreply.github.com>
    Co-authored-by: Cosh_ <CoshUS@users.noreply.github.com>
    Co-authored-by: Mohamed Elasmar <71043312+moelasmar@users.noreply.github.com>
    Co-authored-by: Ben <freiberg.ben@gmail.com>
    Co-authored-by: Mehmet Nuri Deveci <5735811+mndeveci@users.noreply.github.com>
    Co-authored-by: Jacob Fuss <32497805+jfuss@users.noreply.github.com>
    Co-authored-by: Tarun <c2tarun@users.noreply.github.com>
    Co-authored-by: Tarun Mall <tarun@amazon.noreply.github.com>
    Co-authored-by: Wing Fung Lau <4760060+hawflau@users.noreply.github.com>
    Co-authored-by: Rondineli <Rondineli@users.noreply.github.com>
    Co-authored-by: Rondineli Gomes de Araujo <rgomesdearaujo@rgomesdearaujo-mbp.ad.shuttercorp.net>
    Co-authored-by: Rondineli <rondineli.gomes.araujo@gmail.com>
    Co-authored-by: Rondineli <rgomesdearaujo@yahoo.com.br>
    Co-authored-by: mingkun2020 <68391979+mingkun2020@users.noreply.github.com>
    Co-authored-by: Daniel Mil <84205762+mildaniel@users.noreply.github.com>
    Co-authored-by: Ahmed Elbayaa <72949274+elbayaaa@users.noreply.github.com>
    Co-authored-by: Jacob Fuss <jfuss@users.noreply.github.com>
    Co-authored-by: Ichinose Shogo <shogo82148@gmail.com>
    Co-authored-by: Ryan Parman <ryan@ryanparman.com>
    
    * feat: ARM support (#2163)
    
    * feat: ARM architecture support for Function and Layer
    
    * Add docs/tests for Globals Architectures (#85)
    
    Co-authored-by: Renato Valenzuela <37676028+valerena@users.noreply.github.com>
    
    Co-authored-by: Chih-Hsuan Yen <yan12125@gmail.com>
    Co-authored-by: Harsh Mishra <erbeusgriffincasper@gmail.com>
    Co-authored-by: Pranav <54665036+Pranav016@users.noreply.github.com>
    Co-authored-by: Cosh_ <CoshUS@users.noreply.github.com>
    Co-authored-by: Mohamed Elasmar <71043312+moelasmar@users.noreply.github.com>
    Co-authored-by: Ben <freiberg.ben@gmail.com>
    Co-authored-by: Mehmet Nuri Deveci <5735811+mndeveci@users.noreply.github.com>
    Co-authored-by: Jacob Fuss <32497805+jfuss@users.noreply.github.com>
    Co-authored-by: Tarun <c2tarun@users.noreply.github.com>
    Co-authored-by: Tarun Mall <tarun@amazon.noreply.github.com>
    Co-authored-by: Wing Fung Lau <4760060+hawflau@users.noreply.github.com>
    Co-authored-by: Rondineli <Rondineli@users.noreply.github.com>
    Co-authored-by: Rondineli Gomes de Araujo <rgomesdearaujo@rgomesdearaujo-mbp.ad.shuttercorp.net>
    Co-authored-by: Rondineli <rondineli.gomes.araujo@gmail.com>
    Co-authored-by: Rondineli <rgomesdearaujo@yahoo.com.br>
    Co-authored-by: mingkun2020 <68391979+mingkun2020@users.noreply.github.com>
    Co-authored-by: Daniel Mil <84205762+mildaniel@users.noreply.github.com>
    Co-authored-by: Ahmed Elbayaa <72949274+elbayaaa@users.noreply.github.com>
    Co-authored-by: Jacob Fuss <jfuss@users.noreply.github.com>
    Co-authored-by: Ichinose Shogo <shogo82148@gmail.com>
    Co-authored-by: Ryan Parman <ryan@ryanparman.com>
    Co-authored-by: Renato Valenzuela <37676028+valerena@users.noreply.github.com>
    23 people authored Sep 29, 2021
    Copy the full SHA
    5d60204 View commit details

Commits on Nov 30, 2021

  1. Copy the full SHA
    7a4a99d View commit details
Showing 521 changed files with 41,752 additions and 13,311 deletions.
5 changes: 4 additions & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -6,7 +6,10 @@

*Checklist:*

- [ ] Write/update tests
- [ ] Add/update tests using:
- [ ] Correct values
- [ ] Bad/wrong values (None, empty, wrong type, length, etc.)
- [ ] [Intrinsic Functions](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference.html)
- [ ] `make pr` passes
- [ ] Update documentation
- [ ] Verify transformed template deploys and application functions as expected
30 changes: 0 additions & 30 deletions .travis.yml

This file was deleted.

3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -8,6 +8,9 @@ init:
test:
pytest --cov samtranslator --cov-report term-missing --cov-fail-under 95 tests/*

test-cov-report:
pytest --cov samtranslator --cov-report term-missing --cov-report html --cov-fail-under 95 tests/*

integ-test:
pytest --no-cov integration/*

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -52,7 +52,7 @@ environment that lets you locally build, test, debug, and deploy applications de

## What is this Github repository? 💻

This GitHub repository contains the SAM Specification, the Python code that translates SAM templates into AWS CloudFormation stacks and lots of examples applications.
This GitHub repository contains the SAM Specification, the Python code that translates SAM templates into AWS CloudFormation stacks and lots of example applications.
In the words of SAM developers:

> SAM Translator is the Python code that deploys SAM templates via AWS CloudFormation. Source code is high quality (95% unit test coverage),
5 changes: 4 additions & 1 deletion bin/sam-translate.py
Original file line number Diff line number Diff line change
@@ -99,7 +99,10 @@ def transform_template(input_file_path, output_file_path):
feature_toggle = FeatureToggle(
FeatureToggleLocalConfigProvider(
os.path.join(my_path, "..", "tests", "feature_toggle", "input", "feature_toggle_config.json")
)
),
stage=None,
account_id=None,
region=None,
)
cloud_formation_template = transform(sam_template, {}, ManagedPolicyLoader(iam_client), feature_toggle)
cloud_formation_template_prettified = json.dumps(cloud_formation_template, indent=2)
1 change: 1 addition & 0 deletions docs/globals.rst
Original file line number Diff line number Diff line change
@@ -70,6 +70,7 @@ Currently, the following resources and properties are being supported:
PermissionsBoundary:
ReservedConcurrentExecutions:
EventInvokeConfig:
Architectures:
Api:
# Properties of AWS::Serverless::Api
2 changes: 1 addition & 1 deletion docs/internals/generated_resources.rst
Original file line number Diff line number Diff line change
@@ -129,7 +129,7 @@ AWS::Lambda::Permission MyFunction\ **ThumbnailApi**\ Permission\ **P
NOTE: ``ServerlessRestApi*`` resources are generated one per stack.

HTTP API
^^^
^^^^
This is called an "Implicit HTTP API". There can be many functions in the template that define these APIs. Behind the
scenes, SAM will collect all implicit HTTP APIs from all Functions in the template, generate an OpenApi doc, and create an
implicit ``AWS::Serverless::HttpApi`` using this OpenApi. This API defaults to a StageName called "$default" that cannot be
2 changes: 1 addition & 1 deletion docs/safe_lambda_deployments.rst
Original file line number Diff line number Diff line change
@@ -190,7 +190,7 @@ NOTE: Verify that your AWS SDK version supports PutLifecycleEventHookExecutionSt

.. _PutLifecycleEventHookExecutionStatus: https://docs.aws.amazon.com/codedeploy/latest/APIReference/API_PutLifecycleEventHookExecutionStatus.html

.. _Here: https://github.com/awslabs/serverless-application-model/blob/master/examples/2016-10-31/lambda_safe_deployments/src/preTrafficHook.js
.. _Here: https://github.com/aws/serverless-application-model/blob/d168f371f494196a57032313075db9faae5587e4/examples/2016-10-31/lambda_safe_deployments/src/preTrafficHook.js

Traffic Shifting Configurations
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Empty file.
181 changes: 181 additions & 0 deletions integration/combination/test_api_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
import hashlib

try:
from pathlib import Path
except ImportError:
from pathlib2 import Path

import requests
from parameterized import parameterized

from integration.helpers.base_test import BaseTest


class TestApiSettings(BaseTest):
def test_method_settings(self):
self.create_and_verify_stack("combination/api_with_method_settings")

rest_api_id = self.get_physical_id_by_type("AWS::ApiGateway::RestApi")
apigw_client = self.client_provider.api_client
response = apigw_client.get_stage(restApiId=rest_api_id, stageName="Prod")

wildcard_path = "*/*"

method_settings = response["methodSettings"]
self.assertTrue(wildcard_path in method_settings, "MethodSettings for the wildcard path must be present")

wildcard_path_setting = method_settings[wildcard_path]

self.assertTrue(wildcard_path_setting["metricsEnabled"], "Metrics must be enabled")
self.assertTrue(wildcard_path_setting["dataTraceEnabled"], "DataTrace must be enabled")
self.assertEqual(wildcard_path_setting["loggingLevel"], "INFO", "LoggingLevel must be INFO")

@parameterized.expand(
[
"combination/api_with_binary_media_types",
"combination/api_with_binary_media_types_with_definition_body",
]
)
def test_binary_media_types(self, file_name):
self.create_and_verify_stack(file_name, self.get_default_test_template_parameters())

rest_api_id = self.get_physical_id_by_type("AWS::ApiGateway::RestApi")
apigw_client = self.client_provider.api_client

response = apigw_client.get_rest_api(restApiId=rest_api_id)
self.assertEqual(set(response["binaryMediaTypes"]), {"image/jpg", "image/png", "image/gif"})

@parameterized.expand(
[
"combination/api_with_request_models",
"combination/api_with_request_models_openapi",
]
)
def test_request_models(self, file_name):
self.create_and_verify_stack(file_name)

rest_api_id = self.get_physical_id_by_type("AWS::ApiGateway::RestApi")
apigw_client = self.client_provider.api_client

response = apigw_client.get_models(restApiId=rest_api_id)
request_models = response["items"]

self.assertEqual(request_models[0]["name"], "user")
self.assertEqual(
request_models[0]["schema"],
'{\n "type" : "object",\n'
+ ' "properties" : {\n "username" : {\n "type" : "string"\n }\n'
+ " }\n}",
)

def test_request_parameters_open_api(self):
self.create_and_verify_stack("combination/api_with_request_parameters_openapi")

rest_api_id = self.get_physical_id_by_type("AWS::ApiGateway::RestApi")
apigw_client = self.client_provider.api_client

# Test if the request parameters got set on the method
resources_response = apigw_client.get_resources(restApiId=rest_api_id)
resources = resources_response["items"]

resource = get_resource_by_path(resources, "/one")
method = apigw_client.get_method(restApiId=rest_api_id, resourceId=resource["id"], httpMethod="GET")
expected = {"method.request.querystring.type": True}
self.assertEqual(expected, method["requestParameters"])

# Test that the method settings got applied on the method
stage_response = apigw_client.get_stage(restApiId=rest_api_id, stageName="Prod")
method_settings = stage_response["methodSettings"]

path = "one/GET"
self.assertTrue(path in method_settings, "MethodSettings for the path must be present")

path_settings = method_settings[path]
self.assertEqual(path_settings["cacheTtlInSeconds"], 15)
self.assertTrue(path_settings["cachingEnabled"], "Caching must be enabled")

def test_binary_media_types_with_definition_body_openapi(self):
parameters = self.get_default_test_template_parameters()
binary_media = {
"ParameterKey": "BinaryMediaCodeKey",
"ParameterValue": "binary-media.zip",
"UsePreviousValue": False,
"ResolvedValue": "string",
}
parameters.append(binary_media)

self.create_and_verify_stack("combination/api_with_binary_media_types_with_definition_body_openapi", parameters)

rest_api_id = self.get_physical_id_by_type("AWS::ApiGateway::RestApi")
apigw_client = self.client_provider.api_client

response = apigw_client.get_rest_api(restApiId=rest_api_id)
self.assertEqual(
set(response["binaryMediaTypes"]), {"image/jpg", "image/png", "image/gif", "application/octet-stream"}
)
base_url = self.get_stack_output("ApiUrl")["OutputValue"]
self.verify_binary_media_request(base_url + "none", 200)

@parameterized.expand(
[
"combination/api_with_endpoint_configuration",
"combination/api_with_endpoint_configuration_dict",
]
)
def test_end_point_configuration(self, file_name):
self.create_and_verify_stack(file_name, self.get_default_test_template_parameters())

rest_api_id = self.get_physical_id_by_type("AWS::ApiGateway::RestApi")
apigw_client = self.client_provider.api_client

response = apigw_client.get_rest_api(restApiId=rest_api_id)
endpoint_config = response["endpointConfiguration"]
self.assertEqual(endpoint_config["types"], ["REGIONAL"])

def test_implicit_api_settings(self):
self.create_and_verify_stack("combination/implicit_api_with_settings")

rest_api_id = self.get_physical_id_by_type("AWS::ApiGateway::RestApi")
apigw_client = self.client_provider.api_client

response = apigw_client.get_stage(restApiId=rest_api_id, stageName="Prod")

wildcard_path = "*/*"

method_settings = response["methodSettings"]
self.assertTrue(wildcard_path in method_settings, "MethodSettings for the wildcard path must be present")

wildcard_path_setting = method_settings[wildcard_path]

self.assertTrue(wildcard_path_setting["metricsEnabled"], "Metrics must be enabled")
self.assertTrue(wildcard_path_setting["dataTraceEnabled"], "DataTrace must be enabled")
self.assertEqual(wildcard_path_setting["loggingLevel"], "INFO", "LoggingLevel must be INFO")

response = apigw_client.get_rest_api(restApiId=rest_api_id)
endpoint_config = response["endpointConfiguration"]
self.assertEqual(endpoint_config["types"], ["REGIONAL"])
self.assertEqual(set(response["binaryMediaTypes"]), {"image/jpg", "image/png"})

def verify_binary_media_request(self, url, expected_status_code):
headers = {"accept": "image/png"}
response = requests.get(url, headers=headers)

status = response.status_code
expected_file_path = str(Path(self.code_dir, "AWS_logo_RGB.png"))

with open(expected_file_path, mode="rb") as file:
expected_file_content = file.read()
expected_hash = hashlib.sha1(expected_file_content).hexdigest()

if 200 <= status <= 299:
actual_hash = hashlib.sha1(response.content).hexdigest()
self.assertEqual(expected_hash, actual_hash)

self.assertEqual(status, expected_status_code, " must return HTTP " + str(expected_status_code))


def get_resource_by_path(resources, path):
for resource in resources:
if resource["path"] == path:
return resource
return None
Loading