Skip to content

Commit 43ad71b

Browse files
authored
SES: add ARN utility for SES identity (#12513)
1 parent ab2d6a4 commit 43ad71b

File tree

3 files changed

+34
-24
lines changed

3 files changed

+34
-24
lines changed

localstack-core/localstack/testing/pytest/fixtures.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1973,6 +1973,30 @@ def factory(email_address: str) -> None:
19731973
aws_client.ses.delete_identity(Identity=identity)
19741974

19751975

1976+
@pytest.fixture
1977+
def setup_sender_email_address(ses_verify_identity):
1978+
"""
1979+
If the test is running against AWS then assume the email address passed is already
1980+
verified, and passes the given email address through. Otherwise, it generates one random
1981+
email address and verify them.
1982+
"""
1983+
1984+
def inner(sender_email_address: Optional[str] = None) -> str:
1985+
if is_aws_cloud():
1986+
if sender_email_address is None:
1987+
raise ValueError(
1988+
"sender_email_address must be specified to run this test against AWS"
1989+
)
1990+
else:
1991+
# overwrite the given parameters with localstack specific ones
1992+
sender_email_address = f"sender-{short_uid()}@example.com"
1993+
ses_verify_identity(sender_email_address)
1994+
1995+
return sender_email_address
1996+
1997+
return inner
1998+
1999+
19762000
@pytest.fixture
19772001
def ec2_create_security_group(aws_client):
19782002
ec2_sgs = []

localstack-core/localstack/utils/aws/arns.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,16 @@ def route53_resolver_query_log_config_arn(id: str, account_id: str, region_name:
524524
return _resource_arn(id, pattern, account_id=account_id, region_name=region_name)
525525

526526

527+
#
528+
# SES
529+
#
530+
531+
532+
def ses_identity_arn(email: str, account_id: str, region_name: str) -> str:
533+
pattern = "arn:%s:ses:%s:%s:identity/%s"
534+
return _resource_arn(email, pattern, account_id=account_id, region_name=region_name)
535+
536+
527537
#
528538
# Other ARN related helpers
529539
#

tests/aws/services/ses/test_ses.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -116,30 +116,6 @@ def inner(
116116
return inner
117117

118118

119-
@pytest.fixture
120-
def setup_sender_email_address(ses_verify_identity):
121-
"""
122-
If the test is running against AWS then assume the email address passed is already
123-
verified, and passes the given email address through. Otherwise, it generates one random
124-
email address and verify them.
125-
"""
126-
127-
def inner(sender_email_address: Optional[str] = None) -> str:
128-
if is_aws_cloud():
129-
if sender_email_address is None:
130-
raise ValueError(
131-
"sender_email_address must be specified to run this test against AWS"
132-
)
133-
else:
134-
# overwrite the given parameters with localstack specific ones
135-
sender_email_address = f"sender-{short_uid()}@example.com"
136-
ses_verify_identity(sender_email_address)
137-
138-
return sender_email_address
139-
140-
return inner
141-
142-
143119
@pytest.fixture
144120
def add_snapshot_transformer_for_sns_event(snapshot):
145121
def _inner(sender_email, recipient_email, config_set_name):

0 commit comments

Comments
 (0)