Skip to content

Commit

Permalink
Add alter_database_user. Remove update_permissions and reroute
Browse files Browse the repository at this point in the history
update_database_user_password to alter_database_user.
  • Loading branch information
Christopher Rabotin committed Feb 22, 2015
1 parent 1a62701 commit 9db53bf
Showing 1 changed file with 26 additions and 16 deletions.
42 changes: 26 additions & 16 deletions influxdb/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -725,11 +725,33 @@ def update_database_user_password(self, username, new_password):
"""
Update password
"""
return self.alter_database_user(username, new_password)

def alter_database_user(self, username, password=None, permissions=None):
"""
Alters a database user and/or their permissions.
:param permissions: A ``(readFrom, writeTo)`` tuple
:raise TypeError: if permissions cannot be read.
:raise ValueError: if neither password nor permissions provided.
"""
url = "db/{0}/users/{1}".format(self._database, username)

data = {
'password': new_password
}
if not password and not permissions:
raise ValueError("Nothing to alter for user {}.".format(username))

data = {}

if password:
data['password'] = password

if permissions:
try:
data['readFrom'], data['writeTo'] = permissions
except (ValueError, TypeError):
raise TypeError(
"'permissions' must be (readFrom, writeTo) tuple"
)

self.request(
url=url,
Expand All @@ -739,7 +761,7 @@ def update_database_user_password(self, username, new_password):
)

if username == self._username:
self._password = new_password
self._password = password

return True

Expand All @@ -757,18 +779,6 @@ def delete_database_user(self, username):

return True

# update the user by POSTing to db/site_dev/users/paul

def update_permission(self, username, json_body):
"""
TODO: Update read/write permission
2013-11-08: This endpoint has not been implemented yet in ver0.0.8,
but it is documented in http://influxdb.org/docs/api/http.html.
See also: src/api/http/api.go:l57
"""
raise NotImplementedError()

def send_packet(self, packet):
data = json.dumps(packet)
byte = data.encode('utf-8')
Expand Down

0 comments on commit 9db53bf

Please sign in to comment.