API Token
API Token 提供一種免賬號密碼訪問 Openresty Edge Admin API 的方式,
使用時,設定 HTTP 請求頭部: API-Token: {token}
,如 API-Token: 1df87165-3593-4eca-a910-9ac200012345
即可。
例如(注意替換下面例子中的 admin-host 為真實的 admin 域名 或 IP 地址):
curl "https://{admin-host}/admin-api/global/1/ngx/?detail=1" -H "API-token: 1df87165-3593-4eca-a910-9ac20005e6ec" -k
獲取 API Token 列表
簡介
獲取 API Token 列表
URI
GET /admin-api/api_token
URI 引數
start
type: integer
required: no
description: Start offset
end
type: integer
required: no
description: End offset
page
type: integer
required: no
description: Results page (default 1)
page_size
type: integer
required: no
description: Results page size (default 20)
detail
type: integer
required: no
description: Are detailed results required (default 0)
請求示例
curl 'http://{admin-site}/admin-api/api_token?start=0&end=19&page=1&page_size=20&detail=1'
響應示例
Status: 200 OK
{
"status":0,
"data":{
"data":[
{
"id":2,
"_created_unix":1618905030.9693,
"_modified_unix":1618905030.9693,
"name":"test",
"expire":1619769023072
},
{
"id":1,
"_created_unix":1618891253.4172,
"_modified_unix":1618891253.4172,
"name":"k8s-robots",
"expire":0 // 0 means never expires
}
],
"meta":{
"count":2
}
}
}
獲取 API Token
簡介
獲取 API Token
URI
GET /admin-api/api_token/{api-token-id}
URI 引數
detail
type: integer
required: no
description: Are detailed results required (default 0)
請求示例
curl 'http://{admin-site}/admin-api/api_token/2?detail=1'
響應示例
Status: 200 OK
{
"status":0,
"data":{
"id":2,
"_created_unix":1618905030.9693,
"_modified_unix":1618905030.9693,
"name":"test",
"expire":1619769023072
}
}
建立 API Token
簡介
建立 API Token
URI
POST /admin-api/api_token
JSON Body 引數
{
"name":"test-1",
"expire":1619682623072
}
請求示例
curl http://{admin-site}/admin-api/api_token \
-X 'POST' \
-H 'Content-Type: application/json;charset=UTF-8' \
--data-raw '{"name":"test-1","expire":1619682623072}'
響應示例
Status: 200 OK
{
"status":0,
"data":{
"id":3,
"token":"f8d486b5-a953-40b2-8508-e28893074bac",
"_modified_unix":1618907592.5399,
"_created_unix":1618907592.5399,
"uid":1,
"name":"test-1",
"expire":1619682623072
}
}
更新 API Token
簡介
更新 API Token
URI
PUT /admin-api/api_token/{api-token-id}
JSON Body 引數
{
"name":"test-1",
"expire":1619682623072
}
請求示例
curl http://{admin-site}/admin-api/api_token/2 \
-X 'PUT' \
-H 'Content-Type: application/json;charset=UTF-8' \
--data-raw '{"name":"test-1","expire":1619682623072}'
響應示例
Status: 200 OK
{"status":0}
刪除 API Token
簡介
刪除 API Token
URI
DELETE /admin-api/api_token/{api-token-id}
請求示例
curl http://{admin-site}/admin-api/api_token/2 \
-X 'DELETE'
響應示例
Status: 200 OK
{"status":0}