Updating a Rule in the Rules Engine
Function
This API is used to update a rule in the rules engine.
Calling Method
For details, see Calling APIs.
URI
PUT /v1.0/cdn/configuration/domains/{domain_name}/rules/{rule_id}
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
domain_name |
Yes |
String |
Definition Acceleration domain name. Constraints N/A Range N/A Default Value N/A |
|
rule_id |
Yes |
String |
Definition Rule ID, which can be obtained by calling the API for listing rules in the rules engine. Constraints N/A Range N/A Default Value N/A |
Request Parameters
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
name |
Yes |
String |
Definition Rule name. Constraints N/A Range 1 to 50 characters. Default Value N/A |
|
status |
Yes |
String |
Definition Whether the rule is enabled. Constraints N/A Range Default Value N/A |
|
priority |
Yes |
Integer |
Definition Rule priority. A larger value indicates a higher priority. Constraints The priority of a rule must be unique. Range 1 to 100. Default Value N/A |
|
conditions |
Yes |
Conditions object |
Definition Conditions for triggering the rule. Constraints N/A |
|
actions |
Yes |
Array of Actions objects |
Definition Action to be executed when the rule conditions are met. Constraints N/A |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
match |
Yes |
Match object |
Definition Rule conditions. Constraints N/A |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
logic |
Yes |
String |
Definition Logical operator. Constraints N/A Range Default Value N/A |
|
criteria |
Yes |
Array of Criteria objects |
Definition Match condition list. Constraints N/A |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
match_target_type |
No |
String |
Definition Match target type. Constraints N/A Range Default Value N/A |
|
match_target_name |
No |
String |
Definition Match target name. Constraints N/A Range
Default Value N/A |
|
match_type |
No |
String |
Definition Match algorithm. Constraints N/A Range contains: Any condition specified in match_pattern is matched. Default Value N/A |
|
match_pattern |
No |
Array of strings |
Definition Match content. Constraints N/A Range
Default Value N/A |
|
negate |
No |
Boolean |
Definition Whether to perform negation. This parameter is used together with match_type. For example, if negate is set to true and match_type is set to contains, the actual service logic is converted to not_contains. Constraints N/A Range Default Value false |
|
case_sensitive |
No |
Boolean |
Definition Case insensitive or not. Constraints N/A Range Default Value false |
|
logic |
No |
String |
Definition Nested condition logic operator. Constraints N/A Range Default Value N/A |
|
criteria |
No |
Array of Criteria objects |
Definition Nested condition list. Constraints N/A |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
flexible_origin |
No |
Array of flexibleOriginsEngine objects |
Definition Advanced origin rules. CDN can pull content from different origin servers by resource type or path. Constraints Up to 20 rules. |
|
origin_request_header |
No |
Array of OriginRequestHeader objects |
Definition Rewrite the HTTP headers in request URLs during CDN PoP origin pull. Constraints |
|
http_response_header |
No |
Array of HttpResponseHeader objects |
Definition Headers returned by PoPs to clients. CDN includes them in responses to user requests for resources within that domain name. Constraints |
|
access_control |
No |
AccessControl object |
Definition Access control. Constraints N/A |
|
request_limit_rule |
No |
RequestLimitRulesEngine object |
Definition Request rate limiting. This limits the user request rate within a specific range to reduce costs and the risk of burst bandwidth. Constraints N/A |
|
origin_request_url_rewrite |
No |
Definition Origin request URL rewrite. Constraints Up to 20 rules. |
|
|
cache_rule |
No |
CacheRulesEngine object |
Definition Parameters used to control the cache TTL of origin server resources on CDN PoPs. Constraints N/A |
|
request_url_rewrite |
No |
RequestUrlRewriteEngine object |
Definition Access URL rewrite rules, which are used to redirect user requests to the URLs of cached content. Constraints N/A |
|
browser_cache_rule |
No |
BrowserCacheRulesEngine object |
Definition Browser cache TTL, during which users can obtain content directly from their browser cache (if available). Constraints N/A |
|
error_code_cache |
No |
Array of ErrorCodeCacheEngine objects |
Definition You can cache error codes returned by the origin server on CDN PoPs. When users request the same resources, CDN directly returns the error codes to the users. Constraints N/A |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
sources_type |
Yes |
String |
Definition Origin server type. Constraints N/A Range Default Value N/A |
|
ip_or_domain |
Yes |
String |
Definition IP address or domain name of the origin server. Constraints N/A Range N/A Default Value N/A |
|
obs_bucket_type |
No |
String |
Definition OBS bucket type. Constraints Mandatory when the origin server is an OBS bucket. Range Default Value public |
|
bucket_access_key |
No |
String |
Definition Access key of the third-party bucket. Constraints Mandatory when the origin server is a third-party bucket. Range N/A Default Value N/A |
|
bucket_secret_key |
No |
String |
Definition Secret key of the third-party bucket. Constraints Mandatory when the origin server is a third-party bucket. Range N/A Default Value N/A |
|
bucket_region |
No |
String |
Definition Region of the third-party bucket. Constraints Mandatory when the origin server is a third-party bucket. Range N/A Default Value N/A |
|
bucket_name |
No |
String |
Definition Name of the third-party bucket. Constraints Mandatory when the origin server is a third-party bucket. Range N/A Default Value N/A |
|
host_name |
No |
String |
Definition Host header. Constraints N/A Range N/A Default Value Acceleration domain name. |
|
origin_protocol |
No |
String |
Definition Request protocol for CDN origin pull. Constraints N/A Range Default Value http |
|
http_port |
No |
Integer |
Definition HTTP port. Constraints N/A Range 1 to 65,535. Default Value 80 |
|
https_port |
No |
Integer |
Definition HTTPS port. Constraints N/A Range 1 to 65,535. Default Value 443 |
|
priority |
Yes |
Integer |
Definition Priority. A larger value indicates a higher priority. Constraints N/A Range 1 to 100. Default Value N/A |
|
weight |
Yes |
Integer |
Definition Weight. A larger value indicates that content is pulled from this origin server more frequently. If there are multiple origin servers with the same priority, the weight determines the proportion of content pulled from each origin server. Constraints N/A Range 1 to 100. Default Value N/A |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
type |
Yes |
String |
Definition Access control type. Constraints N/A Range Default Value N/A |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
limit_rate_after |
Yes |
Long |
Definition Rate limit condition.
NOTE:
For example, type=size,limit_rate_after=50 indicates that the speed is limited to the value of limit_rate_value after 50 bytes are transmitted.
Constraints N/A Range 0 to 1,073,741,824, in bytes. Default Value N/A |
|
limit_rate_value |
Yes |
Integer |
Definition Rate limit, that is, the maximum access speed after the rate limit is reached. Constraints N/A Range 0 to 104,857,600, in bit/s. Default Value N/A |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
code |
Yes |
Integer |
Definition Error codes to cache. Constraints N/A Range Default Value N/A |
|
ttl |
Yes |
Integer |
Definition Error code cache TTL. Constraints N/A Range 0 to 31,536,000, in seconds.
NOTE:
The cache TTL of 3XX status codes ranges from 0s to 20s.
Default Value N/A |
Response Parameters
Status code: 204
Request succeeded.
None
Example Requests
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"
}
} ]
}
Example Responses
None
SDK Sample Code
The SDK sample code is as follows.
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<CriteriaItem> listMatchCriteria = new ArrayList<>(); listMatchCriteria.add( new CriteriaItem() .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 = [ CriteriaItem( 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 76 77 78 79 80 81 82 83 84 85 86 87 |
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, err := global.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). SafeBuild() if err != nil { fmt.Println(err) return } hcClient, err := cdn.CdnClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). SafeBuild() if err != nil { fmt.Println(err) return } client := cdn.NewCdnClient(hcClient) request := &model.UpdateRuleNewRequest{} request.DomainName = "{domain_name}" request.RuleId = "{rule_id}" accessControlActions := &model.AccessControl{ Type: "block", } var listActionsbody = []model.Actions{ { AccessControl: accessControlActions, }, } var listMatchPatternCriteria = []string{ "HTTP", } matchTargetTypeCriteria:= "scheme" matchTypeCriteria:= "contains" negateCriteria:= false caseSensitiveCriteria:= false var listCriteriaMatch = []model.CriteriaItem{ { 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) } } |
For SDK sample code of more programming languages, see the Sample Code tab in API Explorer. SDK sample code can be automatically generated.
Status Codes
|
Status Code |
Description |
|---|---|
|
204 |
Request succeeded. |
Error Codes
See Error Codes.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot