更新函数配置¶
1. 接口描述¶
接口请求路径:POST /prod-api/cdn/layer7/function/modifyFunction
modifyFunction 用于按 functionName 更新域名下的函数配置。functionArgs 的 argName、argValue 须与 查询函数配置 中同名字段一致。
Token 获取方式见 密钥鉴权。
2. 输入参数¶
以下请求参数列表仅列出了接口请求参数和部分公共参数,完整公共参数列表见 公共请求参数。
| 参数名称 | 必选 | 类型 | 描述 |
|---|---|---|---|
| domainId | 是 | Integer | 域名 ID 示例值: 215 |
| functions | 否 | [Function] | 待更新的函数配置列表 |
3. 示例¶
示例1 更新 IP 白名单¶
输入示例¶
{
"domainId": 215,
"functions": [
{
"functionArgs": [
{
"argName": "values",
"argValue": "[\"1.1.1.1\",\"22.2.2.2\"]"
}
],
"functionName": "IPWhitelist"
}
]
}
代码调用¶
请将 {登录域名}、token 替换为实际值。
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
public class ModifyFunctionTest {
public static void main(String[] args) throws Exception {
String url = "https://{登录域名}/prod-api/cdn/layer7/function/modifyFunction";
String token = "eyJhbGciOiJIUzUxMiJ9.xxxxxx";
String requestBody = "{"
+ "\"domainId\":215,"
+ "\"functions\":["
+ "{\"functionArgs\":[{\"argName\":\"values\",\"argValue\":\"[\\\"1.1.1.1\\\",\\\"22.2.2.2\\\"]\"}],"
+ "\"functionName\":\"IPWhitelist\"}"
+ "]}";
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
HttpPost httpPost = new HttpPost(url);
httpPost.setHeader("Authorization", "Bearer " + token);
httpPost.setEntity(new StringEntity(requestBody, ContentType.APPLICATION_JSON));
try (CloseableHttpResponse response = httpClient.execute(httpPost)) {
int statusCode = response.getStatusLine().getStatusCode();
String body = EntityUtils.toString(response.getEntity(), "UTF-8");
System.out.println("Status Code: " + statusCode);
System.out.println("Body: " + body);
}
}
}
}
package main
import (
"bytes"
"fmt"
"io"
"net/http"
)
func main() {
url := "https://{登录域名}/prod-api/cdn/layer7/function/modifyFunction"
token := "eyJhbGciOiJIUzUxMiJ9.xxxxxx"
requestBody := []byte(`{
"domainId": 215,
"functions": [
{
"functionArgs": [
{
"argName": "values",
"argValue": "[\"1.1.1.1\",\"22.2.2.2\"]"
}
],
"functionName": "IPWhitelist"
}
]
}`)
req, err := http.NewRequest(http.MethodPost, url, bytes.NewReader(requestBody))
if err != nil {
panic(err)
}
req.Header.Set("Authorization", "Bearer "+token)
req.Header.Set("Content-Type", "application/json")
resp, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
panic(err)
}
fmt.Println("Status Code:", resp.StatusCode)
fmt.Println("Body:", string(body))
}
输出示例¶
其他常用请求示例:
更新 HTTP/3
{
"domainId": 215,
"functions": [
{
"functionArgs": [
{
"argName": "status",
"argValue": 0
}
],
"functionName": "http3"
}
]
}
更新 TLS 版本
{
"domainId": 215,
"functions": [
{
"functionArgs": [
{
"argName": "status",
"argValue": 0
}
],
"functionName": "tls_version"
}
]
}
4. 输出参数¶
| 参数名称 | 类型 | 描述 |
|---|---|---|
| code | Integer | 状态码。示例值:200 |
| msg | String | 提示信息。示例值:更新成功 |
5. functionArgs 填写说明¶
根据 functionName 填写对应的 functionArgs:
functionName |
argName |
argValue |
说明 |
|---|---|---|---|
IPWhitelist |
values |
字符串 | IP 列表 JSON 字符串,如 "[\"1.1.1.1\"]";清空传 "" |
http3 |
status |
整数 0 或 1 |
0:开启;1:关闭 |
tls_version |
status |
整数 0 或 1 |
0:开启 TLS 1.0 / 1.1 / 1.2;1:开启 TLS 1.2 / 1.3 |
更新已有配置时,可在 Function 中传入 查询函数配置 返回的 functionId。
6. 错误码¶
| HTTP 状态码 / 业务提示 | 描述 |
|---|---|
| 200 | 成功 |
| 401 | 未鉴权或 Token 无效 |
| 403 | 无权限 |
| 域名id不能为空 | 未传 domainId |
| 错误的values格式 | IP 白名单 values 不是合法 JSON 字符串 |
| 存在重复的IP:{0} | IP 白名单中存在重复 IP |
| 存在无效的IP:{0} | IP 白名单中存在无效 IP |
7. 数据模型¶
Function¶
函数配置项。
| 参数名称 | 必选 | 类型 | 描述 |
|---|---|---|---|
| functionName | 是 | String | 函数名称。取值:IPWhitelist、http3、tls_version 等示例值: IPWhitelist |
| functionId | 否 | Integer | 函数 ID。更新已有配置时传入,与查询返回的 functionId 一致 |
| functionArgs | 是 | [FunctionArg] | 函数参数列表,字段含义见上方填写说明 |
FunctionArg¶
函数参数。
| 参数名称 | 必选 | 类型 | 描述 |
|---|---|---|---|
| argName | 是 | String | 参数名。白名单为 values;http3、tls_version 为 status |
| argValue | 是 | String / Integer | 参数值。白名单为字符串;开关类为整数 0 或 1,含义见上方对照表 |