概述
嬴图数据库的用户(User)可拥有多个权限和策略,以便对嬴图数据库进行操作。
用户命名规则
创建用户时需设置用户名,规则如下:
- 2~64个字符
- 以字母开头
- 仅允许使用字母、下划线和数字(_ 、A-Z、a-z、0-9)
一个嬴图实例中的用户不能重名。
密码
创建用户时需设置密码,规则如下:
- 6~64个字符
- 字符种类不限
查看用户
返回的表名:_user
返回的表头:username
| create
| graphPrivileges
| systemPrivileges
| propertyPrivileges
| policies
(用户名、创建时间、图集权限、系统权限、属性权限、策略)
// 查看当前实例中的所有用户信息
show().user()
// 查看当前实例中指定的用户信息
show().user("<name>")
// 查看当前登录的用户信息
show().self()
创建用户
// 在当前实例中创建一个用户
create().user(
"<username>",
"<password>",
<{}graph_privileges?>,
<[]system_privileges?>,
<[]policies?>,
<{}property_privileges?>
)
其中的数据格式为:
// <{}graph_privileges>
{
"<graph1>":["<graph_privilege>", "<graph_privilege>", ...],
"<graph2>":["<graph_privilege>", "<graph_privilege>", ...],
...
}
// <{}property_privileges>
{
"node": {
"read": [
["<graph>", "<@schema?>", "<property?>"],
["<graph>", "<@schema?>", "<property?>"],
...
],
"write": [
["<graph>", "<@schema?>", "<property?>"],
["<graph>", "<@schema?>", "<property?>"],
...
],
"deny": [
["<graph>", "<@schema?>", "<property?>"],
["<graph>", "<@schema?>", "<property?>"],
...
],
},
"edge": {
"read": [
["<graph>", "<@schema?>", "<property?>"],
["<graph>", "<@schema?>", "<property?>"],
...
],
"write": [
["<graph>", "<@schema?>", "<property?>"],
["<graph>", "<@schema?>", "<property?>"],
...
],
"deny": [
["<graph>", "<@schema?>", "<property?>"],
["<graph>", "<@schema?>", "<property?>"],
...
],
}
}
注1:图集名<graph>
填星号(*)时表示当前实例的所有图集;同理,<@schema>
和<property>
填星号时表示所有schema和所有属性。
注2:参数user()
采用下标传参法,当不设置前项但需设置后项时,前项需使用空括号占位。
本例创建用户user01,设置密码为pwABC123,赋予针对所有图集的图集权限UPDATE、ALGO、LTE和UFE,系统权限STAT、TOP和KILL,以及针对所有属性的属性权限WRITE:
create().user(
"user01",
"pwABC123",
{"*": ["UPDATE","ALGO","LTE","UFE"]},
["STAT","TOP","KILL"],
[],
{
"node": {
"write": [["*","*","*"]]
},
"edge": {
"write": [["*","*","*"]]
}
}
)
修改用户
// 修改当前实例中的指定用户
alter().user("<username>").set({
password:"<new?>",
graph_privileges: <{}graph_privileges?>,
system_privileges: <[]system_privileges?>,
policies: <[]policies?>,
property_privileges: <{}property_privileges?>
})
其中<{}graph_privileges>
和<{}property_privileges>
的数据格式同创建用户。
本例将用户user01的密码修改为superFast:
alter().user("user01").set({password: "superFast"})
本例修改用户user01的权限,使其只能查看图集default的元数据:
alter().user("user01").set({
graph_privileges: {"default": ["FIND"]},
property_privileges: {
"node": {
"read": [["default","*","*"]]
},
"edge": {
"read": [["default","*","*"]]
}
}
})
只有当图集权限FIND和属性权限READ同时给到图集default及其元数据时,用户才能查看该图集的元数据。
删除用户
// 从当前实例中删除指定用户
drop().user("<name>")
重置管理员账户
重置管理员账户需要通过工具ultipa-reset-user
在服务器端进行,该操作不属于嬴图GQL的操作范畴。