-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
feat(integrations): Add API driven pipeline for Slack #112315
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ | |
| from slack_sdk.errors import SlackApiError | ||
|
|
||
| from sentry.identity.pipeline import IdentityPipeline | ||
| from sentry.identity.slack.provider import SlackIdentityProvider | ||
| from sentry.integrations.base import ( | ||
| FeatureDescription, | ||
| IntegrationData, | ||
|
|
@@ -36,7 +37,7 @@ | |
| ) | ||
| from sentry.notifications.platform.target import IntegrationNotificationTarget | ||
| from sentry.organizations.services.organization.model import RpcOrganization | ||
| from sentry.pipeline.views.base import PipelineView | ||
| from sentry.pipeline.views.base import ApiPipelineSteps, PipelineView | ||
| from sentry.pipeline.views.nested import NestedPipelineView | ||
| from sentry.shared_integrations.exceptions import IntegrationError | ||
| from sentry.utils.http import absolute_uri | ||
|
|
@@ -322,6 +323,7 @@ def _get_oauth_scopes(self) -> frozenset[str]: | |
| return self.identity_oauth_scopes | ||
|
|
||
| setup_dialog_config = {"width": 600, "height": 900} | ||
| setup_url_path = "/extensions/slack/setup/" | ||
|
|
||
| def _identity_pipeline_view(self) -> PipelineView[IntegrationPipeline]: | ||
| return NestedPipelineView( | ||
|
|
@@ -331,13 +333,28 @@ def _identity_pipeline_view(self) -> PipelineView[IntegrationPipeline]: | |
| config={ | ||
| "oauth_scopes": self._get_oauth_scopes(), | ||
| "user_scopes": self.user_scopes, | ||
| "redirect_url": absolute_uri("/extensions/slack/setup/"), | ||
| "redirect_url": absolute_uri(self.setup_url_path), | ||
| }, | ||
| ) | ||
|
|
||
| def get_pipeline_views(self) -> Sequence[PipelineView[IntegrationPipeline]]: | ||
| return [self._identity_pipeline_view()] | ||
|
|
||
| def _make_identity_provider(self) -> SlackIdentityProvider: | ||
| return SlackIdentityProvider( | ||
| oauth_scopes=self._get_oauth_scopes(), | ||
| redirect_url=absolute_uri(self.setup_url_path), | ||
| ) | ||
|
|
||
| def get_pipeline_api_steps(self) -> ApiPipelineSteps[IntegrationPipeline]: | ||
| provider = self._make_identity_provider() | ||
| return [ | ||
| provider.make_oauth_api_step( | ||
| bind_key="oauth_data", | ||
| extra_authorize_params={"user_scope": " ".join(self.user_scopes)}, | ||
| ), | ||
| ] | ||
|
cursor[bot] marked this conversation as resolved.
|
||
|
|
||
| def _get_team_info(self, access_token: str) -> Any: | ||
| # Manually add authorization since this method is part of slack installation | ||
|
|
||
|
|
@@ -352,7 +369,13 @@ def _get_team_info(self, access_token: str) -> Any: | |
| raise IntegrationError("Could not retrieve Slack team information.") | ||
|
|
||
| def build_integration(self, state: Mapping[str, Any]) -> IntegrationData: | ||
| data = state["identity"]["data"] | ||
| # TODO: legacy views write token data to state["identity"]["data"] via | ||
| # NestedPipelineView. API steps write directly to state["oauth_data"]. | ||
| # Remove the legacy path once the old views are retired. | ||
| if "oauth_data" in state: | ||
| data = state["oauth_data"] | ||
| else: | ||
| data = state["identity"]["data"] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Slack API errors bypass validation causing unhandled assertionMedium Severity The new API pipeline path for Slack integration setup doesn't validate Slack's OAuth response body for application-level errors. Slack's Reviewed by Cursor Bugbot for commit 647c4e0. Configure here. |
||
| assert data["ok"] | ||
|
|
||
| access_token = data["access_token"] | ||
|
|
||


Uh oh!
There was an error while loading. Please reload this page.