8000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 62e9bb8 + 3742a0e commit 045e76fCopy full SHA for 045e76f
influxdb/client.py
@@ -740,6 +740,28 @@ def revoke_privilege(self, privilege, database, username):
740
username)
741
self.query(text)
742
743
+ def get_list_privileges(self, username):
744
+ """Get the list of all privileges granted to given user.
745
+
746
+ :param username: the username to get privileges of
747
+ :type username: str
748
749
+ :returns: all privileges granted to given user
750
+ :rtype: list of dictionaries
751
752
+ :Example:
753
754
+ ::
755
756
+ >> privileges = client.get_list_privileges('user1')
757
+ >> privileges
758
+ [{u'privilege': u'WRITE', u'database': u'db1'},
759
+ {u'privilege': u'ALL PRIVILEGES', u'database': u'db2'},
760
+ {u'privilege': u'NO PRIVILEGES', u'database': u'db3'}]
761
+ """
762
+ text = "SHOW GRANTS FOR {0}".format(username)
763
+ return list(self.query(text).get_points())
764
765
def send_packet(self, packet):
766
"""Send an UDP packet.
767
influxdb/tests/client_test.py
@@ -798,6 +798,31 @@ def test_revoke_privilege_invalid(self):
798
with _mocked_session(cli, 'get', 400):
799
self.cli.revoke_privilege('', 'testdb', 'test')
800
801
+ def test_get_list_privileges(self):
802
+ data = {'results': [
803
+ {'series': [
804
+ {'columns': ['database', 'privilege'],
805
+ 'values': [
806
+ ['db1', 'READ'],
807
+ ['db2', 'ALL PRIVILEGES'],
808
+ ['db3', 'NO PRIVILEGES']]}
809
+ ]}
810
811
812
+ with _mocked_session(self.cli, 'get', 200, json.dumps(data)):
813
+ self.assertListEqual(
814
+ self.cli.get_list_privileges('test'),
815
+ [{'database': 'db1', 'privilege': 'READ'},
816
+ {'database': 'db2', 'privilege': 'ALL PRIVILEGES'},
817
+ {'database': 'db3', 'privilege': 'NO PRIVILEGES'}]
818
+ )
819
820
+ @raises(Exception)
821
+ def test_get_list_privileges_fails(self):
822
+ cli = InfluxDBClient('host', 8086, 'username', 'password')
823
+ with _mocked_session(cli, 'get', 401):
824
+ cli.get_list_privileges('test')
825
826
def test_invalid_port_fails(self):
827
with self.assertRaises(ValueError):
828
InfluxDBClient('host', '80/redir', 'username', 'password')