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)
This commit is contained in:
Michael Derynck 2024-01-30 11:57:20 -07:00 committed by GitHub
parent 06933a696a
commit 84a92cc9d3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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",
}