Skip to content
This repository was archived by the owner on Oct 29, 2024. It is now read-only.

Add grant_admin_privileges() to InfluxDBClient #331

Merged
merged 2 commits into from
Jun 13, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions influxdb/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,18 @@ def delete_series(self, database=None, measurement=None, tags=None):
for k, v in tags.items()])
self.query(query_str, database=database)

def grant_admin_privileges(self, username):
"""Grant cluster administration privileges to a user.

:param username: the username to grant privileges to
:type username: str

.. note:: Only a cluster administrator can create/drop databases
and manage users.
"""
text = "GRANT ALL PRIVILEGES TO {0}".format(username)
self.query(text)

def revoke_admin_privileges(self, username):
"""Revoke cluster administration privileges from a user.

Expand Down
22 changes: 22 additions & 0 deletions influxdb/tests/client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,28 @@ def test_get_list_users_empty(self):

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

def test_grant_admin_privileges(self):
example_response = '{"results":[{}]}'

with requests_mock.Mocker() as m:
m.register_uri(
requests_mock.GET,
"http://localhost:8086/query",
text=example_response
)
self.cli.grant_admin_privileges('test')

self.assertEqual(
m.last_request.qs['q'][0],
'grant all privileges to test'
)

@raises(Exception)
def test_grant_admin_privileges_invalid(self):
cli = InfluxDBClient('host', 8086, 'username', 'password')
with _mocked_session(cli, 'get', 400):
self.cli.grant_admin_privileges('')

def test_revoke_admin_privileges(self):
example_response = '{"results":[{}]}'

Expand Down