Customizing a Rule Set
Function
This API is used to create a custom rule set. You can enable rules during rule set creation. You can inherit existing rule sets. The API returns the basic information about the rule set.
Calling Method
For details, see Calling APIs.
Authorization Information
Each account root user has all the permissions required to call all APIs, but IAM users must be assigned the following required identity policy-based permissions. For details about the required permissions, see Permissions Policies and Supported Actions.
| Action | Access Level | Resource Type (*: required) | Condition Key | Alias | Dependencies |
|---|---|---|---|---|---|
| codeartscheck::createRuleSet | Write | - | - | - | - |
URI
POST /v2/ruleset
Request Parameters
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| X-Auth-Token | Yes | String | Definition User token. Obtain one by calling the IAM API Obtaining a User Token. The value of X-Subject-Token in the response header is a token. Constraints N/A Range The length is the value of [1-100000]. Default Value N/A |
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| project_id | Yes | String | Definition : 32-character project UUID. Obtain it by calling the API used to query the project list. Constraints: N/A. Value range: 1 to 32 characters. Default value: N/A. |
| template_name | Yes | String | Definition: New rule set name. Constraints: Only letters, digits, periods (.), hyphens (-), and underscores () are allowed. Value range: 1 to 128 characters, including letters, digits, periods (.), hyphens (-), and underscores (). Default value: N/A. |
| language | Yes | String | Definition Rule set language. Constraints A supported language in the system. Range Only one language can be passed. The following languages are supported: Default Value N/A |
| is_default | Yes | String | Definition: Whether to create a rule set based on an existing one. Constraints: Must be 0 or 1. Value range: Default value: N/A |
| rule_ids | No | String | Definition : IDs of the rules to be enabled. When multiple rules are enabled, the IDs are separated by commas (,). Obtain the rule IDs by calling the API used to obtain the rule list. Constraints: Each rule ID must be a 32-character UUID. Separate multiple IDs with commas (,), for example, 00034fc32ee045388365d42ca4e07fe1,002c2eda6d6c11edab16fa163e0fa374. Value range: 1 to 4,000 characters. Default value: N/A. |
| uncheck_ids | No | String | Definition : IDs of the rules to be disabled. When multiple rules are disabled, the IDs are separated by commas (,). Obtain the rule IDs by calling the API used to obtain the rule list. Constraints: Each rule ID must be a 32-character UUID. Separate multiple IDs with commas (,), for example, 00034fc32ee045388365d42ca4e07fe1,002c2eda6d6c11edab16fa163e0fa374. Value range: 1 to 4,000 characters. Default value: N/A. |
| template_id | No | String | Definition : Rule set ID. Pass this parameter when is_default is set to 1 . Obtain the ID by calling the API used to obtain the rule set list. Constraints: 32-character UUID. For example, da303d80d2594faca60dbcc2e29c18aa. Value range: N/A Default value: N/A |
| custom_attributes | No | Array of CustomAttributes objects | Parameters of a custom rule. Rule thresholds can be modified. |
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| attribute | No | String | Definition Configuration item. severity indicates the severity of a rule. Constraints N/A Range severity Default Value N/A |
| rules | No | Array of CustomAttributesRule objects | Definition: Rule details. |
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| rule_id | No | String | Definition : Rule ID. Obtain the ID by calling the API used to obtain the rule list[. Constraints: N/A Value range: 32-character project ID. Default value: N/A |
| value | No | String | Definition: Alarm severity of an attribute. Constraints: N/A. Value range: Default value: N/A. |
| rule_config_list | No | Array of RuleConfig objects | Definition: Rule threshold details. |
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| id | No | Integer | Definition : Rule configuration ID. Obtain the ID by calling the API used to obtain the rule list[. Constraints: N/A Value range: 32-character UUID. Default value: N/A |
| rule_id | No | String | Definition: Tool rule ID, that is, the ID of a threshold for configuring a threshold rule. To obtain such an ID, contact customer service. Constraints: N/A Value range: 32-character UUID. Default value: N/A |
| default_value | No | String | Definition Default threshold of a parameter. Constraints N/A Range N/A Default Value N/A |
| option_value | No | String | Definition New threshold of a parameter. Constraints N/A Range N/A Default Value N/A |
| option_key | No | String | Definition : Key of the current rule configuration item. Obtain the ID by calling the API used to obtain the rule list[. Constraints: Must match the rule ID. Value range: N/A Default value: N/A |
| option_name | No | String | Definition : Key of the current rule configuration item. Obtain the ID by calling the API used to obtain the rule list[. Constraints: Must match the rule ID. Value range: N/A Default value: N/A |
| template_id | No | String | Definition : Rule set ID. Obtain the ID by calling the API used to obtain the rule set list. Constraints: N/A Value range: 32-character UUID. Default value: N/A |
| description | No | String | Definition Parameter description. This parameter is optional. Constraints N/A Range N/A Default Value N/A |
Response Parameters
Status code: 201
| Parameter | Type | Description |
|---|---|---|
| template_id | String | Definition: Rule set ID. Value range: 32-character UUID. |
Status code: 400
| Parameter | Type | Description |
|---|---|---|
| error_code | String | Definition: Error code. Value range: N/A |
| error_msg | String | Definition: Error message. Value range: N/A |
Status code: 401
| Parameter | Type | Description |
|---|---|---|
| error_code | String | Definition: Error code. Value range: N/A |
| error_msg | String | Definition: Error message. Value range: N/A |
Example Requests
Customize a rule set: Set template name to test_cpp and language to cpp.The project ID and template ID corresponding to the rule set are displayed based on the site requirements.
POST https://{endpoint}/v2/ruleset
{
"project_id" : "24b97exxxxxxxxfb912625b14cxxxxxx",
"template_id" : "da303dxxxxxxxxaca60dbcc2e2xxxxxx",
"template_name" : "test_cpp",
"language" : "cpp",
"is_default" : "1",
"rule_ids" : "8139,8138",
"uncheck_ids" : "1101,1102"
} Example Responses
Status code: 201
Request succeeded.
{
"template_id" : "c53417a4804f45eba9c11991131c9e79"
} Status code: 400
A request error occurred.
{
"error_code" : "CC.xxxxxxxx.400",
"error_msg" : "Verify request parameter failed. Check whether the request parameters are correct."
} Status code: 401
The permission is insufficient.
{
"error_code" : "CC.00000003",
"error_msg" : "Authentication information expired."
} SDK Sample Code
The SDK sample code is as follows.
Customize a rule set: Set template name to test_cpp and language to cpp.The project ID and template ID corresponding to the rule set are displayed based on the site requirements.
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 | package com.huaweicloud.sdk.test; import com.huaweicloud.sdk.core.auth.ICredential; import com.huaweicloud.sdk.core.auth.BasicCredentials; 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.codecheck.v2.region.CodeCheckRegion; import com.huaweicloud.sdk.codecheck.v2.*; import com.huaweicloud.sdk.codecheck.v2.model.*; public class CreateRulesetSolution { 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 BasicCredentials() .withAk(ak) .withSk(sk); CodeCheckClient client = CodeCheckClient.newBuilder() .withCredential(auth) .withRegion(CodeCheckRegion.valueOf("<YOUR REGION>")) .build(); CreateRulesetRequest request = new CreateRulesetRequest(); Ruleset body = new Ruleset(); body.withTemplateId("da303dxxxxxxxxaca60dbcc2e2xxxxxx"); body.withUncheckIds("1101,1102"); body.withRuleIds("8139,8138"); body.withIsDefault("1"); body.withLanguage("cpp"); body.withTemplateName("test_cpp"); body.withProjectId("24b97exxxxxxxxfb912625b14cxxxxxx"); request.withBody(body); try { CreateRulesetResponse response = client.createRuleset(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()); } } } |
Customize a rule set: Set template name to test_cpp and language to cpp.The project ID and template ID corresponding to the rule set are displayed based on the site requirements.
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 | # coding: utf-8 import os from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkcodecheck.v2.region.codecheck_region import CodeCheckRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkcodecheck.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 = BasicCredentials(ak, sk) client = CodeCheckClient.new_builder() \ .with_credentials(credentials) \ .with_region(CodeCheckRegion.value_of("<YOUR REGION>")) \ .build() try: request = CreateRulesetRequest() request.body = Ruleset( template_id="da303dxxxxxxxxaca60dbcc2e2xxxxxx", uncheck_ids="1101,1102", rule_ids="8139,8138", is_default="1", language="cpp", template_name="test_cpp", project_id="24b97exxxxxxxxfb912625b14cxxxxxx" ) response = client.create_ruleset(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg) |
Customize a rule set: Set template name to test_cpp and language to cpp.The project ID and template ID corresponding to the rule set are displayed based on the site requirements.
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 | package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" codecheck "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/codecheck/v2" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/codecheck/v2/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/codecheck/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 := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). SafeBuild() if err != nil { fmt.Println(err) return } hcClient, err := codecheck.CodeCheckClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). SafeBuild() if err != nil { fmt.Println(err) return } client := codecheck.NewCodeCheckClient(hcClient) request := &model.CreateRulesetRequest{} templateIdRuleset:= "da303dxxxxxxxxaca60dbcc2e2xxxxxx" uncheckIdsRuleset:= "1101,1102" request.Body = &model.Ruleset{ TemplateId: &templateIdRuleset, UncheckIds: &uncheckIdsRuleset, RuleIds: "8139,8138", IsDefault: "1", Language: "cpp", TemplateName: "test_cpp", ProjectId: "24b97exxxxxxxxfb912625b14cxxxxxx", } response, err := client.CreateRuleset(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 |
|---|---|
| 201 | Request succeeded. |
| 400 | A request error occurred. |
| 401 | The permission is insufficient. |
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