Help Center/ CodeArts Check/ API Reference/ APIs/ Rule Management/ Viewing Rules of a Rule Set
Updated on 2024-11-28 GMT+08:00

Viewing Rules of a Rule Set

Function

This API is used to query rules based on conditions such as the project ID and rule set ID.

Calling Method

For details, see Calling APIs.

URI

GET /v2/{project_id}/ruleset/{ruleset_id}/rules

Table 1 Path Parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Project ID.

ruleset_id

Yes

String

Rule set ID.

Table 2 Query Parameters

Parameter

Mandatory

Type

Description

types

Yes

String

Rule status.

1: all; 2: enabled; 3: disabled.

languages

No

String

Rule language.

tags

No

String

Tag to which a rule belongs.

offset

No

Integer

Offset for pagination.

limit

No

Integer

Number of items on each page.

Request Parameters

Table 3 Request header parameters

Parameter

Mandatory

Type

Description

X-Auth-Token

Yes

String

User token.

It can be obtained by calling the IAM API used to obtain a user token. The value of X-Subject-Token in the response header is the user token.

Response Parameters

Status code: 200

Table 4 Response body parameters

Parameter

Type

Description

info

Array of RuleItem objects

Rule list of a rule set.

total

Integer

Total number.

Table 5 RuleItem

Parameter

Type

Description

rule_id

String

Rule ID.

rule_language

String

Language corresponding to the rule.

rule_name

String

Rule name.

rule_severity

String

Severity of issues corresponding to the rule.

tags

String

Rule tag.

checked

String

Rule status. 0: disabled; 1: enabled.

rule_config_list

Array of RuleConfig objects

Threshold information about rule parameter configuration.

Table 6 RuleConfig

Parameter

Type

Description

id

Integer

Rule configuration ID.

rule_id

Integer

Rule ID.

default_value

String

Default value.

option_value

String

Current.

option_key

String

Key of the current rule configuration item.

option_name

String

Name of the current rule configuration item.

template_id

String

Rule set ID.

description

String

Description.

Status code: 400

Table 7 Response body parameters

Parameter

Type

Description

error_code

String

Error code.

error_msg

String

Error message.

Status code: 401

Table 8 Response body parameters

Parameter

Type

Description

error_code

String

Error code.

error_msg

String

Error message.

Example Requests

GET https://{endpoint}/v2/{project_id}/ruleset/{ruleset_id}/rules

Example Responses

Status code: 200

Request succeeded!

{
  "info" : [ {
    "rule_language" : "cpp",
    "rule_id" : "1614",
    "checked" : "1",
    "rule_name" : "A buffer must have size of 2 integers if used as parameter of pipe().",
    "rule_severity" : "1",
    "tags" : "cwe",
    "rule_config_list" : [ ]
  }, {
    "rule_language" : "cpp",
    "rule_id" : "1611",
    "checked" : "1",
    "rule_name" : "A buffer must have size of 2 integers if used as parameter of pipe().",
    "rule_severity" : "1",
    "tags" : "cwe",
    "rule_config_list" : [ {
      "id" : 250,
      "rule_id" : 11707,
      "template_id" : "906e7eac47dd4bde9c984f5e6f2a54e8",
      "option_key" : "threshold",
      "option_name" : "Adding a threshold",
      "option_value" : "10",
      "default_value" : "20",
      "description" : "If the code complexity exceeds the threshold, the code is identified as a huge cyclomatic complexity. The difference between the large cyclomatic complexity and cyclomatic complexity statistics is that only the number of switch statements is counted. The parameter is mandatory."
    }, {
      "id" : 251,
      "rule_id" : 11707,
      "template_id" : "906e7eac47dd4bde9c984f5e6f2a54e8",
      "option_key" : "threshold_modify",
      "option_name" : "Modifying a threshold",
      "option_value" : "30",
      "default_value" : "20",
      "description" : "If the code complexity exceeds the threshold, the code is identified as a huge cyclomatic complexity. The difference between the large cyclomatic complexity and cyclomatic complexity statistics is that only the number of switch statements is counted. The modified threshold must be greater than the new threshold. This parameter is optional."
    } ]
  } ],
  "total" : 2
}

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."
}

Status Codes

Status Code

Description

200

Request succeeded!

400

Bad Request

401

Unauthorized

Error Codes

See Error Codes.