Skip to content

Commit

Permalink
Merge branch 'master' into ec2-redundant-code
Browse files Browse the repository at this point in the history
  • Loading branch information
viren-nadkarni committed May 14, 2024
2 parents 797347e + ecd113a commit e098a46
Show file tree
Hide file tree
Showing 20 changed files with 369 additions and 156 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/asf-updates.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
run: |
source .venv/bin/activate
# explicitly perform an unsafe fix to remove unused imports in the generated ASF APIs
ruff check --select F401 --unsafe-fixes --fix . --config "lint.ignore-init-module-imports = false"
ruff check --select F401 --unsafe-fixes --fix . --config "lint.preview = true"
make format-modified
- name: Check for changes
Expand Down
15 changes: 14 additions & 1 deletion localstack/aws/api/ec2/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
from datetime import datetime
from typing import List, Optional, TypedDict

from localstack.aws.api import RequestContext, ServiceRequest, handler
from localstack.aws.api import (
RequestContext,
ServiceRequest,
handler,
)
from localstack.aws.api import (
ServiceException as ServiceException,
)

AddressMaxResults = int
AllocationId = str
Expand Down Expand Up @@ -2552,6 +2559,11 @@ class PermissionGroup(str):
all = "all"


class PhcSupport(str):
unsupported = "unsupported"
supported = "supported"


class PlacementGroupState(str):
pending = "pending"
available = "available"
Expand Down Expand Up @@ -11534,6 +11546,7 @@ class InstanceTypeInfo(TypedDict, total=False):
NitroTpmInfo: Optional[NitroTpmInfo]
MediaAcceleratorInfo: Optional[MediaAcceleratorInfo]
NeuronInfo: Optional[NeuronInfo]
PhcSupport: Optional[PhcSupport]


InstanceTypeInfoList = List[InstanceTypeInfo]
Expand Down
4 changes: 4 additions & 0 deletions localstack/aws/api/sqs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@


class MessageSystemAttributeName(str):
All = "All"
SenderId = "SenderId"
SentTimestamp = "SentTimestamp"
ApproximateReceiveCount = "ApproximateReceiveCount"
Expand Down Expand Up @@ -457,6 +458,7 @@ class MessageSystemAttributeValue(TypedDict, total=False):
MessageSystemAttributeNameForSends, MessageSystemAttributeValue
]
MessageList = List[Message]
MessageSystemAttributeList = List[MessageSystemAttributeName]


class PurgeQueueRequest(ServiceRequest):
Expand All @@ -466,6 +468,7 @@ class PurgeQueueRequest(ServiceRequest):
class ReceiveMessageRequest(ServiceRequest):
QueueUrl: String
AttributeNames: Optional[AttributeNameList]
MessageSystemAttributeNames: Optional[MessageSystemAttributeList]
MessageAttributeNames: Optional[MessageAttributeNameList]
MaxNumberOfMessages: Optional[NullableInteger]
VisibilityTimeout: Optional[NullableInteger]
Expand Down Expand Up @@ -705,6 +708,7 @@ def receive_message(
context: RequestContext,
queue_url: String,
attribute_names: AttributeNameList = None,
message_system_attribute_names: MessageSystemAttributeList = None,
message_attribute_names: MessageAttributeNameList = None,
max_number_of_messages: NullableInteger = None,
visibility_timeout: NullableInteger = None,
Expand Down
19 changes: 18 additions & 1 deletion localstack/services/events/models.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
from dataclasses import dataclass, field
from typing import Optional
from typing import Optional, TypeAlias, TypedDict

from localstack.aws.api.core import ServiceException
from localstack.aws.api.events import (
Arn,
CreatedBy,
EventBusName,
EventPattern,
EventResourceList,
EventSourceName,
ManagedBy,
RoleArn,
RuleDescription,
Expand Down Expand Up @@ -102,3 +104,18 @@ class InvalidEventPatternException(Exception):
def __init__(self, reason=None, message=None) -> None:
self.reason = reason
self.message = message or f"Event pattern is not valid. Reason: {reason}"


class FormattedEvent(TypedDict):
version: str
id: str
detail_type: Optional[str] # key "detail-type" is automatically interpreted as detail_type
source: Optional[EventSourceName]
account: str
time: str
region: str
resources: Optional[EventResourceList]
detail: dict[str, str | dict]


TransformedEvent: TypeAlias = FormattedEvent | dict | str
5 changes: 3 additions & 2 deletions localstack/services/events/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
EventBus,
EventBusDict,
EventsStore,
FormattedEvent,
Rule,
RuleDict,
TargetDict,
Expand Down Expand Up @@ -125,7 +126,7 @@ def validate_event(event: PutEventsRequestEntry) -> None | PutEventsResultEntry:
}


def format_event(event: PutEventsRequestEntry, region: str, account_id: str) -> dict:
def format_event(event: PutEventsRequestEntry, region: str, account_id: str) -> FormattedEvent:
# See https://docs.aws.amazon.com/AmazonS3/latest/userguide/ev-events.html
formatted_event = {
"version": "0",
Expand Down Expand Up @@ -685,7 +686,7 @@ def _process_entries(
for target in rule.targets.values():
target_sender = self._target_sender_store[target["Arn"]]
try:
target_sender.send_event(event)
target_sender.process_event(event)
processed_entries.append({"EventId": event["id"]})
except Exception as error:
processed_entries.append(
Expand Down
19 changes: 17 additions & 2 deletions localstack/services/events/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,32 @@

from localstack.aws.api.events import (
Arn,
PutEventsRequestEntry,
Target,
TargetInputPath,
)
from localstack.aws.connect import connect_to
from localstack.services.events.models import FormattedEvent, TransformedEvent
from localstack.utils import collections
from localstack.utils.aws.arns import (
extract_service_from_arn,
firehose_name,
sqs_queue_url_for_arn,
)
from localstack.utils.aws.client_types import ServicePrincipal
from localstack.utils.json import extract_jsonpath
from localstack.utils.strings import to_bytes
from localstack.utils.time import now_utc

LOG = logging.getLogger(__name__)


def transform_event_with_target_input_path(
input_path: TargetInputPath, event: FormattedEvent
) -> TransformedEvent:
formatted_event = extract_jsonpath(event, input_path)
return formatted_event


class TargetSender(ABC):
def __init__(
self,
Expand Down Expand Up @@ -54,9 +63,15 @@ def client(self):
return self._client

@abstractmethod
def send_event(self, event: PutEventsRequestEntry):
def send_event(self, event: FormattedEvent | TransformedEvent):
pass

def process_event(self, event: FormattedEvent):
"""Processes the event and send it to the target."""
if input_path := self.target.get("InputPath"):
event = transform_event_with_target_input_path(input_path, event)
self.send_event(event)

def _validate_input(self, target: Target):
"""Provide a default implementation that does nothing if no specific validation is needed."""
# TODO add For Lambda and Amazon SNS resources, EventBridge relies on resource-based policies.
Expand Down
3 changes: 3 additions & 0 deletions localstack/services/sqs/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
MessageAttributeNameList,
MessageBodyAttributeMap,
MessageBodySystemAttributeMap,
MessageSystemAttributeList,
MessageSystemAttributeName,
NullableInteger,
PurgeQueueInProgress,
Expand Down Expand Up @@ -1183,13 +1184,15 @@ def receive_message(
context: RequestContext,
queue_url: String,
attribute_names: AttributeNameList = None,
message_system_attribute_names: MessageSystemAttributeList = None,
message_attribute_names: MessageAttributeNameList = None,
max_number_of_messages: NullableInteger = None,
visibility_timeout: NullableInteger = None,
wait_time_seconds: NullableInteger = None,
receive_request_attempt_id: String = None,
**kwargs,
) -> ReceiveMessageResult:
# TODO add support for message_system_attribute_names
queue = self._resolve_queue(context, queue_url=queue_url)

if wait_time_seconds is None:
Expand Down
8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ Issues = "https://github.com/localstack/localstack/issues"
# minimal required to actually run localstack on the host for services natively implemented in python
base-runtime = [
# pinned / updated by ASF update action
"boto3==1.34.98",
"boto3==1.34.103",
# pinned / updated by ASF update action
"botocore==1.34.98",
"botocore==1.34.103",
"awscrt>=0.13.14",
"cbor2>=5.2.0",
"dnspython>=1.16.0",
Expand All @@ -76,7 +76,7 @@ base-runtime = [
runtime = [
"localstack-core[base-runtime]",
# pinned / updated by ASF update action
"awscli==1.32.98",
"awscli==1.32.103",
"airspeed-ext>=0.6.3",
"amazon_kclpy>=2.0.6,!=2.1.0,!=2.1.4",
# antlr4-python3-runtime: exact pin because antlr4 runtime is tightly coupled to the generated parser code
Expand Down Expand Up @@ -133,7 +133,7 @@ typehint = [
# typehint is an optional extension of the dev dependencies
"localstack-core[dev]",
# pinned / updated by ASF update action
"boto3-stubs[acm,acm-pca,amplify,apigateway,apigatewayv2,appconfig,appconfigdata,application-autoscaling,appsync,athena,autoscaling,backup,batch,ce,cloudcontrol,cloudformation,cloudfront,cloudtrail,cloudwatch,codecommit,cognito-identity,cognito-idp,dms,docdb,dynamodb,dynamodbstreams,ec2,ecr,ecs,efs,eks,elasticache,elasticbeanstalk,elbv2,emr,emr-serverless,es,events,firehose,fis,glacier,glue,iam,identitystore,iot,iot-data,iotanalytics,iotwireless,kafka,kinesis,kinesisanalytics,kinesisanalyticsv2,kms,lakeformation,lambda,logs,managedblockchain,mediaconvert,mediastore,mq,mwaa,neptune,opensearch,organizations,pi,pipes,qldb,qldb-session,rds,rds-data,redshift,redshift-data,resource-groups,resourcegroupstaggingapi,route53,route53resolver,s3,s3control,sagemaker,sagemaker-runtime,secretsmanager,serverlessrepo,servicediscovery,ses,sesv2,sns,sqs,ssm,sso-admin,stepfunctions,sts,timestream-query,timestream-write,transcribe,wafv2,xray]==1.34.98",
"boto3-stubs[acm,acm-pca,amplify,apigateway,apigatewayv2,appconfig,appconfigdata,application-autoscaling,appsync,athena,autoscaling,backup,batch,ce,cloudcontrol,cloudformation,cloudfront,cloudtrail,cloudwatch,codecommit,cognito-identity,cognito-idp,dms,docdb,dynamodb,dynamodbstreams,ec2,ecr,ecs,efs,eks,elasticache,elasticbeanstalk,elbv2,emr,emr-serverless,es,events,firehose,fis,glacier,glue,iam,identitystore,iot,iot-data,iotanalytics,iotwireless,kafka,kinesis,kinesisanalytics,kinesisanalyticsv2,kms,lakeformation,lambda,logs,managedblockchain,mediaconvert,mediastore,mq,mwaa,neptune,opensearch,organizations,pi,pipes,qldb,qldb-session,rds,rds-data,redshift,redshift-data,resource-groups,resourcegroupstaggingapi,route53,route53resolver,s3,s3control,sagemaker,sagemaker-runtime,secretsmanager,serverlessrepo,servicediscovery,ses,sesv2,sns,sqs,ssm,sso-admin,stepfunctions,sts,timestream-query,timestream-write,transcribe,wafv2,xray]==1.34.103",
]

[tool.setuptools]
Expand Down
4 changes: 2 additions & 2 deletions requirements-base-runtime.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ blinker==1.8.2
# via
# flask
# quart
boto3==1.34.98
boto3==1.34.103
# via localstack-core (pyproject.toml)
botocore==1.34.98
botocore==1.34.103
# via
# boto3
# localstack-core (pyproject.toml)
Expand Down
12 changes: 6 additions & 6 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ aws-sam-translator==1.88.0
# localstack-core
aws-xray-sdk==2.13.0
# via moto-ext
awscli==1.32.98
awscli==1.32.103
# via localstack-core
awscrt==0.20.9
# via localstack-core
Expand All @@ -55,12 +55,12 @@ blinker==1.8.2
# quart
boto==2.49.0
# via amazon-kclpy
boto3==1.34.98
boto3==1.34.103
# via
# aws-sam-translator
# localstack-core
# moto-ext
botocore==1.34.98
botocore==1.34.103
# via
# aws-xray-sdk
# awscli
Expand Down Expand Up @@ -214,7 +214,7 @@ jmespath==1.0.1
# via
# boto3
# botocore
joserfc==0.9.0
joserfc==0.10.0
# via moto-ext
jpype1==1.5.0
# via localstack-core
Expand Down Expand Up @@ -329,7 +329,7 @@ ply==3.11
# jsonpath-ng
# jsonpath-rw
# pandoc
pre-commit==3.7.0
pre-commit==3.7.1
# via localstack-core (pyproject.toml)
priority==1.3.0
# via
Expand Down Expand Up @@ -509,7 +509,7 @@ urllib3==2.2.1
# opensearch-py
# requests
# responses
virtualenv==20.26.1
virtualenv==20.26.2
# via pre-commit
websocket-client==1.8.0
# via
Expand Down
8 changes: 4 additions & 4 deletions requirements-runtime.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ aws-sam-translator==1.88.0
# localstack-core (pyproject.toml)
aws-xray-sdk==2.13.0
# via moto-ext
awscli==1.32.98
awscli==1.32.103
# via localstack-core (pyproject.toml)
awscrt==0.20.9
# via localstack-core
Expand All @@ -43,12 +43,12 @@ blinker==1.8.2
# quart
boto==2.49.0
# via amazon-kclpy
boto3==1.34.98
boto3==1.34.103
# via
# aws-sam-translator
# localstack-core
# moto-ext
botocore==1.34.98
botocore==1.34.103
# via
# aws-xray-sdk
# awscli
Expand Down Expand Up @@ -161,7 +161,7 @@ jmespath==1.0.1
# via
# boto3
# botocore
joserfc==0.9.0
joserfc==0.10.0
# via moto-ext
jpype1==1.5.0
# via localstack-core (pyproject.toml)
Expand Down
8 changes: 4 additions & 4 deletions requirements-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ aws-sam-translator==1.88.0
# localstack-core
aws-xray-sdk==2.13.0
# via moto-ext
awscli==1.32.98
awscli==1.32.103
# via localstack-core
awscrt==0.20.9
# via localstack-core
Expand All @@ -55,12 +55,12 @@ blinker==1.8.2
# quart
boto==2.49.0
# via amazon-kclpy
boto3==1.34.98
boto3==1.34.103
# via
# aws-sam-translator
# localstack-core
# moto-ext
botocore==1.34.98
botocore==1.34.103
# via
# aws-xray-sdk
# awscli
Expand Down Expand Up @@ -198,7 +198,7 @@ jmespath==1.0.1
# via
# boto3
# botocore
joserfc==0.9.0
joserfc==0.10.0
# via moto-ext
jpype1==1.5.0
# via localstack-core
Expand Down
Loading

0 comments on commit e098a46

Please sign in to comment.