Updated on 2024-10-14 GMT+08:00

Querying Security Groups by Tag

Function

This API is used to query security group by tag.

URI

POST /v2.0/{project_id}/security-groups/resource_instances/action

Table 1 Path Parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Project ID

Request Parameters

Table 2 Request body parameters

Parameter

Mandatory

Type

Description

action

Yes

String

Operation

The value can be filter or count.

limit

No

Integer

Number of records to be queried.

Value range: 1 to 1000

This parameter is not available when action is set to count. The default value is 1000 when action is set to filter.

offset

No

Integer

Index position. The query starts from the next data record indexed by this parameter. You do not need to specify this parameter when you query resources on the first page. When you query resources on subsequent pages, set this parameter to the location returned in the response body for the previous query.

This parameter is not available when action is set to count. If action is set to filter, the value must be a number, and the default value is 0. The value cannot be a negative number.

matches

No

Array of Match objects

Search criteria. The tag key is the field to match, and the tag value indicates the matched value.

Currently, only resource_name is supported.

tags

No

Array of ListTag objects

Included tags. Each tag contains a maximum of 10 keys, and each key contains a maximum of 10 values. The structure body cannot be missing, and the key cannot be left blank or set to an empty string. Each tag key must be unique, and each tag value in a tag must be unique.

Table 3 Match

Parameter

Mandatory

Type

Description

key

Yes

String

Key. The tag key can only be the resource name.

value

Yes

String

Value. Each value can contain a maximum of 255 Unicode characters and cannot contain special characters, such as dollar signs ($), hyphens (-), periods (.), or slashes (/).

Maximum: 255

Table 4 ListTag

Parameter

Mandatory

Type

Description

key

Yes

String

Tag key.

The key cannot be left blank.

Minimum: 1

Maximum: 127

values

Yes

Array of strings

Tag values.

If values are null, it indicates any_value. All values of a tag key are in the OR relationship.

Response Parameters

Status code: 200

Table 5 Response body parameters

Parameter

Type

Description

resources

Array of ListResourceResp objects

Resources

total_count

Integer

Number of resources.

Table 6 ListResourceResp

Parameter

Type

Description

resource_detail

Object

Resource details used for extension, which is left blank by default.

resource_id

String

Resource ID

resource_name

String

Resource name. If there is no resource name, this parameter is an empty string by default.

tags

Array of ResourceTag objects

A list of tags. This parameter is an empty array by default if there is no tag.

Table 7 ResourceTag

Parameter

Type

Description

key

String

Tag key.

The key must be unique for each resource.

Minimum: 0

Maximum: 36

value

String

Tag value

Minimum: 0

Maximum: 43

Status code: 400

Table 8 Response body parameters

Parameter

Type

Description

code

String

Error code returned for a request.

message

String

Error message returned for a request.

Status code: 401

Table 9 Response body parameters

Parameter

Type

Description

code

String

Error code returned for a request.

message

String

Error message returned for a request.

Status code: 403

Table 10 Response body parameters

Parameter

Type

Description

code

String

Error code returned for a request.

message

String

Error message returned for a request.

Status code: 404

Table 11 Response body parameters

Parameter

Type

Description

code

String

Error code returned for a request.

message

String

Error message returned for a request.

Status code: 409

Table 12 Response body parameters

Parameter

Type

Description

code

String

Error code returned for a request.

message

String

Error message returned for a request.

Status code: 500

Table 13 Response body parameters

Parameter

Type

Description

code

String

Error code returned for a request.

message

String

Error message returned for a request.

Example Requests

  • example-1: Request body when action is set to filter

    POST https://{Endpoint}/v2.0/{project_id}/security-groups/resource_instances/action
    
    {
      "offset" : "0",
      "limit" : "100",
      "action" : "filter",
      "matches" : [ {
        "key" : "resource_name",
        "value" : "resource1"
      } ],
      "tags" : [ {
        "key" : "key1",
        "values" : [ "*value1", "value2" ]
      } ]
    }
  • example-2: Request body when action is set to count

    POST https://{Endpoint}/v2.0/{project_id}/security-groups/resource_instances/action
    
    {
      "action" : "count",
      "tags" : [ {
        "key" : "key1",
        "values" : [ "value1", "value2" ]
      }, {
        "key" : "key2",
        "values" : [ "value1", "value2" ]
      } ],
      "matches" : [ {
        "key" : "resource_name",
        "value" : "resource1"
      } ]
    }

Example Responses

Status code: 200

If action in the request body is set to filter, the resource tag list is returned. If action in the request body is set to count, the total number of tags is returned.

{
  "resources" : [ {
    "resource_id" : "cdfs_cefs_wesas_12_dsad",
    "resource_name" : "resouece1",
    "tags" : [ {
      "key" : "key1",
      "value" : "value1"
    }, {
      "key" : "key2",
      "value" : "value1"
    } ]
  } ],
  "total_count" : 1000
}

Status Codes

Status Code

Description

200

If action in the request body is set to filter, the resource tag list is returned. If action in the request body is set to count, the total number of tags is returned.

400

The server failed to process the request.

401

Username and password are required to access the page requested.

403

You are forbidden to access the requested page.

404

The server could not find the requested page.

409

The request could not be processed due to a conflict.

500

Failed to complete the request because of an internal service error.

Error Codes

See Error Codes.