From 84a92cc9d35f71fa04f0581ff9210529fc1a12df Mon Sep 17 00:00:00 2001 From: Michael Derynck Date: Tue, 30 Jan 2024 11:57:20 -0700 Subject: [PATCH] Add headers for ChatopsProxyAPIClient (#3789) # What this PR does Add necessary headers to ChatopsProxyAPIClient for dev environment testing. ## Which issue(s) this PR fixes ## Checklist - [x] Unit, integration, and e2e (if applicable) tests updated - [x] Documentation added (or `pr:no public docs` PR label added if not required) - [x] `CHANGELOG.md` updated (or `pr:no changelog` PR label added if not required) --- engine/common/oncall_gateway/client.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/engine/common/oncall_gateway/client.py b/engine/common/oncall_gateway/client.py index cd3eadaf..f2d11a2c 100644 --- a/engine/common/oncall_gateway/client.py +++ b/engine/common/oncall_gateway/client.py @@ -4,6 +4,7 @@ from typing import List from urllib.parse import urljoin import requests +from django.conf import settings SERVICE_TYPE_ONCALL = "oncall" @@ -64,7 +65,7 @@ class ChatopsProxyAPIClient: "service_type": service_type, } } - response = requests.post(url=url, json=d) + response = requests.post(url=url, json=d, headers=self._headers) self._check_response(response) return Tenant(**response.json()["tenant"]), response @@ -81,7 +82,7 @@ class ChatopsProxyAPIClient: } } - response = requests.post(url=url, json=d) + response = requests.post(url=url, json=d, headers=self._headers) self._check_response(response) return response.json()["removed"], response @@ -96,7 +97,7 @@ class ChatopsProxyAPIClient: "cluster_slug": cluster_slug, "slack_team_id": slack_team_id, } - response = requests.post(url=url, json=d) + response = requests.post(url=url, json=d, headers=self._headers) self._check_response(response) return response @@ -111,7 +112,7 @@ class ChatopsProxyAPIClient: "slack_team_id": slack_team_id, } } - response = requests.post(url=url, json=d) + response = requests.post(url=url, json=d, headers=self._headers) self._check_response(response) return SlackLink(**response.json()["slack_link"]), response @@ -126,7 +127,7 @@ class ChatopsProxyAPIClient: "slack_team_id": slack_team_id, } } - response = requests.post(url=url, json=d) + response = requests.post(url=url, json=d, headers=self._headers) self._check_response(response) return response.json()["removed"], response @@ -152,3 +153,11 @@ class ChatopsProxyAPIClient: msg=message, method=response.request.method, ) + + @property + def _headers(self) -> dict: + return { + "User-Agent": settings.GRAFANA_COM_USER_AGENT, + "Authorization": f"Bearer {self.api_token}", + "Content-Type": "application/json", + }