Skip to content

Commit

Permalink
mailer - fix - multi emails in tag for gcp (cloud-custodian#8074)
Browse files Browse the repository at this point in the history
  • Loading branch information
thisisshi authored Dec 14, 2022
1 parent de0a322 commit 90e1623
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
8 changes: 4 additions & 4 deletions tools/c7n_mailer/c7n_mailer/email_delivery.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ def get_valid_emails_from_list(self, targets):
# gcp doesn't support the '@' character in their label values so we
# allow users to specify an email_base_url to append to the end of their
# owner contact tags
if not is_email(target) and self.config.get('email_base_url'):
target = "%s@%s" % (target, self.config['email_base_url'])
if is_email(target):
emails.append(target)
if not is_email(email) and self.config.get('email_base_url'):
full_email = "%s@%s" % (email, self.config['email_base_url'])
if is_email(full_email):
emails.append(full_email)
return emails

def get_event_owner_email(self, targets, event): # TODO: GCP-friendly
Expand Down
9 changes: 9 additions & 0 deletions tools/c7n_mailer/tests/test_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,3 +363,12 @@ def test_get_ldap_connection(self):
)
patched.assert_called()
self.assertEqual(delivery.config['ldap_bind_password'], "a password")

def test_get_valid_emails_from_list_gcp(self):
delivery = EmailDelivery(
{'ldap_uri': 'foo', 'email_base_url': 'example.com'},
self.aws_session, MagicMock())
result = delivery.get_valid_emails_from_list(['resource-owner', 'foo:bar'])
self.assertEqual(len(result), 2)
self.assertTrue('[email protected]' in result)
self.assertTrue('[email protected]' in result)

0 comments on commit 90e1623

Please sign in to comment.