Skip to content

chore: Add integration test service detector for SNS FilterPolicyScope #3015

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

Merged
merged 2 commits into from
Mar 10, 2023
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
2 changes: 1 addition & 1 deletion integration/config/service_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
SNS = "SNS"
SQS = "SQS"
CUSTOM_DOMAIN = "CustomDomain"
ARM = "ARM"
EFS = "EFS"
S3_EVENTS = "S3Events"
SELF_MANAGED_KAFKA = "SelfManagedKafka"
Expand All @@ -36,3 +35,4 @@
EPHEMERAL_STORAGE = "EphemeralStorage"
API_KEY = "ApiKey"
APP_SYNC = "AppSync"
SNS_FILTER_POLICY_SCOPE = "SnsFilterPolicyScope"
17 changes: 16 additions & 1 deletion integration/helpers/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import random
import re
import string # pylint: disable=deprecated-module
from typing import Any, Callable, Dict, Set
from typing import Any, Callable, Dict, Iterator, Set

from integration.config.service_names import (
APP_SYNC,
Expand All @@ -12,6 +12,7 @@
REST_API,
S3_EVENTS,
SCHEDULE_EVENT,
SNS_FILTER_POLICY_SCOPE,
SQS,
STATE_MACHINE_INLINE_DEFINITION,
)
Expand Down Expand Up @@ -210,6 +211,17 @@ def _resource_using_s3_events(resource: Dict[str, Any]) -> bool:
return resource_type == "AWS::S3::Bucket" and properties.get("NotificationConfiguration")


def _get_all_event_sources(template_dict: Dict[str, Any]) -> Iterator[Dict[str, Any]]:
resources = template_dict.get("Resources", {}).values()
for resource in resources:
for event in resource.get("Properties", {}).get("Events", {}).values():
yield event


def _event_using_sns_filter_policy_scope(event: Dict[str, Any]) -> bool:
return event["Type"] == "SNS" and "FilterPolicyScope" in event.get("Properties", {})


SERVICE_DETECTORS: Dict[str, Callable[[Dict[str, Any], Set[str]], bool]] = {
HTTP_API: lambda template_dict, cfn_resource_types: "AWS::ApiGatewayV2::Api" in cfn_resource_types,
REST_API: lambda template_dict, cfn_resource_types: "AWS::ApiGateway::RestApi" in cfn_resource_types,
Expand All @@ -225,6 +237,9 @@ def _resource_using_s3_events(resource: Dict[str, Any]) -> bool:
),
LOCATION: lambda template_dict, cfn_resource_types: "AWS::Location::PlaceIndex" in cfn_resource_types,
APP_SYNC: lambda template_dict, cfn_resource_types: "AWS::AppSync::GraphQLApi" in cfn_resource_types,
SNS_FILTER_POLICY_SCOPE: lambda template_dict, cfn_resource_types: any(
_event_using_sns_filter_policy_scope(event) for event in _get_all_event_sources(template_dict)
),
}


Expand Down