itecdn 5.x用户文档
itecdn 5.x / 用户 API

更新指定四层转发

PUT/v1/streams/{stream_id}

更新一个四层转发。路径中的 stream_id 会覆盖请求体内的 ID,且请求体必须是 JSON 对象而不是数组;仅传需要修改的字段。普通用户只能更新自己的转发,管理员可修改归属用户、CNAME、区域与线路等资源字段。

身份认证

access-token

api-key + api-secret

认证定义
{
  "AccessToken": {
    "type": "apiKey",
    "in": "header",
    "name": "access-token",
    "description": "通过登录接口获得的短期访问令牌。"
  },
  "ApiKey": {
    "type": "apiKey",
    "in": "header",
    "name": "api-key",
    "description": "API Key;必须和 api-secret 同时发送。"
  },
  "ApiSecret": {
    "type": "apiKey",
    "in": "header",
    "name": "api-secret",
    "description": "API Secret;必须和 api-key 同时发送。"
  }
}

请求参数

参数位置类型必填说明与约束
stream_idpathinteger必填

要更新的四层转发 ID;必须存在且当前用户有权限操作。

完整参数定义
{
  "name": "stream_id",
  "in": "path",
  "required": true,
  "schema": {
    "type": "integer",
    "minimum": 1,
    "example": 101
  },
  "description": "要更新的四层转发 ID;必须存在且当前用户有权限操作。"
}

请求体 · 必填

application/json

object

单个转发更新对象;目标 ID 由路径决定。

字段类型必填说明与约束
user_packageinteger可选

用户套餐 ID。

listenarray <object>可选

完整监听列表。

展开字段结构

完整监听列表。

数组元素 · object
字段类型必填说明与约束
portinteger必填

监听端口。

约束 / 默认值 / 示例
{
  "minimum": 1,
  "maximum": 65535
}
protocolstring必填

监听协议。

约束 / 默认值 / 示例
{
  "enum": [
    "tcp",
    "udp"
  ]
}
backend_portinteger可选

回源端口。

约束 / 默认值 / 示例
{
  "minimum": 1,
  "maximum": 65535
}
backendarray <object>可选

完整源站列表;至少一个状态为 up。

展开字段结构

完整源站列表;至少一个状态为 up。

数组元素 · object
字段类型必填说明与约束
addrstring必填

源站地址。

weightinteger必填

权重。

约束 / 默认值 / 示例
{
  "minimum": 1,
  "maximum": 10
}
statestring必填

状态。

约束 / 默认值 / 示例
{
  "enum": [
    "up",
    "down",
    "backup"
  ]
}
balance_waystring可选

负载均衡方式。

约束 / 默认值 / 示例
{
  "enum": [
    "ip_hash",
    "rr"
  ]
}
proxy_protocolinteger可选

是否启用 PROXY protocol。

约束 / 默认值 / 示例
{
  "enum": [
    0,
    1
  ]
}
conn_limitinteger可选

连接数限制。

约束 / 默认值 / 示例
{
  "minimum": 0
}
aclobject可选

访问控制配置。

约束 / 默认值 / 示例
{
  "additionalProperties": false
}
展开字段结构

访问控制配置。

字段类型必填说明与约束
enableinteger可选

是否启用 ACL。

约束 / 默认值 / 示例
{
  "enum": [
    0,
    1
  ]
}
block_regionstring可选

地域拦截配置。

desstring可选

备注。

enableinteger可选

启用状态。

约束 / 默认值 / 示例
{
  "enum": [
    0,
    1
  ]
}
statestring可选

管理员专用。四层转发业务状态:200 正常、512 套餐到期、513 流量超限、514 锁定。

约束 / 默认值 / 示例
{
  "enum": [
    "200",
    "512",
    "513",
    "514"
  ]
}
enable_ipv6integer可选

是否启用 IPv6。

约束 / 默认值 / 示例
{
  "enum": [
    0,
    1
  ]
}
groupsstring可选

转发组 ID,逗号分隔;传空字符串移除关联。

uidinteger可选

管理员专用。指定操作用户。

cname_domaininteger可选

管理员专用。CNAME 域名配置 ID。

cname_modestring可选

管理员专用。CNAME 使用方式。

约束 / 默认值 / 示例
{
  "enum": [
    "package",
    "site"
  ]
}
cname_hostnamestring可选

管理员专用。CNAME 主机名。

region_idinteger可选

管理员专用。区域 ID。

node_group_idinteger可选

管理员专用。主线路组 ID。

backup_node_groupinteger可选

管理员专用。备用线路组 ID。

约束 / 默认值 / 示例
{
  "nullable": true
}
完整 Schema
{
  "type": "object",
  "description": "单个转发更新对象;目标 ID 由路径决定。",
  "additionalProperties": false,
  "properties": {
    "user_package": {
      "type": "integer",
      "description": "用户套餐 ID。"
    },
    "listen": {
      "type": "array",
      "description": "完整监听列表。",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "port",
          "protocol"
        ],
        "properties": {
          "port": {
            "type": "integer",
            "minimum": 1,
            "maximum": 65535,
            "description": "监听端口。"
          },
          "protocol": {
            "type": "string",
            "enum": [
              "tcp",
              "udp"
            ],
            "description": "监听协议。"
          }
        }
      }
    },
    "backend_port": {
      "type": "integer",
      "minimum": 1,
      "maximum": 65535,
      "description": "回源端口。"
    },
    "backend": {
      "type": "array",
      "description": "完整源站列表;至少一个状态为 `up`。",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "addr",
          "weight",
          "state"
        ],
        "properties": {
          "addr": {
            "type": "string",
            "description": "源站地址。"
          },
          "weight": {
            "type": "integer",
            "minimum": 1,
            "maximum": 10,
            "description": "权重。"
          },
          "state": {
            "type": "string",
            "enum": [
              "up",
              "down",
              "backup"
            ],
            "description": "状态。"
          }
        }
      }
    },
    "balance_way": {
      "type": "string",
      "enum": [
        "ip_hash",
        "rr"
      ],
      "description": "负载均衡方式。"
    },
    "proxy_protocol": {
      "type": "integer",
      "enum": [
        0,
        1
      ],
      "description": "是否启用 PROXY protocol。"
    },
    "conn_limit": {
      "type": "integer",
      "minimum": 0,
      "description": "连接数限制。"
    },
    "acl": {
      "type": "object",
      "description": "访问控制配置。",
      "additionalProperties": false,
      "properties": {
        "enable": {
          "type": "integer",
          "enum": [
            0,
            1
          ],
          "description": "是否启用 ACL。"
        }
      }
    },
    "block_region": {
      "type": "string",
      "description": "地域拦截配置。"
    },
    "des": {
      "type": "string",
      "description": "备注。"
    },
    "enable": {
      "type": "integer",
      "enum": [
        0,
        1
      ],
      "description": "启用状态。"
    },
    "state": {
      "type": "string",
      "enum": [
        "200",
        "512",
        "513",
        "514"
      ],
      "description": "管理员专用。四层转发业务状态:200 正常、512 套餐到期、513 流量超限、514 锁定。"
    },
    "enable_ipv6": {
      "type": "integer",
      "enum": [
        0,
        1
      ],
      "description": "是否启用 IPv6。"
    },
    "groups": {
      "type": "string",
      "description": "转发组 ID,逗号分隔;传空字符串移除关联。"
    },
    "uid": {
      "type": "integer",
      "description": "管理员专用。指定操作用户。"
    },
    "cname_domain": {
      "type": "integer",
      "description": "管理员专用。CNAME 域名配置 ID。"
    },
    "cname_mode": {
      "type": "string",
      "enum": [
        "package",
        "site"
      ],
      "description": "管理员专用。CNAME 使用方式。"
    },
    "cname_hostname": {
      "type": "string",
      "description": "管理员专用。CNAME 主机名。"
    },
    "region_id": {
      "type": "integer",
      "description": "管理员专用。区域 ID。"
    },
    "node_group_id": {
      "type": "integer",
      "description": "管理员专用。主线路组 ID。"
    },
    "backup_node_group": {
      "type": "integer",
      "nullable": true,
      "description": "管理员专用。备用线路组 ID。"
    }
  },
  "example": {
    "backend": [
      {
        "addr": "198.51.100.20",
        "weight": 1,
        "state": "up"
      }
    ],
    "enable": 1
  }
}

请求体示例

{
  "backend": [
    {
      "addr": "198.51.100.20",
      "weight": 1,
      "state": "up"
    }
  ],
  "enable": 1
}

响应

HTTP 200

请求已被处理。成功时 code 为 0、msg 为“更新转发成功”、data 为 null;请求体格式错误、转发不存在、权限不足或字段校验失败时仍返回 HTTP 200。

application/json

object

字段类型必填说明与约束
codeinteger必填

业务状态码;成功为 0。

约束 / 默认值 / 示例
{
  "example": 0
}
msgstring必填

处理结果说明。

约束 / 默认值 / 示例
{
  "example": "更新转发成功"
}
datastring必填

成功时为 null;失败时为空字符串。

约束 / 默认值 / 示例
{
  "nullable": true,
  "example": null
}
完整 Schema
{
  "type": "object",
  "required": [
    "code",
    "msg",
    "data"
  ],
  "properties": {
    "code": {
      "type": "integer",
      "description": "业务状态码;成功为 0。",
      "example": 0
    },
    "msg": {
      "type": "string",
      "description": "处理结果说明。",
      "example": "更新转发成功"
    },
    "data": {
      "type": "string",
      "nullable": true,
      "description": "成功时为 null;失败时为空字符串。",
      "example": null
    }
  }
}

示例

{
  "code": 0,
  "msg": "更新转发成功",
  "data": null
}

更新成功

{
  "code": 0,
  "msg": "更新转发成功",
  "data": null
}

请求体格式错误

{
  "code": "stream-8",
  "msg": "需要字典格式",
  "data": ""
}

cURL 示例

根据文档生成;请替换主控地址、路径参数和凭证,并按上表补充查询参数。

curl --request PUT \
  "https://master.example.invalid/v1/streams/{stream_id}" \
  --header "access-token: YOUR_ACCESS_TOKEN" \
  --header "Content-Type: application/json" \
  --data '{"backend": [{"addr": "198.51.100.20", "weight": 1, "state": "up"}], "enable": 1}'

查看完整接口 JSON