Bucket tag

Last updated: 2020-03-20 12:35:28

PDF

Note

This document provides an overview of API on Bucket tags and sample SDK code.

API Operation name pedagogical operation
PUT Bucket tagging Set Bucket tag Set the label for the existing Bucket
GET Bucket tagging Query Bucket tag Query the existing Bucket tags under the specified Bucket
DELETE Bucket tagging Delete Bucket tag Delete the specified Bucket tag

Set Bucket tag

Function description

PUT Bucket tagging is used to label the existing Bucket.

Method prototype

cos_status_t *cos_put_bucket_tagging(const cos_request_options_t *options,
                                      const cos_string_t *bucket,
                                      cos_tagging_params_t *tagging_params,
                                      cos_table_t **resp_headers);

Request Sample

cos_pool_t *pool = NULL;
int is_cname = 0;
cos_status_t *status = NULL;
cos_request_options_t *options = NULL;
cos_table_t *resp_headers = NULL;
cos_string_t bucket;
cos_tagging_params_t *params = NULL;
cos_tagging_params_t *result = NULL;
cos_tagging_tag_t *tag = NULL;

cos_pool_create(&pool, NULL);

options = cos_request_options_create(pool);
options->config = cos_config_create(options->pool);
cos_str_set(&options->config->endpoint, TEST_COS_ENDPOINT);
cos_str_set(&options->config->access_key_id, TEST_ACCESS_KEY_ID);
cos_str_set(&options->config->access_key_secret, TEST_ACCESS_KEY_SECRET);
cos_str_set(&options->config->appid, TEST_APPID);
options->config->is_cname = is_cname;
options->ctl = cos_http_controller_create(options->pool, 0);
cos_str_set(&bucket, TEST_BUCKET_NAME);

// put tagging
params = cos_create_tagging_params(pool);
tag = cos_create_tagging_tag(pool);
cos_str_set(&tag->key, "age");
cos_str_set(&tag->value, "18");
cos_list_add_tail(&tag->node, &params->node);

tag = cos_create_tagging_tag(pool);
cos_str_set(&tag->key, "name");
cos_str_set(&tag->value, "xiaoming");
cos_list_add_tail(&tag->node, &params->node);

status = cos_put_bucket_tagging(options, &bucket, params, &resp_headers);
log_status(status);

cos_pool_destroy(pool);

Parameter description

Parameter name Description Type
OPTIONS COS request options Struct
Bucket Bucket is tagged in BucketName-APPID format. For more information, please see Naming convention String
Tagging_params Bucket tag configuration information Struct
Key The Key, length of the label is no more than 128 bytes, and supports English letters, numbers, spaces, plus sign, minus sign, underscore, equal sign, period, colon and slash String
Value The Value, length of the label is no more than 256 bytes, and supports English letters, numbers, spaces, plus sign, minus sign, underscore, equal sign, period, colon and slash String
Resp_headers Returns the header field of the HTTP response message Struct

Return result description

Returned Result Description Type
Code Error Codes Int
Error_code Error code content String
Error_msg Error code description String
Req_id Request message ID String

Query Bucket tag

Function description

GET Bucket tagging is used to query the existing Bucket tags under the specified Bucket.

Method prototype

cos_status_t *cos_get_bucket_tagging(const cos_request_options_t *options,
                                      const cos_string_t *bucket,
                                      cos_tagging_params_t *tagging_params,
                                      cos_table_t **resp_headers);

Request Sample

cos_pool_t *pool = NULL;
int is_cname = 0;
cos_status_t *status = NULL;
cos_request_options_t *options = NULL;
cos_table_t *resp_headers = NULL;
cos_string_t bucket;
cos_tagging_params_t *params = NULL;
cos_tagging_params_t *result = NULL;
cos_tagging_tag_t *tag = NULL;

cos_pool_create(&pool, NULL);

options = cos_request_options_create(pool);
options->config = cos_config_create(options->pool);
cos_str_set(&options->config->endpoint, TEST_COS_ENDPOINT);
cos_str_set(&options->config->access_key_id, TEST_ACCESS_KEY_ID);
cos_str_set(&options->config->access_key_secret, TEST_ACCESS_KEY_SECRET);
cos_str_set(&options->config->appid, TEST_APPID);
options->config->is_cname = is_cname;
options->ctl = cos_http_controller_create(options->pool, 0);
cos_str_set(&bucket, TEST_BUCKET_NAME);

// get tagging
result = cos_create_tagging_params(pool);
status = cos_get_bucket_tagging(options, &bucket, result, &resp_headers);
log_status(status);

tag = NULL;
cos_list_for_each_entry(cos_tagging_tag_t, tag, &result->node, node) {
    printf("taging key: %s\n", tag->key.data);
    printf("taging value: %s\n", tag->value.data);
} 

cos_pool_destroy(pool);

Parameter description

Parameter name Description Type
OPTIONS COS request options Struct
Bucket Query the tag Bucket in BucketName-APPID format. For more information, please see Naming convention String
Tagging_params Bucket tag configuration information Struct
Key The Key, length of the label is no more than 128 bytes, and supports English letters, numbers, spaces, plus sign, minus sign, underscore, equal sign, period, colon and slash String
Value The Value, length of the label is no more than 256 bytes, and supports English letters, numbers, spaces, plus sign, minus sign, underscore, equal sign, period, colon and slash String
Resp_headers Returns the header field of the HTTP response message Struct

Return result description

Returned Result Description Type
Code Error Codes Int
Error_code Error code content String
Error_msg Error code description String
Req_id Request message ID String

Delete Bucket tag

Function description

DELETE Bucket tagging is used to delete the existing Bucket tag under the specified Bucket.

Method prototype

cos_status_t *cos_delete_bucket_tagging(const cos_request_options_t *options,
                                      const cos_string_t *bucket,
                                      cos_table_t **resp_headers);

Request Sample

cos_pool_t *pool = NULL;
int is_cname = 0;
cos_status_t *status = NULL;
cos_request_options_t *options = NULL;
cos_table_t *resp_headers = NULL;
cos_string_t bucket;
cos_tagging_params_t *params = NULL;
cos_tagging_params_t *result = NULL;
cos_tagging_tag_t *tag = NULL;

cos_pool_create(&pool, NULL);

options = cos_request_options_create(pool);
options->config = cos_config_create(options->pool);
cos_str_set(&options->config->endpoint, TEST_COS_ENDPOINT);
cos_str_set(&options->config->access_key_id, TEST_ACCESS_KEY_ID);
cos_str_set(&options->config->access_key_secret, TEST_ACCESS_KEY_SECRET);
cos_str_set(&options->config->appid, TEST_APPID);
options->config->is_cname = is_cname;
options->ctl = cos_http_controller_create(options->pool, 0);
cos_str_set(&bucket, TEST_BUCKET_NAME);

// delete tagging
status = cos_delete_bucket_tagging(options, &bucket, &resp_headers);
log_status(status);

cos_pool_destroy(pool);

Parameter description

Parameter name Description Type
OPTIONS COS request options Struct
Bucket Bucket with the deleted tag is in BucketName-APPID format. For more information, please see Naming convention String
Resp_headers Returns the header field of the HTTP response message Struct

Return result description

Returned Result Description Type
Code Error Codes Int
Error_code Error code content String
Error_msg Error code description String
Req_id Request message ID String