Skip to content

Commit

Permalink
no longer double-encoding event pattern json for cloudtrail config (a…
Browse files Browse the repository at this point in the history
  • Loading branch information
ryandeivert authored Jun 20, 2018
1 parent 044f19e commit 68d063b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
9 changes: 2 additions & 7 deletions stream_alert_cli/terraform/cloudtrail.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,8 @@ def generate_cloudtrail(cluster_name, cluster_dict, config):
is_global_trail = modules['cloudtrail'].get('is_global_trail', True)
region = config['global']['account']['region']

event_pattern_default = json.dumps({'account': [config['global']['account']['aws_account_id']]})
try:
event_pattern = json.loads(modules['cloudtrail'].get('event_pattern',
event_pattern_default))
except ValueError:
LOGGER_CLI.error('Event Pattern is not valid JSON')
return False
event_pattern_default = {'account': [config['global']['account']['aws_account_id']]}
event_pattern = modules['cloudtrail'].get('event_pattern', event_pattern_default)

# From here: http://amzn.to/2zF7CS0
valid_event_pattern_keys = {
Expand Down
10 changes: 4 additions & 6 deletions tests/unit/stream_alert_cli/terraform/test_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
See the License for the specific language governing permissions and
limitations under the License.
"""
import json

from stream_alert_cli.config import CLIConfig
from stream_alert_cli.terraform import (
common,
Expand Down Expand Up @@ -327,13 +325,13 @@ def test_generate_cloudtrail_all_options(self):
'enable_kinesis': True,
'existing_trail': False,
'is_global_trail': False,
'event_pattern': json.dumps({
'event_pattern': {
'source': ['aws.ec2'],
'account': '12345678910',
'detail': {
'state': ['running']
}
})
}
}
cloudtrail.generate_cloudtrail(
cluster_name,
Expand Down Expand Up @@ -369,9 +367,9 @@ def test_generate_cloudtrail_invalid_event_pattern(self, mock_logging):
'enable_kinesis': True,
'existing_trail': False,
'is_global_trail': False,
'event_pattern': json.dumps({
'event_pattern': {
'invalid': ['aws.ec2']
})
}
}
result = cloudtrail.generate_cloudtrail(cluster_name, self.cluster_dict, self.config)
assert_false(result)
Expand Down

0 comments on commit 68d063b

Please sign in to comment.