Skip to content
Merged
Show file tree
Hide file tree
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
fix(slack): channel api deprecated
Slack api https://slack.com/api/channels.* is deprecated see:
https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api
All new slack apps created after June 10th, 2020 will give error, which
creates issue for on premise sentry.

This commit fixes the issue by adding `slack.legacy-app=(true/false)`
config so that it continues support for legacy slack apps while new apps
can toggle this option for new slack API support

Resolves: #7897
  • Loading branch information
dcshiman committed Jun 18, 2020
commit 718f2826fa9c7e4c86146994eb75ecfce8b0ed9b
12 changes: 10 additions & 2 deletions src/sentry/integrations/slack/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from django.core.urlresolvers import reverse

from sentry import tagstore
from sentry import options
from sentry.api.fields.actor import Actor
from sentry.incidents.logic import get_incident_aggregates
from sentry.incidents.models import IncidentStatus, IncidentTrigger
Expand Down Expand Up @@ -373,11 +374,12 @@ def build_incident_attachment(incident, metric_value=None):

# Different list types in slack that we'll use to resolve a channel name. Format is
# (<list_name>, <result_name>, <prefix>).
LIST_TYPES = [
LEGACY_LIST_TYPES = [
("channels", "channels", CHANNEL_PREFIX),
("groups", "groups", CHANNEL_PREFIX),
("users", "members", MEMBER_PREFIX),
]
LIST_TYPES = [("conversations", "channels", CHANNEL_PREFIX), ("users", "members", MEMBER_PREFIX)]


def strip_channel_name(name):
Expand Down Expand Up @@ -418,12 +420,18 @@ def get_channel_id_with_timeout(integration, name, timeout):
# Look for channel ID
payload = dict(token_payload, **{"exclude_archived": False, "exclude_members": True})

if options.get("slack.legacy-app") is True:
list_types = LEGACY_LIST_TYPES
else:
list_types = LIST_TYPES
payload = dict(payload, **{"types": "public_channel,private_channel"})

time_to_quit = time.time() + timeout

client = SlackClient()
id_data = None
found_duplicate = False
for list_type, result_name, prefix in LIST_TYPES:
for list_type, result_name, prefix in list_types:
cursor = ""
while True:
endpoint = "/%s.list" % list_type
Expand Down
1 change: 1 addition & 0 deletions src/sentry/options/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
register("slack.client-secret", flags=FLAG_PRIORITIZE_DISK)
register("slack.verification-token", flags=FLAG_PRIORITIZE_DISK)
register("slack.signing-secret", flags=FLAG_PRIORITIZE_DISK)
register("slack.legacy-app", flags=FLAG_PRIORITIZE_DISK, type=Bool, default=True)

# Slack V2 Integration
register("slack-v2.client-id", flags=FLAG_PRIORITIZE_DISK)
Expand Down
1 change: 1 addition & 0 deletions src/sentry/utils/pytest/sentry.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ def pytest_configure(config):
"slack.client-id": "slack-client-id",
"slack.client-secret": "slack-client-secret",
"slack.verification-token": "slack-verification-token",
"slack.legacy-app": True,
"github-app.name": "sentry-test-app",
"github-app.client-id": "github-client-id",
"github-app.client-secret": "github-client-secret",
Expand Down