Skip to content

feat: update user's password by users_api #498

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 14, 2022
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## 1.33.0 [unreleased]

### Features
1. [#498](https://github.com/influxdata/influxdb-client-python/pull/498): Add possibility to update user's password by `users_api`

### Bug Fixes
1. [#497](https://github.com/influxdata/influxdb-client-python/pull/497): Parsing InfluxDB response with new line character in CSV column [async/await]

Expand Down
35 changes: 25 additions & 10 deletions influxdb_client/client/users_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"""

from typing import Union
from influxdb_client import UsersService, User, Users, UserResponse
from influxdb_client import UsersService, User, Users, UserResponse, PasswordResetBody


class UsersApi(object):
Expand Down Expand Up @@ -36,30 +36,45 @@ def update_user(self, user: User) -> UserResponse:
"""
return self._service.patch_users_id(user_id=user.id, user=user)

def update_password(self, user: Union[str, User, UserResponse], password: str) -> None:
"""Update a password.

:param user: User to update password (required)
:param password: New password (required)
:return: None
"""
user_id = self._user_id(user)

return self._service.post_users_id_password(user_id=user_id, password_reset_body=PasswordResetBody(password))

def delete_user(self, user: Union[str, User, UserResponse]) -> None:
"""Delete a user.

:param user: user id or User
:return: User
:return: None
"""
if isinstance(user, User):
user_id = user.id
elif isinstance(user, UserResponse):
user_id = user.id
else:
user_id = user
user_id = self._user_id(user)

return self._service.delete_users_id(user_id=user_id)

def find_users(self, **kwargs) -> Users:
"""List all users.

:key int offset: Offset for pagination
:key int limit: Limit for pagination
:key int offset: The offset for pagination. The number of records to skip.
:key int limit: Limits the number of records returned. Default is `20`.
:key str after: The last resource ID from which to seek from (but not including).
This is to be used instead of `offset`.
:key str name: The user name.
:key str id: The user ID.
:return: Buckets
"""
return self._service.get_users(**kwargs)

def _user_id(self, user: Union[str, User, UserResponse]):
if isinstance(user, User):
user_id = user.id
elif isinstance(user, UserResponse):
user_id = user.id
else:
user_id = user
return user_id
Loading