หน้านี้ยังไม่พร้อมใช้งานในภาษาท้องถิ่นของคุณ เรากำลังพยายามอย่างหนักเพื่อเพิ่มเวอร์ชันภาษาอื่น ๆ เพิ่มเติม ขอบคุณสำหรับการสนับสนุนเสมอมา
Customizing a Rule Set
Function
This API is used to create a rule set. You can specify rules when creating a rule set.
Calling Method
For details, see Calling APIs.
URI
POST /v2/ruleset
Request Parameters
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
X-Auth-Token |
Yes |
String |
Definition User token. Obtain a token by calling the IAM API forobtaining a user token. The value of X-Subject-Token in the response header is the user token. Constraints N/A Range 1–100,000 characters Default Value N/A |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
project_id |
Yes |
String |
Definition 32-character UUID of a project. Obtain the ID by calling the API for querying projects. Constraints N/A Range 32-character project ID. Default Value N/A |
template_name |
Yes |
String |
Definition New rule set name. Constraints Only letters, digits, periods (.), hyphens (-), and underscores () are allowed. Range Can contain any 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. Supported languages include: ArkTS, C#, C++, CSS, Go, HTML, Java, JavaScript, Kotlin, Lua, PHP, Python, Rust, Scala, Shell, SQL, and TypeScript. 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. Range Default Value N/A |
rule_ids |
Yes |
String |
Definition ID of a rule to be enabled. Separate multiple IDs with commas (,). Obtain a rule ID by calling the API for obtaining rules. Constraints Each rule ID must be a 32-character UUID. Separate multiple IDs with commas (,). For example, 00034fc32ee045388365d42ca4e07fe1,002c2eda6d6c11edab16fa163e0fa374. Range Max. 4,000 characters. Default Value N/A |
uncheck_ids |
No |
String |
Definition ID of a rule to be disabled. Separate multiple IDs with commas (,). Obtain a rule ID by calling the API for obtaining rules. Constraints Each rule ID must be a 32-character UUID. Separate multiple IDs with commas (,). For example, 00034fc32ee045388365d42ca4e07fe1,002c2eda6d6c11edab16fa163e0fa374. Range Max. 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 of an existing rule set by calling the API for querying rule sets. Constraints 32-character UUID. For example, da303d80d2594faca60dbcc2e29c18aa. 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 |
Rule details. |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
rule_id |
No |
String |
Definition Rule ID. Obtain a rule ID by calling the API for obtaining rules. Constraints N/A Range 32-character project ID. Default Value N/A |
value |
No |
String |
Definition Severity of attribute. 0: critical; 1: major; 2: minor; 3: suggestion. Constraints N/A Range Default Value N/A |
rule_config_list |
No |
Array of RuleConfig objects |
Rule threshold details. |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
id |
No |
Integer |
Definition Rule configuration ID. Obtain a rule configuration ID by calling the API for obtaining rules. Constraints N/A 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 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 a rule configuration ID by calling the API for obtaining rules. Constraints Must match the rule ID. Range N/A Default Value N/A |
option_name |
No |
String |
Definition Key of the current rule configuration item. Obtain a rule configuration ID by calling the API for obtaining rules. Constraints Must match the rule ID. Range N/A Default Value N/A |
template_id |
No |
String |
Definition Rule set ID. Obtain a rule set ID by calling the API for querying rule sets. Constraints N/A 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. Range 32-character UUID. |
Status code: 400
Parameter |
Type |
Description |
---|---|---|
error_code |
String |
Error code. |
error_msg |
String |
Error message. |
Status code: 401
Parameter |
Type |
Description |
---|---|---|
error_code |
String |
Error code. |
error_msg |
String |
Error message. |
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
Bad Request
{
"error_code" : "CC.00000000",
"error_msg" : "Network busy. Try again later."
}
Status code: 401
Unauthorized
{
"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 |
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 := basic.NewCredentialsBuilder().
WithAk(ak).
WithSk(sk).
Build()
client := codecheck.NewCodeCheckClient(
codecheck.CodeCheckClientBuilder().
WithRegion(region.ValueOf("<YOUR REGION>")).
WithCredential(auth).
Build())
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.
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 |
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 := basic.NewCredentialsBuilder().
WithAk(ak).
WithSk(sk).
Build()
client := codecheck.NewCodeCheckClient(
codecheck.CodeCheckClientBuilder().
WithRegion(region.ValueOf("<YOUR REGION>")).
WithCredential(auth).
Build())
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 |
Bad Request |
401 |
Unauthorized |
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