user_created = hc.create_user( user_name = "test_user", pwd = "password123" )
复制
Create User
Result:
This method returns a Boolean value to represent whether this operation is successful. If the error pops up when creating user, “ValueError” exception will be raised.
Parameter description:
Parameters | Description | Options |
---|---|---|
user_name (str) |
New username |
Yes |
password (str) |
New password |
Yes |
is_super (bool) |
Whether this user is superuser |
No, defaults to False |
can_create_role (bool) |
Whether this user can create role |
No, defaults to False |
can_create_db (bool) |
Whether this user can create database |
No, defaults to False |
Check User
user_info = hc.get_user_info("user_name")
复制
Result:
This method returns a Dictionary containing the user information.
Parameter description:
Parameters | Description | Options |
---|---|---|
user_name (str) |
Name of user to get information |
Yes |
Delete User
user_deleted = hc.delete_user("user_name")
复制
Result:
This method returns a Boolean value to represent whether this operation is successful. If the error pops up when deleting user, “ValueError” exception will be raised.
Parameter description:
Parameters | Description | Required |
---|---|---|
user_name (str) |
Username to be deleted |
Yes |
Alter User
changed = hc.change_user_info(user_name = "test_user", pwd = "password123", is_super = True)
复制
Result:
This method returns a Boolean value to represent whether this operation is successful. If the error pops up when altering user, “ValueError” exception will be raised.
Parameter description:
Parameters | Description | Required |
---|---|---|
user_name (str) |
Username to be changed |
Yes |
pwd (str) |
New password |
Yes |
change_meta (bool) |
Whether to change metadata |
No, defaults to False |
is_super (bool) |
Whether this user is superuser |
No, defaults to False |
can_create_role (bool) |
Whether this user can create role |
No, defaults to False |
can_create_db (bool) |
Whether this user can create database |
No, defaults to False |
Change User Password
changed = hc.change_password(new_password = "another_new_password123", user_name = "test_user")
复制
Result:
This method returns a Boolean value to represent whether this operation is successful. If the error pops up when changing password, “ValueError” exception will be raised.
Parameter description:
Parameters | Description | Required |
---|---|---|
new_password (str) |
New password of the specified user |
Yes |
user_name (str) |
Name of user to change password, if not specified, the password of current user will be changed |
No |
Grant Privilege
granted = hc.grant_user_permission("user_name", ["all"], "table_name", "database_name")
复制
Result:
This method returns a Boolean value to represent whether this operation is successful. If the error pops up when granting privilege, “ValueError” exception will be raised.
Parameter description:
Parameters | Description | Required |
---|---|---|
user_name (str) |
User to whom will be granted privileges |
Yes |
privileges (list[str]) |
Privilege list, including “create”, “access”, “all” |
Yes |
table_name (str) |
Table name |
No, grants privileges on "default" database if not specified. If user does not have privilege on "default" database, “ValueError” exception will be raised |
database_name (str) |
Database where the table is created |
No, defaults to "default" database |
Revoke Privilege
delete_grant = hc.delete_user_permission("test_user", ["all"], "my_test_rename", "my_database")
复制
Result:
This method returns a Boolean value to represent whether this operation is successful. If the error pops up when revoking privilege, “ValueError” exception will be raised.
Parameter description:
Parameters | Description | Required |
---|---|---|
user_name (str) |
User to whom will be revoked privileges |
Yes |
privileges (list[str]) |
Privilege list, including “create”, “access”, “all” |
Yes |
table_name (str) |
Table name |
No, revokes privileges on "default" database if not specified. If user does not have privilege on "default" database, “ValueError” exception will be raised |
database_name (str) |
Database where the table is created |
No, defaults to "default" database |
Check User Privilege
user_permission = hc.view_user_permission("user_name")
复制
Result:
This method returns a Dictionary containing user privilege information.
Parameter description:
Parameters | Description | Required |
---|---|---|
user_name (str) |
User to check privilege |
Yes |
Check Table Privilege
table_permission = view_table_permission("table_name", "database_name")
复制
Result:
This method returns a Dictionary containing user privilege information.
Parameter description:
Parameters | Description | Required |
---|---|---|
table_name (str) |
Table to check privilege |
Yes |
database_name |
Database where the table is located |
No, defaults to "default" database |