Skip to content

Commit

Permalink
fix(slack): channel api deprecated (#19446)
Browse files Browse the repository at this point in the history
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 authored Jun 19, 2020
1 parent 0fc6049 commit cc9f7d1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
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

0 comments on commit cc9f7d1

Please sign in to comment.