Skip to content

Commit

Permalink
adding fix for #886
Browse files Browse the repository at this point in the history
  • Loading branch information
ryandeivert committed Sep 17, 2019
1 parent 96126b0 commit 3032a79
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
5 changes: 3 additions & 2 deletions streamalert/rule_promotion/publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
class StatsPublisher:
"""Run queries to generate statistics on alerts."""

DEFAULT_STATS_SNS_TOPIC = 'staging_stats'
DEFAULT_STATS_SNS_TOPIC_SUFFIX = '{}_streamalert_rule_staging_stats'

def __init__(self, config, athena_client, current_time):
self._topic_arn = self.formatted_sns_topic_arn(config)
Expand All @@ -41,9 +41,10 @@ def formatted_sns_topic_arn(cls, config):
Return:
str: Formatted SNS topic arn using either the config option or default topic
"""
prefix = config['global']['account']['prefix']
topic = config['lambda']['rule_promotion_config'].get(
'digest_sns_topic',
cls.DEFAULT_STATS_SNS_TOPIC
cls.DEFAULT_STATS_SNS_TOPIC_SUFFIX.format(prefix)
)
return 'arn:aws:sns:{region}:{account_id}:{topic}'.format(
region=config['global']['account']['region'],
Expand Down
27 changes: 24 additions & 3 deletions tests/unit/streamalert/rule_promotion/test_publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,39 @@ def _get_fake_stats(count=2):
yield stat


def test_formatted_sns_topic_arn(self):
"""StatsPublisher - Format SNS Topic"""
def test_formatted_sns_topic_arn_default(self):
"""StatsPublisher - Format SNS Topic, Default"""
test_config = {
'global': {
'account': {
'aws_account_id': '123456789012',
'prefix': 'unit-testing',
'region': 'us-east-1'
}
},
'lambda': {
'rule_promotion_config': {} # no digest_sns_topic here
}
}
topic = self.publisher.formatted_sns_topic_arn(test_config)
assert_equal(
topic,
'arn:aws:sns:us-east-1:123456789012:unit-testing_streamalert_rule_staging_stats'
)

def test_formatted_sns_topic_arn_hard_coded(self):
"""StatsPublisher - Format SNS Topic, Hard-Coded"""
test_config = {
'global': {
'account': {
'aws_account_id': '123456789012',
'prefix': 'unit-testing',
'region': 'us-east-1'
}
},
'lambda': {
'rule_promotion_config': {
'digest_sns_topic': 'foobar'
'digest_sns_topic': 'foobar' # should use digest_sns_topic here
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def test_generate(self):
'rules_table_arn': '${module.globals.rules_table_arn}',
'source': 'modules/tf_rule_promotion_iam',
'send_digest_schedule_expression': 'cron(30 13 * * ? *)',
'digest_sns_topic': 'staging_stats',
'digest_sns_topic': 'unit-testing_streamalert_rule_staging_stats',
'athena_results_bucket_arn': '${module.stream_alert_athena.results_bucket_arn}',
'athena_data_buckets': [
'unit-testing.streamalert.data',
Expand Down

0 comments on commit 3032a79

Please sign in to comment.