Skip to content

Commit 722d022

Browse files
bentskusimonrw
authored andcommitted
Events: add classmethod to recreate services (#12566)
1 parent 13b7400 commit 722d022

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

localstack-core/localstack/services/events/api_destination.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,23 @@ def __init__(
6464
description,
6565
)
6666

67+
@classmethod
68+
def restore_from_api_destination_and_connection(
69+
cls, api_destination: ApiDestination, connection: Connection
70+
):
71+
api_destination_service = cls(
72+
name=api_destination.name,
73+
region=api_destination.region,
74+
account_id=api_destination.account_id,
75+
connection_arn=api_destination.connection_arn,
76+
connection=connection,
77+
invocation_endpoint=api_destination.invocation_endpoint,
78+
http_method=api_destination.http_method,
79+
invocation_rate_limit_per_second=api_destination.invocation_rate_limit_per_second,
80+
)
81+
api_destination_service.api_destination = api_destination
82+
return api_destination_service
83+
6784
@property
6885
def arn(self) -> Arn:
6986
return self.api_destination.arn

localstack-core/localstack/services/events/connection.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,16 @@ def __init__(
3232
auth_parameters: CreateConnectionAuthRequestParameters,
3333
description: ConnectionDescription | None = None,
3434
invocation_connectivity_parameters: ConnectivityResourceParameters | None = None,
35+
create_secret: bool = True,
3536
):
3637
self._validate_input(name, authorization_type)
3738
state = self._get_initial_state(authorization_type)
38-
secret_arn = self.create_connection_secret(
39-
region, account_id, name, authorization_type, auth_parameters
40-
)
39+
40+
secret_arn = None
41+
if create_secret:
42+
secret_arn = self.create_connection_secret(
43+
region, account_id, name, authorization_type, auth_parameters
44+
)
4145
public_auth_parameters = self._get_public_parameters(authorization_type, auth_parameters)
4246

4347
self.connection = Connection(
@@ -52,6 +56,19 @@ def __init__(
5256
invocation_connectivity_parameters,
5357
)
5458

59+
@classmethod
60+
def restore_from_connection(cls, connection: Connection):
61+
connection_service = cls(
62+
connection.name,
63+
connection.region,
64+
connection.account_id,
65+
connection.authorization_type,
66+
connection.auth_parameters,
67+
create_secret=False,
68+
)
69+
connection_service.connection = connection
70+
return connection_service
71+
5572
@property
5673
def arn(self) -> Arn:
5774
return self.connection.arn

0 commit comments

Comments
 (0)