跳转至

修改



POST /api/v1/workspace/inner_accesskey/{workspace_uuid}/refresh

概述

重置空间内置系统Key的AK/SK,缺失时创建新Key。

调用前和使用步骤

需要w权限。先用工作空间列表确认活动空间,再用初始化并获取内置Key核对当前Key和依赖方。此入口本身不再次验证空间活动状态,缺少Key时会直接创建,因此不能把任意UUID传入来试探是否存在空间。已有Key时保留记录uuid,重新生成AK/SK并更新时间;缺失时创建Owner系统Key。无请求体,没有ttl宽限时间或只改名称的选项,每次刷新都会生成新凭据,不具备幂等性。失败后先核对当前凭据,不能盲目再次刷新。当前实现主动标记旧AK的认证缓存失效,没有同时主动清除旧SK缓存。若旧SK已有有效认证缓存,不能仅凭成功响应认定全部旧凭据已立即撤销;应由管理员核对缓存处理和实际鉴权结果。

路由参数

参数名 类型 必选 说明
workspace_uuid string Y 工作空间UUID,不是API Key记录UUID或明文AK/SK。
例子: wksp_example001
获取或填写方式: 从工作空间列表的content.data[].uuid取得,并核对站点和活动状态。

请求头

参数名 类型 必选 说明
X-Df-SVersion string 原始路径与请求体签名版本;不能省略后继续沿用本页算法。
例子: v20240417
获取或填写方式: 本页示例使用此固定版本,与示例签名算法配套。
X-Df-Access-Key string Y 本模块列表可用r或w权限;其他三项包括GET初始化均需要w权限。
例子: <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凭据,认证见External API 签名认证。列表允许r或w权限,其他三项包括GET初始化需要w权限。所有响应都可能返回高权限凭据明文,不应用普通前台页面的掩码展示规则;示例使用占位值,实际凭据应安全保管。缺失Key新建分支在flush前取返回快照,id、callCount、lastCallAt可能为null;已有Key分支则返回原记录资料和新凭据。

请求例子

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 = 'POST'
path = '/api/v1/workspace/inner_accesskey/wksp_example001/refresh'
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('请求结果未知,请先核对目标当前状态及是否已经写入,再决定是否重新签名重试;不要自动重复写请求。')
    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状态;本模块查询及删除选取status=0。
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 内置Key名称,初始化时为inner。
content.ak string 内置系统Access Key明文,按高权限凭据保管;不是External签名AK。
content.sk string 内置系统Secret Key明文,按高权限凭据保管;不是External签名SK。
content.workspaceUUID string 所属空间UUID。
content.accountUUID string 绑定账号标识,初始化的系统Key通常为空字符串。
content.createdWay string 创建来源,初始化通常manual;系统范围由isSystem/businessType区分。
content.businessType string 此模块只管理inner sys类型。
content.isSystem integer 此模块只管理系统内置Key,初始化为1。
content.isOwnerRole integer 初始化为1,具有Owner角色语义;与普通手工Owner Key分开管理。
content.remark string 既有备注,本模块没有修改备注的请求参数。
content.isBurnAfterReading integer 保留的阅后即焚标记;本模块不执行读取后销毁,不应依赖它撤销凭据。
content.callCount integer 或 null 持久累计调用次数;异步统计,非实时计数。创建快照在flush前可为null。
content.lastCallAt integer 或 null 最后调用Unix秒,通常-1表示暂无记录;创建快照可为null。
{
  "code": 200,
  "content": {
    "id": 1001,
    "uuid": "wsak_inner_example001",
    "status": 0,
    "creator": "external",
    "updator": "external",
    "createAt": 1785427200,
    "deleteAt": -1,
    "updateAt": 1785427200,
    "name": "inner",
    "ak": "<refreshed-inner-access-key>",
    "sk": "<refreshed-inner-secret-key>",
    "workspaceUUID": "wksp_example001",
    "accountUUID": "",
    "createdWay": "manual",
    "businessType": "inner sys",
    "isSystem": 1,
    "isOwnerRole": 1,
    "remark": "",
    "isBurnAfterReading": 0,
    "callCount": 0,
    "lastCallAt": -1
  },
  "errorCode": "",
  "message": "",
  "success": true,
  "traceId": "TRACE-EXAMPLE"
}

缺失Key时创建的快照示例:

{
  "code": 200,
  "content": {
    "id": null,
    "uuid": "wsak_inner_example001",
    "status": 0,
    "creator": "external",
    "updator": "",
    "createAt": 1785427200,
    "deleteAt": -1,
    "updateAt": -1,
    "name": "inner",
    "ak": "<inner-access-key>",
    "sk": "<inner-secret-key>",
    "workspaceUUID": "wksp_example001",
    "accountUUID": "",
    "createdWay": "manual",
    "businessType": "inner sys",
    "isSystem": 1,
    "isOwnerRole": 1,
    "remark": "",
    "isBurnAfterReading": 0,
    "callCount": null,
    "lastCallAt": null
  },
  "errorCode": "",
  "message": "",
  "success": true,
  "traceId": "TRACE-EXAMPLE"
}

错误响应

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

参数不符合声明时返回公共请求错误;数据库、缓存等普通内部异常最终统一为500 ft.InternalServerError。写请求失败后先核对持久状态与缓存,不保证全部没有生效。

HTTP 状态 errorCode 触发条件 消息或响应说明 处理方式
406 ft.ParameterValidationFailed 请求字段缺失,或字段值违反声明的校验条件 参数解析失败 核对参数位置、字段名、类型和取值。
500 ft.InternalServerError 数据库、缓存失效或未显式处理的内部异常 内部错误 保存traceId,先核对Key现态与实际调用结果再决定重试;数据库可能已提交,不能按错误响应认定没有变更。

文档评价

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