Skip to content

Commit

Permalink
Add missing app_type argument to uninstall request (#4700)
Browse files Browse the repository at this point in the history
  • Loading branch information
Konstantinov-Innokentii authored Jul 18, 2024
1 parent 4e03732 commit dd84aa1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
8 changes: 3 additions & 5 deletions engine/apps/chatops_proxy/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import requests
from django.conf import settings

SERVICE_TYPE_ONCALL = "oncall"
APP_TYPE_ONCALL = "oncall"
PROVIDER_TYPE_SLACK = "slack"


Expand Down Expand Up @@ -172,16 +172,14 @@ def get_oauth_installation(
return OAuthInstallation(**response.json()["oauth_installation"]), response

def delete_oauth_installation(
self,
stack_id: int,
provider_type: str,
grafana_user_id: int,
self, stack_id: int, provider_type: str, grafana_user_id: int, app_type: str
) -> tuple[bool, requests.models.Response]:
url = f"{self.api_base_url}/oauth_installations/uninstall"
d = {
"stack_id": stack_id,
"provider_type": provider_type,
"grafana_user_id": grafana_user_id,
"app_type": app_type,
}
response = requests.post(url=url, json=d, headers=self._headers)
self._check_response(response)
Expand Down
4 changes: 2 additions & 2 deletions engine/apps/chatops_proxy/register_oncall_tenant.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# register_oncall_tenant moved to separate file from engine/apps/chatops_proxy/utils.py to avoid circular imports.
from django.conf import settings

from apps.chatops_proxy.client import SERVICE_TYPE_ONCALL, ChatopsProxyAPIClient
from apps.chatops_proxy.client import APP_TYPE_ONCALL, ChatopsProxyAPIClient


def register_oncall_tenant(org):
Expand All @@ -12,7 +12,7 @@ def register_oncall_tenant(org):
client.register_tenant(
str(org.uuid),
settings.ONCALL_BACKEND_REGION,
SERVICE_TYPE_ONCALL,
APP_TYPE_ONCALL,
org.stack_id,
org.stack_slug,
)
20 changes: 11 additions & 9 deletions engine/apps/chatops_proxy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from django.conf import settings

from .client import PROVIDER_TYPE_SLACK, SERVICE_TYPE_ONCALL, ChatopsProxyAPIClient, ChatopsProxyAPIException
from .client import APP_TYPE_ONCALL, PROVIDER_TYPE_SLACK, ChatopsProxyAPIClient, ChatopsProxyAPIException
from .register_oncall_tenant import register_oncall_tenant
from .tasks import (
link_slack_team_async,
Expand All @@ -30,7 +30,7 @@ def get_installation_link_from_chatops_proxy(user) -> typing.Optional[str]:
org.stack_id,
user.user_id,
org.web_link,
SERVICE_TYPE_ONCALL,
APP_TYPE_ONCALL,
)
return link
except ChatopsProxyAPIException as api_exc:
Expand Down Expand Up @@ -63,7 +63,7 @@ def register_oncall_tenant_with_async_fallback(org):
kwargs={
"service_tenant_id": str(org.uuid),
"cluster_slug": settings.ONCALL_BACKEND_REGION,
"service_type": SERVICE_TYPE_ONCALL,
"service_type": APP_TYPE_ONCALL,
"stack_id": org.stack_id,
"stack_slug": org.stack_slug,
"org_id": org.id,
Expand All @@ -80,7 +80,7 @@ def unregister_oncall_tenant(service_tenant_id: str, cluster_slug: str):
kwargs={
"service_tenant_id": service_tenant_id,
"cluster_slug": cluster_slug,
"service_type": SERVICE_TYPE_ONCALL,
"service_type": APP_TYPE_ONCALL,
},
countdown=2,
)
Expand All @@ -97,7 +97,7 @@ def can_link_slack_team(
"""
client = ChatopsProxyAPIClient(settings.ONCALL_GATEWAY_URL, settings.ONCALL_GATEWAY_API_TOKEN)
try:
response = client.can_slack_link(service_tenant_id, cluster_slug, slack_team_id, SERVICE_TYPE_ONCALL)
response = client.can_slack_link(service_tenant_id, cluster_slug, slack_team_id, APP_TYPE_ONCALL)
return response.status_code == 200
except Exception as e:
logger.error(
Expand All @@ -111,7 +111,7 @@ def can_link_slack_team(
def link_slack_team(service_tenant_id: str, slack_team_id: str):
client = ChatopsProxyAPIClient(settings.ONCALL_GATEWAY_URL, settings.ONCALL_GATEWAY_API_TOKEN)
try:
client.link_slack_team(service_tenant_id, slack_team_id, SERVICE_TYPE_ONCALL)
client.link_slack_team(service_tenant_id, slack_team_id, APP_TYPE_ONCALL)
except Exception as e:
logger.error(
f'msg="Failed to link slack team: {e}"'
Expand All @@ -121,7 +121,7 @@ def link_slack_team(service_tenant_id: str, slack_team_id: str):
kwargs={
"service_tenant_id": service_tenant_id,
"slack_team_id": slack_team_id,
"service_type": SERVICE_TYPE_ONCALL,
"service_type": APP_TYPE_ONCALL,
},
countdown=2,
)
Expand All @@ -132,7 +132,7 @@ def unlink_slack_team(service_tenant_id: str, slack_team_id: str):
kwargs={
"service_tenant_id": service_tenant_id,
"slack_team_id": slack_team_id,
"service_type": SERVICE_TYPE_ONCALL,
"service_type": APP_TYPE_ONCALL,
}
)

Expand All @@ -144,7 +144,9 @@ def uninstall_slack(stack_id: int, grafana_user_id: int) -> bool:
"""
client = ChatopsProxyAPIClient(settings.ONCALL_GATEWAY_URL, settings.ONCALL_GATEWAY_API_TOKEN)
try:
removed, response = client.delete_oauth_installation(stack_id, PROVIDER_TYPE_SLACK, grafana_user_id)
removed, response = client.delete_oauth_installation(
stack_id, PROVIDER_TYPE_SLACK, grafana_user_id, APP_TYPE_ONCALL
)
except ChatopsProxyAPIException as api_exc:
if api_exc.status == 404:
return True
Expand Down

0 comments on commit dd84aa1

Please sign in to comment.