Skip to content

Commit 719c671

Browse files
authored
Merge pull request #17 from trussworks/check-empty-strings
Everything is defaulted to empty string so check for that rather than…
2 parents d3beaed + 279221a commit 719c671

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

sleuth/sleuth/auditor.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,18 +111,18 @@ def audit():
111111
print_key_report(iam_users)
112112

113113
# lets disabled expired keys and build list of old and expired for slack
114-
if os.environ['ENABLE_AUTO_EXPIRE'] == 'true':
114+
if 'ENABLE_AUTO_EXPIRE' in os.environ and os.environ['ENABLE_AUTO_EXPIRE'] == 'true':
115115
for u in iam_users:
116116
for k in u.keys:
117117
if k.audit_state == 'expire':
118118
disable_key(k, u.username)
119119

120-
if 'SNS_TOPIC' not in os.environ and 'SLACK_URL' not in os.environ:
120+
if ('SNS_TOPIC' not in os.environ and 'SLACK_URL' not in os.environ) or (os.environ['SNS_TOPIC'] == "" and os.environ['SLACK_URL'] == ""):
121121
LOGGER.warn('No notification settings set, please set SNS_TOPIC or SLACK_URL envar!')
122122

123123
# lets assemble and send slack msg
124-
if 'SNS_TOPIC' in os.environ:
125-
if 'SNS_MESSAGE' not in os.environ:
124+
if 'SNS_TOPIC' in os.environ and os.environ['SNS_TOPIC'] != "":
125+
if 'SNS_MESSAGE' not in os.environ or os.environ['SNS_MESSAGE'] == "":
126126
LOGGER.warn('No message set for sns topic, please set SNS_MESSAGE envar!')
127127
LOGGER.info('Detected SNS setting so preparing and sending message via SNS')
128128
send_to_slack, slack_msg = prepare_sns_message(iam_users)
@@ -133,8 +133,8 @@ def audit():
133133
LOGGER.info('Nothing to report')
134134

135135

136-
if 'SLACK_URL' in os.environ:
137-
if 'SLACK_MESSAGE_TILE' not in os.environ or 'SLACK_MESSAGE_TEXT' in os.environ:
136+
if 'SLACK_URL' in os.environ and 'SLACK_URL' != "":
137+
if ('SLACK_MESSAGE_TITLE' not in os.environ or 'SLACK_MESSAGE_TEXT' not in os.environ) or (os.environ['SLACK_MESSAGE_TITLE'] == "" or os.environ['SLACK_MESSAGE_TEXT'] == ""):
138138
LOGGER.warn('No message set for slack, please set SLACK_MESSAGE_TILE and SLACK_MESSAGE_TEXT envars!')
139139
LOGGER.info('Using direct Slack API')
140140
# lets assemble the slack message

0 commit comments

Comments
 (0)