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

Prepare OnCall for Unified Slack App #4232

Merged
merged 65 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
6ee54a4
Add chatops-proxy routing data to AlertGroup Buttons
Konstantinov-Innokentii Apr 9, 2024
3a699c4
Make "Responders" button work
Konstantinov-Innokentii Apr 10, 2024
9581552
Make "Attach to" work
Konstantinov-Innokentii Apr 11, 2024
8bd9ef3
Make "Resolution notes" btn work
Konstantinov-Innokentii Apr 11, 2024
2dda654
Start work on the slack installation from the chatops-proxy
Konstantinov-Innokentii Apr 16, 2024
b187082
Support slack installation via chatops-proxy.
Konstantinov-Innokentii Apr 24, 2024
c97a994
Fix get_installation_link_from_chatops_proxy util
Konstantinov-Innokentii Apr 24, 2024
97d140a
Add SELF_HOSTED_STACK_ID env var
Konstantinov-Innokentii Apr 26, 2024
7103c5c
draft event receiver
Konstantinov-Innokentii Apr 26, 2024
0131c47
Merge branch 'slack_add_tenant_id' into handle_chatops_proxy_broadcast
Konstantinov-Innokentii Apr 29, 2024
4cf952c
Reorganize chatops-event handler
Konstantinov-Innokentii Apr 29, 2024
5cf0bb7
Fix types
Konstantinov-Innokentii Apr 29, 2024
0215e8c
Fixes
Konstantinov-Innokentii Apr 29, 2024
70f0e53
Move common.oncall_gateway to apps.chatops-proxy
Konstantinov-Innokentii Apr 30, 2024
62204f2
Introduce UNIFIED_SLACK_APP_ENABLED env var
Konstantinov-Innokentii Apr 30, 2024
ed0f6de
Fix registering oncall tenant
Konstantinov-Innokentii Apr 30, 2024
58b8376
Add api/v3/slack urls
Konstantinov-Innokentii May 3, 2024
616e6e9
fix get_installation_link_from_chatops_proxy
vadimkerr May 3, 2024
ee58525
fix AcceptShiftSwapRequestStep
vadimkerr May 10, 2024
f051bad
fix AcknowledgeConfirmationStep
vadimkerr May 10, 2024
281b419
fix EditScheduleShiftNotifyStep
vadimkerr May 10, 2024
a20fabd
fix UpdateAppearanceStep
vadimkerr May 10, 2024
c9b9abe
fix OnPagingChange steps
vadimkerr May 10, 2024
25bf434
fix OnPagingItemActionChange
vadimkerr May 10, 2024
6a8c33b
fix FinishDirectPaging
vadimkerr May 10, 2024
9fba9f6
Merge branch 'dev' into handle_chatops_proxy_broadcast
vadimkerr May 10, 2024
d126d03
fix responders tests
vadimkerr May 10, 2024
9c440e2
fix tests
vadimkerr May 10, 2024
cd9f325
simplify
vadimkerr May 10, 2024
0b9c414
remove user.organization
vadimkerr May 10, 2024
61cbbd2
add celery routes
vadimkerr May 10, 2024
b1df185
fix mypy
vadimkerr May 10, 2024
d99a046
fix mypy
vadimkerr May 10, 2024
ee4439f
Install slack from chatops-proxy
Konstantinov-Innokentii May 15, 2024
5d2f566
removed otel, added makeRequestRaw to return actual response, check s…
teodosii May 16, 2024
0abc787
check for 200
teodosii May 16, 2024
9235ede
lint
teodosii May 16, 2024
b265b59
Remove change which makes no sense
Konstantinov-Innokentii May 20, 2024
779c352
Add bunch of comments
Konstantinov-Innokentii May 20, 2024
56ce18d
Better comment for ChatopsEventsHandler
Konstantinov-Innokentii May 20, 2024
408b751
Better logging for Chatops events
Konstantinov-Innokentii May 20, 2024
4df9f69
Merge branch 'refs/heads/dev' into handle_chatops_proxy_broadcast
Konstantinov-Innokentii May 20, 2024
6d2edc7
Bump kindest/node image
Konstantinov-Innokentii May 20, 2024
8073e3d
Fix integration tests
Konstantinov-Innokentii May 20, 2024
252b268
Merge remote-tracking branch 'refs/remotes/origin/rares/support-slack…
Konstantinov-Innokentii May 21, 2024
1fa0469
Bring back unlink_slack if UNIFIED SLACK APP isn't enabled
Konstantinov-Innokentii May 21, 2024
52e8771
Rename OauthInstallation to OAuthInstallation
Konstantinov-Innokentii May 23, 2024
ae2eeca
Add logging if there is no handler for chatops-event
Konstantinov-Innokentii May 23, 2024
8ddd8a1
Remove outdated comment
Konstantinov-Innokentii May 23, 2024
b2ddd02
Add tests for ChatopsEventsView
Konstantinov-Innokentii May 23, 2024
a650357
Fix test_event_handler
Konstantinov-Innokentii May 23, 2024
e717174
Add tests for SlackInstallationHandler
Konstantinov-Innokentii May 23, 2024
9d8b129
Add tests for install_slack_integration
Konstantinov-Innokentii May 23, 2024
a5eb5fd
Add tests for uninstall_slack_integration
Konstantinov-Innokentii May 23, 2024
3afcb4f
Simplify test_root_event_handler
Konstantinov-Innokentii May 24, 2024
705e117
Correct test data
Konstantinov-Innokentii May 24, 2024
bede2ad
Merge branch 'dev' into handle_chatops_proxy_broadcast
teodosii May 24, 2024
89a3c0c
Add tests for start slack installation via social auth
Konstantinov-Innokentii May 24, 2024
f3a951d
lint
teodosii May 24, 2024
e3dd665
Merge branch 'handle_chatops_proxy_broadcast' of https://github.com/g…
teodosii May 24, 2024
82f3695
Merge branch 'dev' into handle_chatops_proxy_broadcast
Konstantinov-Innokentii May 24, 2024
6e6e120
Merge branch 'dev' into handle_chatops_proxy_broadcast
Konstantinov-Innokentii May 27, 2024
8811757
Merge branch 'dev' into handle_chatops_proxy_broadcast
Konstantinov-Innokentii May 29, 2024
8d438a3
Verify chatops-proxy events signature
Konstantinov-Innokentii Jun 3, 2024
aae84ab
Merge branch 'dev' into handle_chatops_proxy_broadcast
Konstantinov-Innokentii Jun 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Empty file.
7 changes: 7 additions & 0 deletions engine/apps/chatops_proxy/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from common.api_helpers.optional_slash_router import optional_slash_path

from .views import ReceiveBroadcast

urlpatterns = [
optional_slash_path("broadcast", ReceiveBroadcast.as_view()),
]
8 changes: 8 additions & 0 deletions engine/apps/chatops_proxy/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from rest_framework.response import Response
from rest_framework.views import APIView


class ReceiveBroadcast(APIView):
def post(self, request):
print(request.data)
return Response(status=200)
19 changes: 19 additions & 0 deletions engine/apps/slack/oauth.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from django.conf import settings
from django.shortcuts import redirect
from rest_framework.response import Response
from rest_framework.views import APIView

from common.oncall_gateway.client import ChatopsProxyAPIClient


class OauthStartView(APIView):
def get(self, request):
client = ChatopsProxyAPIClient(settings.ONCALL_GATEWAY_URL, settings.ONCALL_GATEWAY_API_TOKEN)

try:
link, _ = client.get_slack_oauth_link(
request.auth.organization.stack_id, request.auth.user.user_id, request.auth.organization.web_link
)
return redirect(link)
except Exception as e:
return Response({"error": str(e)}, status=500)
Fixed Show fixed Hide fixed
6 changes: 5 additions & 1 deletion engine/apps/social_auth/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@ class SlackOAuth2V2(SlackOAuth2):

@handle_http_errors
def auth_complete(self, *args, **kwargs):
"""Completes login process, must return user instance"""
"""
Override original method to include auth token in redirect uri and adjust response shape to slack Oauth2.0 V2.
Access token is in the ["authed_user"]["access_token"] field, not in the root of the response.
"""
self.process_error(self.data)
state = self.validate_state()
# add auth token to redirect uri, because it must be the same in all slack auth requests
Expand All @@ -113,6 +116,7 @@ def auth_complete(self, *args, **kwargs):
method=self.ACCESS_TOKEN_METHOD,
)
self.process_error(response)
# Take access token from the authed_user field, not from the root
access_token = response["authed_user"]["access_token"]
kwargs.update(response=response)
return self.do_auth(access_token, *args, **kwargs)
Expand Down
9 changes: 9 additions & 0 deletions engine/common/oncall_gateway/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,15 @@ def unlink_slack_team(
self._check_response(response)
return response.json()["removed"], response

def get_slack_oauth_link(
self, stack_id: int, grafana_user_id: int, app_redirect: str
) -> tuple[str, requests.models.Response]:
url = f"{self.api_base_url}/api/v3/oauth2/start"
d = {"stack_id": stack_id, "grafana_user_id": grafana_user_id, "app_redirect": app_redirect}
response = requests.post(url=url, json=d, headers=self._headers)
self._check_response(response)
return response.json()["install_link"], response

def _check_response(self, response: requests.models.Response):
"""
Wraps an exceptional response to ChatopsProxyAPIException
Expand Down
5 changes: 5 additions & 0 deletions engine/engine/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,8 @@
path("internal/schema/", SpectacularYAMLAPIView.as_view(api_version="internal/v1"), name="schema"),
path("internal/schema/swagger-ui/", SpectacularSwaggerView.as_view(url_name="schema"), name="swagger-ui"),
]

if settings.FEATURE_MULTIREGION_ENABLED:
urlpatterns += [
path("api/chatops/", include("apps.chatops_proxy.urls")),
]
1 change: 1 addition & 0 deletions engine/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ class DatabaseTypes:
"apps.phone_notifications",
"drf_spectacular",
"apps.google",
"apps.chatops_proxy",
]

REST_FRAMEWORK = {
Expand Down