Listing Rules in the Rules Engine
Function
This API is used to list rules in the rules engine.
Calling Method
For details, see Calling APIs.
URI
GET /v1.0/cdn/configuration/domains/{domain_name}/rules
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| domain_name | Yes | String | Definition Acceleration domain name. Constraints N/A Range N/A Default Value N/A |
Request Parameters
None
Response Parameters
Status code: 200
| Parameter | Type | Description |
|---|---|---|
| rules | Array of RuleResponse objects | Rule list. |
| Parameter | Type | Description |
|---|---|---|
| rule_id | String | Rule ID. |
| name | String | Rule name. |
| status | String | Rule status. The value can be on (enabled) or off (disabled). |
| priority | Integer | Rule priority. A larger value indicates a higher priority. |
| conditions | Conditions object | Definition Conditions for triggering the rule. |
| actions | Array of Actions objects | Actions to be executed when the rule conditions are met. |
| Parameter | Type | Description |
|---|---|---|
| logic | String | Definition Logical operator. Range |
| criteria | Array of Criteria objects | Definition Match condition list. |
| Parameter | Type | Description |
|---|---|---|
| match_target_type | String | Definition Match target type. Range |
| match_target_name | String | Definition Match target name. Range
|
| match_type | String | Definition Match algorithm. Range contains: Any condition specified in match_pattern is matched. |
| match_pattern | Array of strings | Definition Match content. Range
|
| negate | 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. Range |
| case_sensitive | Boolean | Definition Case insensitive or not. Range |
| logic | String | Definition Nested condition logic operator. Range |
| criteria | Array of Criteria objects | Definition Nested condition list. |
| Parameter | Type | Description |
|---|---|---|
| flexible_origin | Array of flexibleOriginsEngine objects | Definition Advanced origin rules. CDN can pull content from different origin servers by resource type or path. |
| origin_request_header | Array of OriginRequestHeader objects | Definition Rewrite the HTTP headers in request URLs during CDN PoP origin pull. |
| http_response_header | 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. |
| access_control | AccessControl object | Definition Access control. |
| request_limit_rule | 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. |
| origin_request_url_rewrite | Definition Origin request URL rewrite. | |
| cache_rule | CacheRulesEngine object | Definition Parameters used to control the cache TTL of origin server resources on CDN PoPs. |
| request_url_rewrite | RequestUrlRewriteEngine object | Definition Access URL rewrite rules, which are used to redirect user requests to the URLs of cached content. |
| browser_cache_rule | BrowserCacheRulesEngine object | Definition Browser cache TTL, during which users can obtain content directly from their browser cache (if available). |
| error_code_cache | 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. |
| Parameter | Type | Description |
|---|---|---|
| sources_type | String | Definition Origin server type. Range |
| ip_or_domain | String | Definition IP address or domain name of the origin server. Range N/A |
| obs_bucket_type | String | Definition OBS bucket type. Range |
| bucket_access_key | String | Definition Access key of the third-party bucket. Range N/A |
| bucket_secret_key | String | Definition Secret key of the third-party bucket. Range N/A |
| bucket_region | String | Definition Region of the third-party bucket. Range N/A |
| bucket_name | String | Definition Name of the third-party bucket. Range N/A |
| host_name | String | Definition Host header. Range N/A |
| origin_protocol | String | Definition Request protocol for CDN origin pull. Range |
| http_port | Integer | Definition HTTP port. Range 1 to 65,535. |
| https_port | Integer | Definition HTTPS port. Range 1 to 65,535. |
| priority | Integer | Definition Priority. A larger value indicates a higher priority. Range 1 to 100. |
| weight | 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. Range 1 to 100. |
| Parameter | Type | Description |
|---|---|---|
| name | String | Definition Name of an origin request header. Range |
| value | String | Definition Value of the origin request header. Range |
| action | String | Definition Operation type of the origin request header. action is set to set, if the header does not exist in the original origin request, it is added. If it exists, it is modified. Range |
| Parameter | Type | Description |
|---|---|---|
| name | String | Definition Name of an HTTP response header. Range |
| value | String | Definition Value of the HTTP response header. Range |
| action | String | Definition Operation type of the HTTP response header. action is set to set, if the header does not exist in the original HTTP response, it is added. If it exists, it is modified. Range |
| Parameter | Type | Description |
|---|---|---|
| limit_rate_after | 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. Range 0 to 1,073,741,824, in bytes. |
| limit_rate_value | Integer | Definition Rate limit, that is, the maximum access speed after the rate limit is reached. Range 0 to 104,857,600, in bit/s. |
| Parameter | Type | Description |
|---|---|---|
| rewrite_type | String | Definition Rewrite method. Range |
| source_url | String | Definition URI to rewrite. rewrite_type is set to wildcard or regex. When rewrite_type is set to regex, this parameter must start with ^/. Example: ^/test. Range |
| target_url | String | Definition URI after rewrite. Range NOTE: The nth wildcard (*) field can be captured by $n, where n = 1, 2, 3, .... Example: /newtest/$1/$2.jpg. |
| Parameter | Type | Description |
|---|---|---|
| ttl | Integer | Definition TTL of a resource cached on CDN PoPs. Range N/A |
| ttl_unit | String | Definition Unit of the cache TTL. Range |
| follow_origin | String | Definition Source of the cache TTL, that is, whether CDN PoPs use the cache TTL set on the origin server or that set in cache rules on CDN. Range |
| force_cache | String | Definition Forcible cache. Specify whether CDN PoP cache ignores the no-cache, private, and no-store fields in the Cache-Control response header sent from the origin server. Range |
| Parameter | Type | Description |
|---|---|---|
| cache_type | String | Definition Cache effective type. Range |
| ttl | Integer | Definition Cache TTL. ttl. Range N/A |
| ttl_unit | String | Definition Unit of the cache TTL. ttl. Range |
Example Requests
GET https://cdn.myhuaweicloud.com/v1.0/cdn/configuration/domains/www.example.com/rules
Example Responses
Status code: 200
Request succeeded.
{
"rules" : [ {
"rule_id" : "example***********************id",
"name" : "example",
"status" : "on",
"priority" : 1,
"conditions" : {
"match" : {
"logic" : "and",
"criteria" : [ {
"match_target_type" : "scheme",
"match_target_name" : "example",
"match_type" : "contains",
"match_pattern" : [ "HTTP" ],
"negate" : false,
"case_sensitive" : false
} ]
}
}
} ]
} 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 | 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.*; public class ListRuleDetailsSolution { 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(); ListRuleDetailsRequest request = new ListRuleDetailsRequest(); request.withDomainName("{domain_name}"); try { ListRuleDetailsResponse response = client.listRuleDetails(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 | # 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 = ListRuleDetailsRequest() request.domain_name = "{domain_name}" response = client.list_rule_details(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 | 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.ListRuleDetailsRequest{} request.DomainName = "{domain_name}" response, err := client.ListRuleDetails(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 |
|---|---|
| 200 | Request succeeded. |
Error Codes
See Error Codes.
What is your overall rating for this page?
Thank 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