# 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)

# 请求示例
# Shell

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)

# 请求示例
# Shell

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
    }
}

# Create API token

# 简介

创建 API token

# URI
POST /admin-api/api_token
# JSON Body 参数
{
    "name":"test-1",
    "expire":1619682623072
}
# 请求示例
# Shell
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
}
# 请求示例
# Shell
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}
# 请求示例
# Shell
curl  http://{admin-site}/admin-api/api_token/2 \
  -X 'DELETE'
# 响应示例
Status: 200 OK
{"status":0}