Related to https://github.com/grafana/oncall-private/issues/2826 Continuing work started in https://github.com/grafana/oncall/pull/5211, this adds support for Grafana service accounts tokens for API authentication (except alert group actions which will still require a user behind). Next steps would be updating the go client and the terraform provider to allow service account token auth for OnCall resources. Following proposal 1.1 from [doc](https://docs.google.com/document/d/1I3nFbsUEkiNPphBXT-kWefIeramTY71qqZ1OA06Kmls/edit?usp=sharing).
18 lines
787 B
Python
18 lines
787 B
Python
import json
|
|
|
|
import httpretty
|
|
|
|
|
|
def setup_service_account_api_mocks(organization, perms=None, user_data=None, perms_status=200, user_status=200):
|
|
# requires enabling httpretty
|
|
if perms is None:
|
|
perms = {}
|
|
mock_response = httpretty.Response(status=perms_status, body=json.dumps(perms))
|
|
perms_url = f"{organization.grafana_url}/api/access-control/user/permissions"
|
|
httpretty.register_uri(httpretty.GET, perms_url, responses=[mock_response])
|
|
|
|
if user_data is None:
|
|
user_data = {"login": "some-login", "uid": "service-account:42"}
|
|
mock_response = httpretty.Response(status=user_status, body=json.dumps(user_data))
|
|
user_url = f"{organization.grafana_url}/api/user"
|
|
httpretty.register_uri(httpretty.GET, user_url, responses=[mock_response])
|