From bdb6a0e9758bdd08537181274009877bb5184034 Mon Sep 17 00:00:00 2001 From: Andreas Motl Date: Fri, 29 Mar 2024 11:22:42 +0100 Subject: [PATCH] Service Accounts: Unlock endpoint to update service account by id --- CHANGELOG.md | 2 ++ grafana_client/elements/_async/service_account.py | 14 +++++++++++++- grafana_client/elements/service_account.py | 14 +++++++++++++- test/elements/test_service_account.py | 9 +++++++++ 4 files changed, 37 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cf8332d..fc3c1c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ uses `GrafanaTimeoutError` instead. Other than this, [Niquests] is a drop- in replacement for [Requests] and therefore is largely compatible. * Remove Python 3.6 support. Thanks, @Ousret. +* Service Accounts: Unlock endpoint to update service account by id. + Thanks, @einar-lanfranco. [Niquests]: https://niquests.readthedocs.io/ [Riquests]: https://requests.readthedocs.io/ diff --git a/grafana_client/elements/_async/service_account.py b/grafana_client/elements/_async/service_account.py index fed013d..5fa8489 100644 --- a/grafana_client/elements/_async/service_account.py +++ b/grafana_client/elements/_async/service_account.py @@ -35,12 +35,24 @@ async def create(self, service_account): create_service_account_path = "/serviceaccounts/" return await self.client.POST(create_service_account_path, json=service_account) + async def update(self, service_account_id, service_account): + """ + Update service account by id. + https://grafana.com/docs/grafana/latest/developers/http_api/serviceaccount/#update-service-account + + :param service_account_id: + :param service_account: {"name": "string", "role": "string"} + :return: + """ + path = "/serviceaccounts/%s" % service_account_id + return await self.client.PATCH(path, json=service_account) + async def delete(self, service_account_id): """ Delete service account. https://grafana.com/docs/grafana/latest/developers/http_api/serviceaccount/#delete-service-account - :param service_account: + :param service_account_id: :return: """ diff --git a/grafana_client/elements/service_account.py b/grafana_client/elements/service_account.py index ca339b2..20e6266 100644 --- a/grafana_client/elements/service_account.py +++ b/grafana_client/elements/service_account.py @@ -35,12 +35,24 @@ def create(self, service_account): create_service_account_path = "/serviceaccounts/" return self.client.POST(create_service_account_path, json=service_account) + def update(self, service_account_id, service_account): + """ + Update service account by id. + https://grafana.com/docs/grafana/latest/developers/http_api/serviceaccount/#update-service-account + + :param service_account_id: + :param service_account: {"name": "string", "role": "string"} + :return: + """ + path = "/serviceaccounts/%s" % service_account_id + return self.client.PATCH(path, json=service_account) + def delete(self, service_account_id): """ Delete service account. https://grafana.com/docs/grafana/latest/developers/http_api/serviceaccount/#delete-service-account - :param service_account: + :param service_account_id: :return: """ diff --git a/test/elements/test_service_account.py b/test/elements/test_service_account.py index 0d1f55f..6093e95 100644 --- a/test/elements/test_service_account.py +++ b/test/elements/test_service_account.py @@ -66,6 +66,15 @@ def test_create(self, m): user = self.grafana.serviceaccount.create({"name": "foo", "role": "Admin"}) self.assertEqual(user["message"], "Service account created") + @requests_mock.Mocker() + def test_update(self, m): + m.patch( + "http://localhost/api/serviceaccounts/42", + json={"message": "Service account updated"}, + ) + user = self.grafana.serviceaccount.update(42, {"name": "foo", "role": "Admin"}) + self.assertEqual(user["message"], "Service account updated") + @requests_mock.Mocker() def test_delete(self, m): m.delete(