Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle exception when no Slack API key was provided #34923

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions salt/states/slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
api_key: peWcBiMOS9HrZG15peWcBiMOS9HrZG15

'''
from salt.exceptions import SaltInvocationError


def __virtual__():
Expand Down Expand Up @@ -96,18 +97,18 @@ def post_message(name,
ret['comment'] = 'Slack message is missing: {0}'.format(message)
return ret

result = __salt__['slack.post_message'](
channel=channel,
message=message,
from_name=from_name,
api_key=api_key,
icon=icon,
)

if result:
try:
result = __salt__['slack.post_message'](
channel=channel,
message=message,
from_name=from_name,
api_key=api_key,
icon=icon,
)
except SaltInvocationError as sie:
ret['comment'] = 'Failed to send message: {0} ({1})'.format(name, sie)
else:
ret['result'] = True
ret['comment'] = 'Sent message: {0}'.format(name)
else:
ret['comment'] = 'Failed to send message: {0}'.format(name)

return ret