Obtaining the Direct Reading Configuration of a Bucket (SDK for C)
If you have any questions during development, post them on the Issues page of GitHub.
Function
The owner of a bucket can obtain the direct reading status of the bucket.
If direct reading has never been configured for a bucket or the direct reading configuration has been deleted, no status will be returned after this operation.
Restrictions
- To obtain the direct reading configuration of a bucket, you must be the bucket owner or have the required permission (obs:bucket:GetDirectColdAccessConfiguration granted using IAM or GetDirectColdAccessConfiguration granted using a bucket policy). For details, see Introduction to OBS Access Control, IAM Custom Policies, and Creating a Custom Bucket Policy.
- The mapping between OBS regions and endpoints must comply with what is listed in Regions and Endpoints.
Method
void get_bucket_direct_cold_access(const obs_options *options,
obs_get_bucket_direct_cold_access_handler *handler, void *callback_data); Request Parameters
| Parameter | Type | Mandatory (Yes/No) | Description |
|---|---|---|---|
| options | const obs_options* | Yes | Explanation: Context of the requested bucket. You can set the AK, SK, endpoint, bucket, timeout interval, and temporary credentials through obs_options. Restrictions: None Value range: None Default value: None |
| handler | Yes | Explanation: A callback structure where all members are pointers to callback functions, used to set the callback functions that handle response data. You can set a callback function to copy the response data from the server to callback_data (custom callback data). Restrictions: None Value range: None Default value: None | |
| callback_data | void * | No | Explanation: Custom callback data. Restrictions: None Value range: None Default value: None |
| Parameter | Type | Mandatory (Yes/No) | Description |
|---|---|---|---|
| response_handler | obs_response_handler | Yes | Explanation: Response callback function structure. Restrictions: None Value range: None Default value: None |
| get_bucket_direct_cold_access_callback | Yes | Explanation: Pointer to the callback function of the direct reading policy. The content of direct_cold_access_status in the callback can be recorded in callback_data (custom callback data). Restrictions: None Value range: None Default value: None |
| Parameter | Type | Mandatory (Yes/No) | Description |
|---|---|---|---|
| direct_cold_access_status | const char * | Yes | Explanation: Status of the direct reading policy. Restrictions: None Value range: Enabled: The direct reading policy is enabled. Disabled: The direct reading policy is disabled. Empty string: No direct reading policy is configured for the bucket. Default value: None |
| callback_data | void * | Yes | Explanation: Pointer to the custom callback data. Restrictions: None Value range: None Default value: None |
Sample Code
#include "eSDKOBS.h"
#include <stdio.h>
#include <string.h>
// The response callback function. The content of properties in the callback can be recorded in callback_data (custom callback data).
obs_status response_properties_callback(const obs_response_properties *properties, void *callback_data);
// The callback function for the completed response. The content of obs_status and obs_error_details in the callback can be recorded in callback_data (custom callback data).
void response_complete_callback(obs_status status, const obs_error_details *error, void *callback_data);
// Callback function for obtaining the direct reading configuration of a bucket
obs_status get_direct_cold_access_callback(const char *enabled, void *callback_data);
typedef struct DirectColdAccessInfo
{
char enabled[64];
obs_status ret_status;
}DirectColdAccessInfo;
int main()
{
// The following example shows how to use get_bucket_direct_cold_access to obtain the direct reading configuration of a bucket.
// Call the obs_initialize method at the program entry to initialize global resources such as the network and memory.
obs_initialize(OBS_INIT_ALL);
obs_options options;
// Create and initialize options, including the access domain name (host_name), access keys (access_key_id and access_key_secret), bucket name (bucket_name), and bucket storage class (storage_class).
init_obs_options(&options);
// Enter the endpoint corresponding to the bucket for host_name. CN-Hong Kong is used here as an example. Replace it with the one currently in use.
options.bucket_options.host_name = "obs.ap-southeast-1.myhuaweicloud.com";
// Hard-coded or plaintext AK and SK are risky. For security purposes, encrypt your AK and SK and store them in the configuration file or environment variables.
// In this example, the AK and SK are stored in environment variables for identity authentication. Before running the code in this example, configure local environment variables ACCESS_KEY_ID and SECRET_ACCESS_KEY.
options.bucket_options.access_key = getenv("ACCESS_KEY_ID");
options.bucket_options.secret_access_key = getenv("SECRET_ACCESS_KEY");
// Specify the bucket name, for example, example-bucket-name.
char * bucketName = "example-bucket-name";
options.bucket_options.bucket_name = bucketName;
obs_response_handler response_handler = { &response_properties_callback, &response_complete_callback };
// Set the response callback function.
obs_get_bucket_direct_cold_access_handler get_direct_cold_access_handler =
{
response_handler,
&get_direct_cold_access_callback
};
// Create callback data.
DirectColdAccessInfo direct_cold_access_info;
memset(&direct_cold_access_info, 0, sizeof(DirectColdAccessInfo));
direct_cold_access_info.ret_status = OBS_STATUS_BUTT;
// Obtain the direct reading configuration of a bucket.
get_bucket_direct_cold_access(&options, &get_direct_cold_access_handler, &direct_cold_access_info);
if (OBS_STATUS_OK == direct_cold_access_info.ret_status) {
printf("get bucket direct cold access successfully. enabled: %s\n", direct_cold_access_info.enabled);
}
else
{
printf("get bucket direct cold access failed(%s).\n", obs_get_status_name(direct_cold_access_info.ret_status));
}
// Release the allocated global resources.
obs_deinitialize();
}
obs_status get_direct_cold_access_callback(const char *enabled, void *callback_data)
{
DirectColdAccessInfo *info = (DirectColdAccessInfo *)callback_data;
if (enabled) {
strncpy(info->enabled, enabled, sizeof(info->enabled) - 1);
info->enabled[sizeof(info->enabled) - 1] = '\0';
} else {
info->enabled[0] = '\0';
}
return OBS_STATUS_OK;
}
// The response callback function. The content of properties in the callback can be recorded in callback_data (custom callback data).
obs_status response_properties_callback(const obs_response_properties *properties, void *callback_data)
{
if (properties == NULL)
{
printf("error! obs_response_properties is null!");
return OBS_STATUS_OK;
}
// Print the response.
#define print_nonnull(name, field) \
do { \
if (properties-> field) { \
printf("%s: %s\n", name, properties->field); \
} \
} while (0)
print_nonnull("request_id", request_id);
print_nonnull("request_id2", request_id2);
print_nonnull("content_type", content_type);
if (properties->content_length) {
printf("content_length: %llu\n", properties->content_length);
}
print_nonnull("server", server);
print_nonnull("ETag", etag);
print_nonnull("version_id", version_id);
return OBS_STATUS_OK;
}
// The callback function for the completed response. The content of obs_status and obs_error_details in the callback can be recorded in callback_data (custom callback data).
void response_complete_callback(obs_status status, const obs_error_details *error, void *callback_data)
{
if (callback_data) {
DirectColdAccessInfo *info = (DirectColdAccessInfo *)callback_data;
info->ret_status = status;
}
else {
printf("Callback_data is NULL");
}
if (error && error->message) {
printf("Error Message: \n %s\n", error->message);
}
if (error && error->resource) {
printf("Error Resource: \n %s\n", error->resource);
}
if (error && error->further_details) {
printf("Error further_details: \n %s\n", error->further_details);
}
if (error && error->extra_details_count) {
int i;
for (i = 0; i < error->extra_details_count; i++) {
printf("Error Extra Detail(%d):\n %s:%s\n", i, error->extra_details[i].name,
error->extra_details[i].value);
}
}
if (error && error->error_headers_count) {
int i;
for (i = 0; i < error->error_headers_count; i++) {
const char *errorHeader = error->error_headers[i];
printf("Error Headers(%d):\n %s\n", i, errorHeader == NULL ? "NULL Header" : errorHeader);
}
}
} 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