跳转至

获取



GET /api/v1/workspace/accesskey/{ak_uuid}/get

概述

按API Key记录UUID读取凭据、绑定身份与当前有效权限。

调用前和使用步骤

本接口虽然是GET,声明需要w权限External凭据。UUID从API Key列表或创建响应取得;不会按额外workspaceUUID限制,先核对返回content.workspaceUUID。手工Key和已知UUID的非系统绑定账号Key都可查询。手工Key权限以其角色关系为准,没有有效角色关系时可回退管理员;绑定账号Key权限随账号空间角色变化。返回roles/permissions/rolePermissions才是有效权限摘要,不要仅从创建或修改时的roleInfo空数组推断无权限。读取不会消耗或销毁Key。

路由参数

参数名 类型 必选 说明
ak_uuid string Y API Key记录UUID(常为wsak_前缀),不是ak/sk调用凭据;该External路径按UUID跨空间定位,执行前核对workspaceUUID。
例子: wsak_example001
获取或填写方式: 从API Key列表的content.data[].uuid或创建成功content.uuid取得。

请求头

参数名 类型 必选 说明
X-Df-SVersion string 原始路径与请求体签名版本;不能省略后继续沿用本页算法。
例子: v20240417
获取或填写方式: 本页示例使用此固定版本,与示例签名算法配套。
X-Df-Access-Key string Y 本模块列表可用r或w权限;其余接口包括GET详情均需要w权限External凭据。
例子: <external-access-key>
获取或填写方式: 由站点管理员分配 External API AK,不能使用工作空间 OpenAPI Key。
X-Df-Signature string Y 对大写方法、nonce、原始完整路径、timestamp和原始UTF-8请求体按空格拼接后做HMAC-SHA256,取hex摘要。
例子: <hmac-sha256-hex>
获取或填写方式: 按External API 签名认证使用配套SK计算,完整可运行模板见下方。
X-Df-Timestamp string Y 必须在站点配置的签名有效时间窗内,不能复用示例时间。
例子: 1785427200
获取或填写方式: 发送时用 str(int(time.time())) 生成当前Unix秒字符串。
X-Df-Nonce string Y 临时流水号;失败重发也生成新值并重算签名。
例子: 97d275ee9f774315a7885ba7347acbd9
获取或填写方式: 每次请求重新生成uuid.uuid4().hex。

参数补充说明

使用站点级External API AK/SK,签名方式见External API 签名认证。本页生成的工作空间API Key与External签名凭据不是同一套凭据。External当前会返回AK/SK明文,不应用前台页面的掩码策略;响应示例全部使用占位值,应按凭据保管实际响应。

请求例子

import hashlib
import hmac
import json
import time
import uuid
from urllib.parse import urlencode
from urllib.request import Request, urlopen
from urllib.error import HTTPError, URLError

# 替换为目标站点地址及管理员分配的 External API AK/SK。
server = "https://external-api.guance.com"
access_key = "<external-access-key>"
secret_key = "<external-secret-key>"
method = 'GET'
path = '/api/v1/workspace/accesskey/wsak_example001/get'
query = {}
data = None
full_path = path + ("?" + urlencode(query) if query else "")
body = "" if data is None else json.dumps(data, ensure_ascii=False, separators=(",", ":"))
timestamp = str(int(time.time()))
nonce = uuid.uuid4().hex
string_to_sign = " ".join([method, nonce, full_path, timestamp, body])
signature = hmac.new(secret_key.encode("utf-8"), string_to_sign.encode("utf-8"), hashlib.sha256).hexdigest()
headers = {
    "X-Df-Access-Key": access_key,
    "X-Df-Timestamp": timestamp,
    "X-Df-Nonce": nonce,
    "X-Df-Signature": signature,
    "X-Df-SVersion": "v20240417",
}
if data is not None:
    headers["Content-Type"] = "application/json"
request = Request(server + full_path, data=None if data is None else body.encode("utf-8"), headers=headers, method=method)
try:
    with urlopen(request, timeout=30) as result:
        payload = json.loads(result.read().decode("utf-8"))
except HTTPError as error:
    print("HTTP", error.code, error.read().decode("utf-8"))  # 按errorCode、content及traceId处理,不输出AK/SK。
    raise SystemExit(1)
except (URLError, TimeoutError):
    print('读取失败,可退避后重新签名重试,保留traceId及查询条件。')
    raise SystemExit(1)
print(json.dumps(payload, ensure_ascii=False, indent=2))

响应

HTTP 200,application/json统一外壳,业务结果位于content;External不自动加入declaration,列表分页位于content.pageInfo。

字段 类型 说明
content.id integer 或 null 内部记录序号,调用接口使用uuid;创建快照在flush前取得,此字段可为null。
content.uuid string API Key记录UUID,与调用凭据ak/sk不同。
content.status integer Key状态:0启用、2禁用、3已删除。列表/详情仅返回0,删除也可处理未删除的禁用Key。
content.creator string 创建身份,External创建通常external。
content.updator string 更新身份,未修改时可为空。
content.createAt integer 创建Unix秒。
content.deleteAt integer 删除Unix秒,未删除通常-1。
content.updateAt integer 更新Unix秒,尚未修改通常-1。
content.name string API Key显示名称。
content.ak string 工作空间Access Key调用凭据明文,可用于该空间OpenAPI认证,不是本External请求的X-Df-Access-Key。
content.sk string 工作空间Secret Key明文,应作为敏感凭据保存;不是此External请求的配套SK。
content.workspaceUUID string 所属空间UUID。
content.accountUUID string 绑定账号UUID;手工空间Key为空字符串,绑定账号Key的有效权限需按账号角色确认。
content.createdWay string 来源标识,例如manual、user、agent;列表排除所有accountUUID非空的Key。
content.businessType string 系统业务类型标识,手工Key通常为空。
content.isSystem integer 是否系统内置Key;本模块查询/操作过滤系统Key。
content.isOwnerRole integer 是否Owner专用Key,1是、0否;同空间最多一条未删除Owner Key。
content.remark string 既有备注;本External公开新增/修改参数不含remark。
content.isBurnAfterReading integer 保留的阅后即焚标记;本模块不执行读取后销毁,不应依赖它撤销凭据。
content.callCount integer 或 null 持久累计调用次数;异步统计,非实时计数。创建快照在flush前可为null。
content.lastCallAt integer 或 null 最后调用Unix秒,通常-1表示暂无记录;创建快照可为null。
content.creatorInfo object 创建身份摘要,无法解析时{},字段按身份类型变化。
content.creatorInfo.uuid string 创建身份UUID,系统身份可能为空。
content.creatorInfo.status integer 创建身份状态。
content.creatorInfo.wsAccountStatus integer 空间关系状态摘要;系统身份可为0。
content.creatorInfo.username string 用户名或系统身份名。
content.creatorInfo.name string 显示名。
content.creatorInfo.email string 邮箱或系统身份标识。
content.creatorInfo.mobile string 手机号,系统身份为空。
content.creatorInfo.countryCode string 账号身份可提供的手机区号,系统身份可能省略。
content.creatorInfo.iconUrl string 账号身份可提供的头像,系统身份可能省略。
content.creatorInfo.acntWsNickname string 账号身份可提供的空间昵称,系统身份可能省略。
content.effectiveAccountUUID string 鉴权角色主体;手工Key为Key自身uuid,绑定账号Key为accountUUID。
content.accountInfo object 或 null 绑定账号时返回去除password/mfaSecret的账号资料,手工Key为null。
content.accountInfo.id integer 站点内账号记录序号,仅作资料返回;调用其他接口使用uuid。
content.accountInfo.uuid string 账号UUID,后续查询、修改、禁用、删除使用此字段。
content.accountInfo.status integer 绑定账号状态:成功可返回0或其他未禁用历史状态;2会先触发ft.AgentMemberDisabled,3或不存在先触发ft.AgentMemberNotFound。
content.accountInfo.creator string 创建身份标识,External创建通常SYS。
content.accountInfo.updator string 最近修改身份标识,尚无修改时可为空。
content.accountInfo.createAt number 创建时间,Unix秒。
content.accountInfo.updateAt number 更新时间,Unix秒,尚无更新时间时可为-1。
content.accountInfo.deleteAt number 状态操作时间字段,初始通常-1;启用/禁用也会写此值,不应单独据此判断删除,使用status。
content.accountInfo.name string 显示昵称。
content.accountInfo.username string 登录账号名。第三方账号可为空或与其他账号重复。
content.accountInfo.email string 账号联系邮箱;创建时为空且username是邮箱格式时会补为username。
content.accountInfo.mobile string 手机号本地号码,已解密展示,不含国家区号;未设置为空字符串。
content.accountInfo.countryCode string 手机号国家/地区区号纯数字字符串,如86;未设置为空字符串。
content.accountInfo.exterId string 第三方身份系统的唯一ID;本地账号通常为空。
content.accountInfo.extend object 或 null 绑定账号的既有扩展资料,可能含user_icon头像地址;本页仅返回,不能通过Key参数修改。
content.accountInfo.extend.user_icon string 可选头像URL或静态资源文件名;读取历史资料时可能出现,不是本页可写参数。
content.accountInfo.source string 身份来源标识,例如local、unknown、oidc、ldap,也可能存在agent等历史内部来源。
content.accountInfo.nameSpace string 身份命名空间,External创建默认为空;不能通过本模块公开参数设置。
content.accountInfo.isUsed integer 或 boolean 账号是否已使用的标记。
content.accountInfo.agreeTerms integer 条款同意标记。
content.accountInfo.canaryPublic boolean 灰度标记。
content.accountInfo.enableMFA boolean 是否启用MFA。
content.accountInfo.language string 语言标识,zh、en、zh-hant、id、ja、ko。
content.accountInfo.tokenHoldTime integer 账号无操作会话保持时长,单位秒;新账号按站点安全会话配置初始化,不保证固定为示例值。
content.accountInfo.tokenMaxValidDuration integer 账号会话最大有效期,单位秒;新账号按站点安全会话配置初始化。
content.accountInfo.timezone string 时区标识,未设置为空。
content.accountInfo.attributes object SSO同步属性KV对象,可能被后续SSO登录覆盖;键和值由对接方约定。
content.accountInfo.attributes.{属性名} 任意JSON值 自定义属性值,建议使用字符串,例如部门=研发部。
content.accountInfo.customAttributes object 业务侧维护的属性KV对象。
content.accountInfo.customAttributes.{属性名} 任意JSON值 业务自定义值,建议使用字符串,例如costCenter=CC-1001。
content.accountInfo.statusPageSubs integer 状态页订阅标记。
content.accountInfo.defaultWorkspace string 账号默认工作空间UUID,未配置为空。
content.accountInfo.brandKey string 账号当前品牌标识,由站点允许的品牌集合决定。
content.accountInfo.scheduleMobile string 排班专用手机号本地号码,未设置为空。
content.accountInfo.scheduleEmail string 排班专用邮箱,未设置为空。
content.accountInfo.ifScheduleMobileEnable boolean 是否启用排班手机号。
content.accountInfo.ifScheduleEmailEnable boolean 是否启用排班邮箱。
content.accountInfo.accountStatus string 账号附加状态标识,未设置为空。
content.roles 对象数组 当前有效角色摘要,Owner专用Key为Owner角色。
content.roles[].uuid string 角色UUID。
content.roles[].name string 角色名称。
content.permissions 字符串数组 当前有效权限标识,顺序不保证。
content.permissions[] string 一个有效权限ID。
content.rolePermissions object 以角色UUID为键的完整有效权限映射。
content.rolePermissions.{角色UUID} 字符串数组 该角色当前有效权限ID列表;动态角色键来自roles[].uuid。
content.rolePermissions.{角色UUID}[] string 单个权限ID。
{
  "code": 200,
  "content": {
    "id": 1001,
    "uuid": "wsak_example001",
    "status": 0,
    "creator": "external",
    "updator": "",
    "createAt": 1785427200,
    "deleteAt": -1,
    "updateAt": -1,
    "name": "示例只读API Key",
    "ak": "<workspace-api-key>",
    "sk": "<workspace-secret-key>",
    "workspaceUUID": "wksp_example001",
    "accountUUID": "",
    "createdWay": "manual",
    "businessType": "",
    "isSystem": 0,
    "isOwnerRole": 0,
    "remark": "",
    "isBurnAfterReading": 0,
    "callCount": 0,
    "lastCallAt": -1,
    "creatorInfo": {
      "uuid": "",
      "status": 0,
      "name": "SYS",
      "wsAccountStatus": 0,
      "username": "SYS",
      "email": "SYS",
      "mobile": ""
    },
    "effectiveAccountUUID": "wsak_example001",
    "accountInfo": null,
    "roles": [
      {
        "uuid": "role_example001",
        "name": "示例最小权限角色"
      }
    ],
    "permissions": [
      "routine.defaultAccess"
    ],
    "rolePermissions": {
      "role_example001": [
        "routine.defaultAccess"
      ]
    }
  },
  "errorCode": "",
  "message": "",
  "success": true,
  "traceId": "TRACE-EXAMPLE"
}

绑定账号Key的结构示例(实际权限随绑定账号而变化):

{
  "code": 200,
  "content": {
    "id": 1001,
    "uuid": "wsak_example001",
    "status": 0,
    "creator": "external",
    "updator": "",
    "createAt": 1785427200,
    "deleteAt": -1,
    "updateAt": -1,
    "name": "示例只读API Key",
    "ak": "<workspace-api-key>",
    "sk": "<workspace-secret-key>",
    "workspaceUUID": "wksp_example001",
    "accountUUID": "acnt_example001",
    "createdWay": "agent",
    "businessType": "",
    "isSystem": 0,
    "isOwnerRole": 0,
    "remark": "",
    "isBurnAfterReading": 0,
    "callCount": 0,
    "lastCallAt": -1,
    "creatorInfo": {
      "uuid": "",
      "status": 0,
      "name": "SYS",
      "wsAccountStatus": 0,
      "username": "SYS",
      "email": "SYS",
      "mobile": ""
    },
    "effectiveAccountUUID": "acnt_example001",
    "accountInfo": {
      "id": 1001,
      "uuid": "acnt_example001",
      "status": 0,
      "creator": "SYS",
      "updator": "",
      "createAt": 1785427200,
      "deleteAt": -1,
      "updateAt": -1,
      "name": "示例Agent",
      "username": "agent-example",
      "email": "",
      "mobile": "",
      "countryCode": "",
      "exterId": "",
      "extend": null,
      "source": "agent",
      "nameSpace": "",
      "isUsed": 0,
      "agreeTerms": 0,
      "canaryPublic": false,
      "enableMFA": false,
      "language": "zh",
      "tokenHoldTime": 86400,
      "tokenMaxValidDuration": 604800,
      "timezone": "",
      "attributes": {
        "部门": "研发部"
      },
      "customAttributes": {
        "costCenter": "CC-1001"
      },
      "statusPageSubs": 0,
      "defaultWorkspace": "",
      "brandKey": "guance",
      "scheduleMobile": "",
      "scheduleEmail": "",
      "ifScheduleMobileEnable": false,
      "ifScheduleEmailEnable": false,
      "accountStatus": ""
    },
    "roles": [
      {
        "uuid": "role_example001",
        "name": "示例最小权限角色"
      }
    ],
    "permissions": [
      "routine.defaultAccess"
    ],
    "rolePermissions": {
      "role_example001": [
        "routine.defaultAccess"
      ]
    }
  },
  "errorCode": "",
  "message": "",
  "success": true,
  "traceId": "TRACE-EXAMPLE"
}

错误响应

鉴权、限流和公共请求错误参见公共错误定义。

下表列出已确认的请求和业务分支。普通数据库/缓存/审计5xx经全局包装为ft.InternalServerError;写接口返回错误时,名称、Owner标志、角色或删除状态可能已经保存,须先查询现态再决定下一步。

HTTP 状态 errorCode 触发条件 消息或响应说明 处理方式
406 ft.ParameterValidationFailed 请求字段缺失,或字段值违反声明的校验条件 参数解析失败 核对参数位置、字段名、类型和取值。
404 ft.AKNotExistOrDelete UUID没有对应的活动非系统API Key,或Key已经删除/禁用 指定的AK不存在, 或已被删除 从列表重新获取目标uuid;注意列表不显示绑定账号Key,系统内置Key不能经此入口管理。
404 ft.AgentMemberNotFound 绑定账号UUID对应账号已不存在或已删除 未找到 agent 对应用户 从对应账号管理入口核对账号与Key绑定,不要把它作为手工Key处理。
403 ft.AgentMemberDisabled 绑定账号处于禁用状态 agent 对应用户已被禁用 先通过对应账号管理流程处理状态。
404 ft.WorkspaceAgentMemberNotFound 绑定账号没有该空间活动直接成员关系 该agent未找到agent对应用户 通过对应账号/Agent管理入口核对空间成员绑定。
500 ft.InternalServerError 数据库、缓存失效、审计或未处理的字段异常 内部错误 保留traceId并核对Key当前名称、角色和状态。数据可能先提交后失败,不能仅根据500视为未生效。

文档评价

文档内容是否对您有帮助?