更新规则引擎规则
功能介绍
更新规则引擎规则。
调用方法
请参见如何调用API。
URI
PUT /v1.0/cdn/configuration/domains/{domain_name}/rules/{rule_id}
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
domain_name |
是 |
String |
参数解释: 加速域名 约束限制: 不涉及 取值范围: 不涉及 默认取值: 不涉及 |
rule_id |
是 |
String |
参数解释: 规则ID,可以通过查询规则引擎列表接口获取 约束限制: 不涉及 取值范围: 不涉及 默认取值: 不涉及 |
请求参数
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
name |
是 |
String |
参数解释: 规则名称 约束限制: 不涉及 取值范围: 1-50个字符 默认取值: 不涉及 |
status |
是 |
String |
参数解释: 是否开启规则 约束限制: 不涉及 取值范围:
默认取值: 不涉及 |
priority |
是 |
Integer |
参数解释: 此条规则的优先级,数值越大,优先级越高 约束限制: 优先级不能相同 取值范围: 1-100 默认取值: 不涉及 |
conditions |
是 |
Conditions object |
参数解释: 触发当前规则的条件 约束限制: 不涉及 |
actions |
是 |
Array of Actions objects |
参数解释: 满足规则条件后执行的动作 约束限制: 不涉及 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
logic |
是 |
String |
参数解释: 逻辑运算符 约束限制: 不涉及 取值范围:
默认取值: 不涉及 |
criteria |
是 |
Array of Criteria objects |
参数解释: 匹配条件列表 约束限制: 不涉及 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
match_target_type |
否 |
String |
参数解释: 匹配目标类型 约束限制: 不涉及 取值范围:
默认取值: 不涉及 |
match_target_name |
否 |
String |
参数解释: 匹配目标名称 约束限制: 不涉及 取值范围:
默认取值: 不涉及 |
match_type |
否 |
String |
参数解释: 匹配算法 约束限制: 不涉及 取值范围: contains:包含匹配,匹配到match_pattern任意一个条件即匹配成功 默认取值: 不涉及 |
match_pattern |
否 |
Array of strings |
参数解释: 匹配内容 约束限制: 不涉及 取值范围:
默认取值: 不涉及 |
negate |
否 |
Boolean |
参数解释: 是否取反,与match_type配合使用。例:negate配置为true,match_type配置为contains,则实际业务逻辑将转换为not_contains 约束限制: 不涉及 取值范围:
默认取值: false: 不取反 |
case_sensitive |
否 |
Boolean |
参数解释: 是否区分大小写 约束限制: 不涉及 取值范围:
默认取值: false: 不区分大小写 |
logic |
否 |
String |
参数解释: 嵌套条件逻辑运算符 约束限制: 不涉及 取值范围:
默认取值: 不涉及 |
criteria |
否 |
Array of Criteria objects |
参数解释: 嵌套条件列表 约束限制: 不涉及 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
flexible_origin |
否 |
Array of flexibleOriginsEngine objects |
参数解释: 高级回源,实现根据不同的资源类型或路径回源到不同源站 约束限制: 最多配置20条 |
origin_request_header |
否 |
Array of OriginRequestHeader objects |
参数解释: CDN节点回源时,改写用户回源请求URL的HTTP头部信息 约束限制:
|
http_response_header |
否 |
Array of HttpResponseHeader objects |
参数解释: 配置节点响应给客户端的头部信息,配置响应消息后,用户请求加速域名下的资源时,CDN返回给用户的消息中将包含该域名配置的响应头信息 约束限制:
|
access_control |
否 |
AccessControl object |
参数解释: 访问控制 约束限制: 不涉及 |
request_limit_rules |
否 |
RequestLimitRulesEngine object |
参数解释: 请求限速,将用户请求速度限制在指定范围内,一定程度上减少突发高带宽风险,节省成本 约束限制: 不涉及 |
origin_request_url_rewrite |
否 |
参数解释: 改写回源URL 约束限制: 最多配置20条 |
|
cache_rule |
否 |
CacheRulesEngine object |
参数解释: 通过不同参数控制源站资源在CDN节点的缓存时长 约束限制: 不涉及 |
request_url_rewrite |
否 |
RequestUrlRewriteEngine object |
参数解释: 访问URL重写,当用户请求URL与CDN节点缓存资源的URL不一致时,可以通过访问URL重写功能重定向到目标URL 约束限制: 不涉及 |
browser_cache_rule |
否 |
BrowserCacheRulesEngine object |
参数解释: 浏览器缓存过期时间,当终端用户请求资源时,如果浏览器有缓存,直接返回给用户 约束限制: 不涉及 |
error_code_cache |
否 |
ErrorCodeCacheEngine object |
参数解释: 将源站返回的错误状态码缓存到CDN节点,用户再次请求时由CDN直接响应给用户错误状态码 约束限制: 不涉及 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
sources_type |
是 |
String |
参数解释: 源站类型 约束限制: 不涉及 取值范围:
默认取值: 不涉及 |
ip_or_domain |
是 |
String |
参数解释: 源站IP或者域名 约束限制: 不涉及 取值范围: 不涉及 默认取值: 不涉及 |
obs_bucket_type |
否 |
String |
参数解释: OBS桶类型 约束限制: 源站类型是“OBS桶域名”时需要传该参数 取值范围:
默认取值: public: 公有桶 |
bucket_access_key |
否 |
String |
参数解释: 第三方对象存储访问密钥 约束限制: 源站类型为第三方桶时必填 取值范围: 不涉及 默认取值: 不涉及 |
bucket_secret_key |
否 |
String |
参数解释: 第三方对象存储密钥 约束限制: 源站类型为第三方桶时必填 取值范围: 不涉及 默认取值: 不涉及 |
bucket_region |
否 |
String |
参数解释: 第三方对象存储区域 约束限制: 源站类型为第三方桶时必填 取值范围: 不涉及 默认取值: 不涉及 |
bucket_name |
否 |
String |
参数解释: 第三方对象存储名称 约束限制: 源站类型为第三方桶时必填 取值范围: 不涉及 默认取值: 不涉及 |
host_name |
否 |
String |
参数解释: 回源HOST 约束限制: 不涉及 取值范围: 不涉及 默认取值: 加速域名 |
origin_protocol |
否 |
String |
参数解释: 指定CDN回源时的请求协议 约束限制: 不涉及 取值范围:
默认取值: http: http协议 |
http_port |
否 |
Integer |
参数解释: HTTP端口 约束限制: 不涉及 取值范围: 1-65535 默认取值: 80 |
https_port |
否 |
Integer |
参数解释: HTTPS端口 约束限制: 不涉及 取值范围: 1-65535 默认取值: 443 |
priority |
是 |
Integer |
参数解释: 优先级,值越大优先级越高 约束限制: 不涉及 取值范围: 1-100 默认取值: 不涉及 |
weight |
是 |
Integer |
参数解释: 权重,值越大回源到该源站的次数越多。多个优先级相同的源站,由权重决定回源到各个源站的比例 约束限制: 不涉及 取值范围: 1-100 默认取值: 不涉及 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
name |
是 |
String |
参数解释: 设置回源请求头参数 约束限制: 不涉及 取值范围:
默认取值: 不涉及 |
value |
否 |
String |
参数解释: 设置回源请求头参数的值 约束限制: 不涉及 取值范围:
默认取值: 不涉及 |
action |
是 |
String |
参数解释: 回源请求头设置类型 约束限制:
取值范围:
默认取值: 不涉及 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
name |
是 |
String |
参数解释: 设置HTTP响应头参数 约束限制: 不涉及 取值范围:
默认取值: 不涉及 |
value |
否 |
String |
参数解释: 设置HTTP响应头参数的值 约束限制: 不涉及 取值范围:
默认取值: 不涉及 |
action |
是 |
String |
参数解释: 设置HTTP响应头操作类型 约束限制:
取值范围:
默认取值: 不涉及 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
type |
是 |
String |
参数解释: 访问控制类型 约束限制: 不涉及 取值范围:
默认取值: 不涉及 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
limit_rate_after |
是 |
Long |
参数解释: 限速条件
说明:
例如:type=size,limit_rate_after=50表示从传输50个字节后开始限速且限速值为limit_rate_value
约束限制: 不涉及 取值范围: 0-1073741824,单位:byte 默认取值: 不涉及 |
limit_rate_value |
是 |
Integer |
参数解释: 限速值,即达到限速条件后的最大访问速度 约束限制: 不涉及 取值范围: 0-104857600,单位:Bps 默认取值: 不涉及 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
rewrite_type |
是 |
String |
参数解释: 改写方式 约束限制: 不涉及 取值范围:
默认取值: 不涉及 |
source_url |
否 |
String |
参数解释: 需要替换的URI 约束限制: 当rewrite_type为wildcard或regex时,该参数必填 当rewrite_type为regex时,该参数必填必须以“^/”开始,如:^/test 取值范围:
默认取值: 不涉及 |
target_url |
是 |
String |
参数解释: 替换后的URI 约束限制: 取值范围:
说明:
通配符 * 可通过$n捕获(n=1,2,3...,例如:/newtest/$1/$2.jpg)
默认取值: 不涉及 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
ttl |
是 |
Integer |
参数解释: 资源在CDN节点的缓存过期时间 约束限制: 最大支持365天 取值范围: 不涉及 默认取值: 不涉及 |
ttl_unit |
是 |
String |
参数解释: 缓存过期时间单位 约束限制: 不涉及 取值范围:
默认取值: 不涉及 |
follow_origin |
是 |
String |
参数解释: 缓存过期时间来源,设置CDN节点的缓存遵循源站还是CDN侧的配置 约束限制: 不涉及 取值范围:
默认取值: off: CDN节点的缓存过期时间遵循“缓存规则”中的“缓存过期时间” |
force_cache |
否 |
String |
参数解释: 强制缓存:CDN节点缓存过期时间是否忽略源站响应头Cache-Control中的no-cache、private、no-store字段 约束限制: 强制缓存与缓存过期时间来源功能配合使用,具体使用限制及配置效果请参考CDN用户指南的配置节点缓存规则章节 取值范围:
默认取值: off: 关闭强制缓存 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
redirect_status_code |
否 |
Integer |
参数解释: 重定向状态码 约束限制: 不涉及 取值范围:
默认取值: 不涉及 |
redirect_url |
是 |
String |
参数解释: 重定向URL 约束限制:
取值范围: 不涉及 默认取值: 不涉及 |
redirect_host |
是 |
String |
参数解释: 支持将客户端请求重定向到其他域名 约束限制: 不涉及 取值范围:
默认取值: 不填时默认为当前域名 |
execution_mode |
是 |
String |
参数解释: 执行规则 约束限制: 不涉及 取值范围:
默认取值: 不涉及 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
cache_type |
是 |
String |
参数解释: 缓存生效类型 约束限制: 不涉及 取值范围:
默认取值: 不涉及 |
ttl |
否 |
Integer |
参数解释: 缓存过期时间 约束限制:
取值范围: 不涉及 默认取值: 不涉及 |
ttl_unit |
否 |
String |
参数解释: 缓存过期时间单位 约束限制: 当缓存生效类型为ttl时必填 取值范围:
默认取值: 不涉及 |
响应参数
状态码:204
请求成功
无
请求示例
PUT https://cdn.myhuaweicloud.com/v1.0/cdn/configuration/domains/www.example/rules/example*******************ruleid { "name" : "example", "status" : "on", "priority" : 1, "conditions" : { "match" : { "logic" : "and", "criteria" : [ { "match_target_type" : "scheme", "match_type" : "contains", "match_pattern" : [ "HTTP" ], "negate" : false, "case_sensitive" : false } ] } }, "actions" : [ { "access_control" : { "type" : "block" } } ] }
响应示例
无
SDK代码示例
SDK代码示例如下。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
package com.huaweicloud.sdk.test; import com.huaweicloud.sdk.core.auth.ICredential; import com.huaweicloud.sdk.core.auth.GlobalCredentials; import com.huaweicloud.sdk.core.exception.ConnectionException; import com.huaweicloud.sdk.core.exception.RequestTimeoutException; import com.huaweicloud.sdk.core.exception.ServiceResponseException; import com.huaweicloud.sdk.cdn.v2.region.CdnRegion; import com.huaweicloud.sdk.cdn.v2.*; import com.huaweicloud.sdk.cdn.v2.model.*; import java.util.List; import java.util.ArrayList; public class UpdateRuleNewSolution { public static void main(String[] args) { // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment String ak = System.getenv("CLOUD_SDK_AK"); String sk = System.getenv("CLOUD_SDK_SK"); ICredential auth = new GlobalCredentials() .withAk(ak) .withSk(sk); CdnClient client = CdnClient.newBuilder() .withCredential(auth) .withRegion(CdnRegion.valueOf("<YOUR REGION>")) .build(); UpdateRuleNewRequest request = new UpdateRuleNewRequest(); request.withDomainName("{domain_name}"); request.withRuleId("{rule_id}"); UpdateRuleRequest body = new UpdateRuleRequest(); AccessControl accessControlActions = new AccessControl(); accessControlActions.withType("block"); List<Actions> listbodyActions = new ArrayList<>(); listbodyActions.add( new Actions() .withAccessControl(accessControlActions) ); List<String> listCriteriaMatchPattern = new ArrayList<>(); listCriteriaMatchPattern.add("HTTP"); List<Criteria> listMatchCriteria = new ArrayList<>(); listMatchCriteria.add( new Criteria() .withMatchTargetType("scheme") .withMatchType("contains") .withMatchPattern(listCriteriaMatchPattern) .withNegate(false) .withCaseSensitive(false) ); Match matchConditions = new Match(); matchConditions.withLogic("and") .withCriteria(listMatchCriteria); Conditions conditionsbody = new Conditions(); conditionsbody.withMatch(matchConditions); body.withActions(listbodyActions); body.withConditions(conditionsbody); body.withPriority(1); body.withStatus("on"); body.withName("example"); request.withBody(body); try { UpdateRuleNewResponse response = client.updateRuleNew(request); System.out.println(response.toString()); } catch (ConnectionException e) { e.printStackTrace(); } catch (RequestTimeoutException e) { e.printStackTrace(); } catch (ServiceResponseException e) { e.printStackTrace(); System.out.println(e.getHttpStatusCode()); System.out.println(e.getRequestId()); System.out.println(e.getErrorCode()); System.out.println(e.getErrorMsg()); } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# coding: utf-8 import os from huaweicloudsdkcore.auth.credentials import GlobalCredentials from huaweicloudsdkcdn.v2.region.cdn_region import CdnRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkcdn.v2 import * if __name__ == "__main__": # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment ak = os.environ["CLOUD_SDK_AK"] sk = os.environ["CLOUD_SDK_SK"] credentials = GlobalCredentials(ak, sk) client = CdnClient.new_builder() \ .with_credentials(credentials) \ .with_region(CdnRegion.value_of("<YOUR REGION>")) \ .build() try: request = UpdateRuleNewRequest() request.domain_name = "{domain_name}" request.rule_id = "{rule_id}" accessControlActions = AccessControl( type="block" ) listActionsbody = [ Actions( access_control=accessControlActions ) ] listMatchPatternCriteria = [ "HTTP" ] listCriteriaMatch = [ Criteria( match_target_type="scheme", match_type="contains", match_pattern=listMatchPatternCriteria, negate=False, case_sensitive=False ) ] matchConditions = Match( logic="and", criteria=listCriteriaMatch ) conditionsbody = Conditions( match=matchConditions ) request.body = UpdateRuleRequest( actions=listActionsbody, conditions=conditionsbody, priority=1, status="on", name="example" ) response = client.update_rule_new(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/global" cdn "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cdn/v2" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cdn/v2/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cdn/v2/region" ) func main() { // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment ak := os.Getenv("CLOUD_SDK_AK") sk := os.Getenv("CLOUD_SDK_SK") auth := global.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). Build() client := cdn.NewCdnClient( cdn.CdnClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). Build()) request := &model.UpdateRuleNewRequest{} request.DomainName = "{domain_name}" request.RuleId = "{rule_id}" accessControlActions := &model.AccessControl{ Type: "block", } var listActionsbody = []model.Actions{ { AccessControl: accessControlActions, }, } var listMatchPatternCriteria = List{ "HTTP", } matchTargetTypeCriteria:= "scheme" matchTypeCriteria:= "contains" negateCriteria:= false caseSensitiveCriteria:= false var listCriteriaMatch = []model.Criteria{ { MatchTargetType: &matchTargetTypeCriteria, MatchType: &matchTypeCriteria, MatchPattern: &listMatchPatternCriteria, Negate: &negateCriteria, CaseSensitive: &caseSensitiveCriteria, }, } matchConditions := &model.Match{ Logic: "and", Criteria: listCriteriaMatch, } conditionsbody := &model.Conditions{ Match: matchConditions, } request.Body = &model.UpdateRuleRequest{ Actions: listActionsbody, Conditions: conditionsbody, Priority: int32(1), Status: "on", Name: "example", } response, err := client.UpdateRuleNew(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } } |
更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。
状态码
状态码 |
描述 |
---|---|
204 |
请求成功 |
错误码
请参见错误码。