Skip to content

Commit 1410eb1

Browse files
authored
Service Accounts: Unlock endpoint to update service account by id (#165)
1 parent aa00dd9 commit 1410eb1

File tree

4 files changed

+37
-2
lines changed

4 files changed

+37
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
* Remove Python 3.6 support. Thanks, @Ousret.
1212
* Improve support for folders, by adding ``parent_uid`` option to relevant
1313
endpoints, and by adding missing ``move_folder``. Thanks, @grafuls.
14+
* Service Accounts: Unlock endpoint to update service account by id.
15+
Thanks, @einar-lanfranco.
1416

1517
[Niquests]: https://niquests.readthedocs.io/
1618
[Riquests]: https://requests.readthedocs.io/

grafana_client/elements/_async/service_account.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,24 @@ async def create(self, service_account):
3535
create_service_account_path = "/serviceaccounts/"
3636
return await self.client.POST(create_service_account_path, json=service_account)
3737

38+
async def update(self, service_account_id, service_account):
39+
"""
40+
Update service account by id.
41+
https://grafana.com/docs/grafana/latest/developers/http_api/serviceaccount/#update-service-account
42+
43+
:param service_account_id:
44+
:param service_account: {"name": "string", "role": "string"}
45+
:return:
46+
"""
47+
path = "/serviceaccounts/%s" % service_account_id
48+
return await self.client.PATCH(path, json=service_account)
49+
3850
async def delete(self, service_account_id):
3951
"""
4052
Delete service account.
4153
https://grafana.com/docs/grafana/latest/developers/http_api/serviceaccount/#delete-service-account
4254
43-
:param service_account:
55+
:param service_account_id:
4456
:return:
4557
"""
4658

grafana_client/elements/service_account.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,24 @@ def create(self, service_account):
3535
create_service_account_path = "/serviceaccounts/"
3636
return self.client.POST(create_service_account_path, json=service_account)
3737

38+
def update(self, service_account_id, service_account):
39+
"""
40+
Update service account by id.
41+
https://grafana.com/docs/grafana/latest/developers/http_api/serviceaccount/#update-service-account
42+
43+
:param service_account_id:
44+
:param service_account: {"name": "string", "role": "string"}
45+
:return:
46+
"""
47+
path = "/serviceaccounts/%s" % service_account_id
48+
return self.client.PATCH(path, json=service_account)
49+
3850
def delete(self, service_account_id):
3951
"""
4052
Delete service account.
4153
https://grafana.com/docs/grafana/latest/developers/http_api/serviceaccount/#delete-service-account
4254
43-
:param service_account:
55+
:param service_account_id:
4456
:return:
4557
"""
4658

test/elements/test_service_account.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,15 @@ def test_create(self, m):
6666
user = self.grafana.serviceaccount.create({"name": "foo", "role": "Admin"})
6767
self.assertEqual(user["message"], "Service account created")
6868

69+
@requests_mock.Mocker()
70+
def test_update(self, m):
71+
m.patch(
72+
"http://localhost/api/serviceaccounts/42",
73+
json={"message": "Service account updated"},
74+
)
75+
user = self.grafana.serviceaccount.update(42, {"name": "foo", "role": "Admin"})
76+
self.assertEqual(user["message"], "Service account updated")
77+
6978
@requests_mock.Mocker()
7079
def test_delete(self, m):
7180
m.delete(

0 commit comments

Comments
 (0)