Skip to content
This repository was archived by the owner on Mar 23, 2026. It is now read-only.

Commit c2656fe

Browse files
committed
move create_default_topic_polocy
1 parent 4cb765f commit c2656fe

File tree

3 files changed

+34
-33
lines changed

3 files changed

+34
-33
lines changed

localstack-core/localstack/services/sns/provider.py

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@
120120
SnsPublishContext,
121121
)
122122
from localstack.services.sns.utils import (
123+
create_default_topic_policy,
123124
create_platform_endpoint_arn,
124125
create_subscription_arn,
125126
encode_subscription_token_with_region,
@@ -1304,7 +1305,7 @@ def _default_attributes(topic: Topic, context: RequestContext) -> TopicAttribute
13041305
default_attributes = {
13051306
"DisplayName": "",
13061307
"Owner": context.account_id,
1307-
"Policy": _create_default_topic_policy(topic["arn"]),
1308+
"Policy": create_default_topic_policy(topic["arn"]),
13081309
"SubscriptionsConfirmed": "0",
13091310
"SubscriptionsDeleted": "0",
13101311
"SubscriptionsPending": "0",
@@ -1340,36 +1341,6 @@ def _create_default_effective_delivery_policy():
13401341
)
13411342

13421343

1343-
def _create_default_topic_policy(topic_arn: str) -> str:
1344-
return json.dumps(
1345-
{
1346-
"Version": "2008-10-17",
1347-
"Id": "__default_policy_ID",
1348-
"Statement": [
1349-
{
1350-
"Effect": "Allow",
1351-
"Sid": "__default_statement_ID",
1352-
"Principal": {"AWS": "*"},
1353-
"Action": [
1354-
"SNS:GetTopicAttributes",
1355-
"SNS:SetTopicAttributes",
1356-
"SNS:AddPermission",
1357-
"SNS:RemovePermission",
1358-
"SNS:DeleteTopic",
1359-
"SNS:Subscribe",
1360-
"SNS:ListSubscriptionsByTopic",
1361-
"SNS:Publish",
1362-
],
1363-
"Resource": topic_arn,
1364-
"Condition": {
1365-
"StringEquals": {"AWS:SourceOwner": parse_arn(topic_arn)["account"]}
1366-
},
1367-
}
1368-
],
1369-
}
1370-
)
1371-
1372-
13731344
def _validate_message_attributes(
13741345
message_attributes: MessageAttributeMap, position: int | None = None
13751346
) -> None:

localstack-core/localstack/services/sns/resource_providers/aws_sns_topicpolicy.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
ResourceProvider,
1515
ResourceRequest,
1616
)
17-
from localstack.services.sns.provider import _create_default_topic_policy
17+
from localstack.services.sns.provider import create_default_topic_policy
1818

1919

2020
class SNSTopicPolicyProperties(TypedDict):
@@ -99,7 +99,7 @@ def delete(
9999
sns.set_topic_attributes(
100100
TopicArn=topic_arn,
101101
AttributeName="Policy",
102-
AttributeValue=_create_default_topic_policy(topic_arn),
102+
AttributeValue=create_default_topic_policy(topic_arn),
103103
)
104104

105105
except ClientError as err:

localstack-core/localstack/services/sns/utils.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,33 @@ def get_topic_subscriptions(store: SnsStore, topic_arn: str) -> list[SnsSubscrip
152152

153153
subscriptions = [store.subscriptions[k] for k in sub_arns if k in store.subscriptions]
154154
return subscriptions
155+
156+
157+
def create_default_topic_policy(topic_arn: str) -> str:
158+
return json.dumps(
159+
{
160+
"Version": "2008-10-17",
161+
"Id": "__default_policy_ID",
162+
"Statement": [
163+
{
164+
"Effect": "Allow",
165+
"Sid": "__default_statement_ID",
166+
"Principal": {"AWS": "*"},
167+
"Action": [
168+
"SNS:GetTopicAttributes",
169+
"SNS:SetTopicAttributes",
170+
"SNS:AddPermission",
171+
"SNS:RemovePermission",
172+
"SNS:DeleteTopic",
173+
"SNS:Subscribe",
174+
"SNS:ListSubscriptionsByTopic",
175+
"SNS:Publish",
176+
],
177+
"Resource": topic_arn,
178+
"Condition": {
179+
"StringEquals": {"AWS:SourceOwner": parse_arn(topic_arn)["account"]}
180+
},
181+
}
182+
],
183+
}
184+
)

0 commit comments

Comments
 (0)