Skip to content

Events: add classmethod to recreate services #12566

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 3 commits into from
May 6, 2025
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
17 changes: 17 additions & 0 deletions localstack-core/localstack/services/events/api_destination.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,23 @@ def __init__(
description,
)

@classmethod
def restore_from_api_destination_and_connection(
cls, api_destination: ApiDestination, connection: Connection
):
api_destination_service = cls(
name=api_destination.name,
region=api_destination.region,
account_id=api_destination.account_id,
connection_arn=api_destination.connection_arn,
connection=connection,
invocation_endpoint=api_destination.invocation_endpoint,
http_method=api_destination.http_method,
invocation_rate_limit_per_second=api_destination.invocation_rate_limit_per_second,
)
api_destination_service.api_destination = api_destination
return api_destination_service

@property
def arn(self) -> Arn:
return self.api_destination.arn
Expand Down
23 changes: 20 additions & 3 deletions localstack-core/localstack/services/events/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,16 @@ def __init__(
auth_parameters: CreateConnectionAuthRequestParameters,
description: ConnectionDescription | None = None,
invocation_connectivity_parameters: ConnectivityResourceParameters | None = None,
create_secret: bool = True,
):
self._validate_input(name, authorization_type)
state = self._get_initial_state(authorization_type)
secret_arn = self.create_connection_secret(
region, account_id, name, authorization_type, auth_parameters
)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very nice way to decouple secret creation from api connection creation

secret_arn = None
if create_secret:
secret_arn = self.create_connection_secret(
region, account_id, name, authorization_type, auth_parameters
)
public_auth_parameters = self._get_public_parameters(authorization_type, auth_parameters)

self.connection = Connection(
Expand All @@ -52,6 +56,19 @@ def __init__(
invocation_connectivity_parameters,
)

@classmethod
def restore_from_connection(cls, connection: Connection):
connection_service = cls(
connection.name,
connection.region,
connection.account_id,
connection.authorization_type,
connection.auth_parameters,
create_secret=False,
)
connection_service.connection = connection
return connection_service

@property
def arn(self) -> Arn:
return self.connection.arn
Expand Down
Loading