Skip to content

Commit b1d9fb9

Browse files
authored
Merge pull request influxdata#331 from babilen/grant_admin_privileges
Add grant_admin_privileges() to InfluxDBClient
2 parents 8c343b9 + df4ee82 commit b1d9fb9

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

influxdb/client.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,18 @@ def delete_series(self, database=None, measurement=None, tags=None):
684684
for k, v in tags.items()])
685685
self.query(query_str, database=database)
686686

687+
def grant_admin_privileges(self, username):
688+
"""Grant cluster administration privileges to a user.
689+
690+
:param username: the username to grant privileges to
691+
:type username: str
692+
693+
.. note:: Only a cluster administrator can create/drop databases
694+
and manage users.
695+
"""
696+
text = "GRANT ALL PRIVILEGES TO {0}".format(username)
697+
self.query(text)
698+
687699
def revoke_admin_privileges(self, username):
688700
"""Revoke cluster administration privileges from a user.
689701

influxdb/tests/client_test.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,28 @@ def test_get_list_users_empty(self):
710710

711711
self.assertListEqual(self.cli.get_list_users(), [])
712712

713+
def test_grant_admin_privileges(self):
714+
example_response = '{"results":[{}]}'
715+
716+
with requests_mock.Mocker() as m:
717+
m.register_uri(
718+
requests_mock.GET,
719+
"http://localhost:8086/query",
720+
text=example_response
721+
)
722+
self.cli.grant_admin_privileges('test')
723+
724+
self.assertEqual(
725+
m.last_request.qs['q'][0],
726+
'grant all privileges to test'
727+
)
728+
729+
@raises(Exception)
730+
def test_grant_admin_privileges_invalid(self):
731+
cli = InfluxDBClient('host', 8086, 'username', 'password')
732+
with _mocked_session(cli, 'get', 400):
733+
self.cli.grant_admin_privileges('')
734+
713735
def test_revoke_admin_privileges(self):
714736
example_response = '{"results":[{}]}'
715737

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy