Skip to content

Commit

Permalink
fix the issue when empty ignore rules input being parsed to empty str…
Browse files Browse the repository at this point in the history
…ing rule that fails parsing

Signed-off-by: Andrey Devyatkin <andrey.devyatkin@fivexl.io>
  • Loading branch information
Andrey9kin committed Dec 2, 2021
1 parent 5a85149 commit 2fa9424
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ def get_hook_url_for_account(event, configuration, default_hook_url):
def lambda_handler(event, context):

default_hook_url = read_env_variable_or_die('HOOK_URL')
user_rules = os.environ.get('RULES', None)
ignore_rules = os.environ.get('IGNORE_RULES', "").split(",")
user_rules = parse_rules_from_string(os.environ.get('RULES', ''))
ignore_rules = parse_rules_from_string(os.environ.get('IGNORE_RULES', ''))
use_default_rules = os.environ.get('USE_DEFAULT_RULES', None)
events_to_track = os.environ.get('EVENTS_TO_TRACK', None)
configuration = os.environ.get('CONFIGURATION', None)
Expand All @@ -108,8 +108,7 @@ def lambda_handler(event, context):
if use_default_rules:
rules += default_rules
if user_rules:
rules_list = user_rules.split(",")
rules += rules_list
rules += user_rules
if events_to_track:
events_list = events_to_track.replace(" ", "").split(",")
rules.append(f'"eventName" in event and event["eventName"] in {json.dumps(events_list)}')
Expand Down Expand Up @@ -187,6 +186,13 @@ def flatten(x, name=''):
return out


# Parse rules from string
def parse_rules_from_string(rules_as_string):
rules_as_list = rules_as_string.split(',')
# make sure there are no empty strings in the list
return [x for x in rules_as_list if x]


# Format message
def event_to_slack_message(event, source_file):

Expand Down

0 comments on commit 2fa9424

Please sign in to comment.