获取用户配置文件 API
编辑获取用户配置文件 API
编辑用户配置文件功能仅设计供 Kibana 和 Elastic 的可观测性、企业搜索以及 Elastic Security 解决方案使用。个人用户和外部应用程序不应直接调用此 API。Elastic 保留在未来版本中更改或删除此功能的权利,恕不另行通知。
使用唯一的配置文件 ID 列表检索用户配置文件。
请求
编辑GET /_security/profile/<uid>
路径参数
编辑-
uid
- (必需,字符串)用户配置文件的唯一标识符。您可以指定多个 ID,以逗号分隔列表的形式。
查询参数
编辑-
data
- (可选,字符串)配置文件文档的
data
字段的逗号分隔过滤器列表。要返回所有内容,请使用data=*
。要返回内容子集,请使用data=<key>
来检索指定<key>
下嵌套的内容。默认不返回任何内容。
响应体
编辑成功调用会返回用户配置文件的 JSON 表示形式及其内部版本号。如果未找到与提供的 uid
匹配的配置文件文档,则 API 将返回一个空对象。默认情况下不返回 data
字段的内容,以避免反序列化潜在的大型负载。
示例
编辑resp = client.security.get_user_profile( uid="u_79HkWkwmnBH5gqFKwoxggWPjEBOur1zLPXQPEl1VBW0_0", ) print(resp)
const response = await client.security.getUserProfile({ uid: "u_79HkWkwmnBH5gqFKwoxggWPjEBOur1zLPXQPEl1VBW0_0", }); console.log(response);
GET /_security/profile/u_79HkWkwmnBH5gqFKwoxggWPjEBOur1zLPXQPEl1VBW0_0
对于匹配 u_79HkWkwmnBH5gqFKwoxggWPjEBOur1zLPXQPEl1VBW0_0
的 uid
,API 返回以下响应
{ "profiles": [ { "uid": "u_79HkWkwmnBH5gqFKwoxggWPjEBOur1zLPXQPEl1VBW0_0", "enabled": true, "last_synchronized": 1642650651037, "user": { "username": "jacknich", "roles": [ "admin", "other_role1" ], "realm_name": "native", "full_name": "Jack Nicholson", "email": "[email protected]" }, "labels": { "direction": "north" }, "data": {}, "_doc": { "_primary_term": 88, "_seq_no": 66 } } ] }
以下请求检索嵌套在键 app1
下的 data
子集,以及用户的配置文件
resp = client.security.get_user_profile( uid="u_79HkWkwmnBH5gqFKwoxggWPjEBOur1zLPXQPEl1VBW0_0", data="app1.key1", ) print(resp)
const response = await client.security.getUserProfile({ uid: "u_79HkWkwmnBH5gqFKwoxggWPjEBOur1zLPXQPEl1VBW0_0", data: "app1.key1", }); console.log(response);
GET /_security/profile/u_79HkWkwmnBH5gqFKwoxggWPjEBOur1zLPXQPEl1VBW0_0?data=app1.key1
{ "profiles": [ { "uid": "u_79HkWkwmnBH5gqFKwoxggWPjEBOur1zLPXQPEl1VBW0_0", "enabled": true, "last_synchronized": 1642650651037, "user": { "username": "jacknich", "roles": [ "admin", "other_role1" ], "realm_name": "native", "full_name": "Jack Nicholson", "email": "[email protected]" }, "labels": { "direction": "north" }, "data": { "app1": { "key1": "value1" } }, "_doc": { "_primary_term": 88, "_seq_no": 66 } } ] }
如果在检索用户配置文件时出现任何错误,则它们将返回在 errors
字段中
{ "profiles": [], "errors": { "count": 1, "details": { "u_FmxQt3gr1BBH5wpnz9HkouPj3Q710XkOgg1PWkwLPBW_5": { "type": "resource_not_found_exception", "reason": "profile document not found" } } } }