Skip to content

Commit

Permalink
Service Accounts: Unlock endpoint to update service account by id (#165)
Browse files Browse the repository at this point in the history
  • Loading branch information
amotl authored Mar 29, 2024
1 parent aa00dd9 commit 1410eb1
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
* Remove Python 3.6 support. Thanks, @Ousret.
* Improve support for folders, by adding ``parent_uid`` option to relevant
endpoints, and by adding missing ``move_folder``. Thanks, @grafuls.
* Service Accounts: Unlock endpoint to update service account by id.
Thanks, @einar-lanfranco.

[Niquests]: https://niquests.readthedocs.io/
[Riquests]: https://requests.readthedocs.io/
Expand Down
14 changes: 13 additions & 1 deletion grafana_client/elements/_async/service_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""

Expand Down
14 changes: 13 additions & 1 deletion grafana_client/elements/service_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""

Expand Down
9 changes: 9 additions & 0 deletions test/elements/test_service_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 1410eb1

Please sign in to comment.