From 718f2826fa9c7e4c86146994eb75ecfce8b0ed9b Mon Sep 17 00:00:00 2001 From: DC Shiman Date: Thu, 18 Jun 2020 14:49:18 +0800 Subject: [PATCH] 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 --- src/sentry/integrations/slack/utils.py | 12 ++++++++++-- src/sentry/options/defaults.py | 1 + src/sentry/utils/pytest/sentry.py | 1 + 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/sentry/integrations/slack/utils.py b/src/sentry/integrations/slack/utils.py index 80966a0f3890c8..2505f7a0bb02e4 100644 --- a/src/sentry/integrations/slack/utils.py +++ b/src/sentry/integrations/slack/utils.py @@ -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 @@ -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_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): @@ -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 diff --git a/src/sentry/options/defaults.py b/src/sentry/options/defaults.py index 0df80c8ab36f4a..7fc7af80caf9df 100644 --- a/src/sentry/options/defaults.py +++ b/src/sentry/options/defaults.py @@ -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) diff --git a/src/sentry/utils/pytest/sentry.py b/src/sentry/utils/pytest/sentry.py index a5a916efc58e9d..e82ed21482b7e4 100644 --- a/src/sentry/utils/pytest/sentry.py +++ b/src/sentry/utils/pytest/sentry.py @@ -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",