Listing Bucket Inventory Rules (SDK for C)
If you have any questions during development, post them on the Issues page of GitHub.
Function
This API is used to list all inventory rules of a specified bucket.
Restrictions
- To list bucket inventory rules, you must be the bucket owner or have the required permission (obs:bucket:GetBucketInventoryConfiguration granted using IAM or GetBucketInventoryConfiguration 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 list_bucket_inventory(const obs_options *options,
obs_list_bucket_inventory_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: Callback structure, which is used to set the callback functions that handle response 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 | Yes | Explanation: Response callback function structure. Restrictions: None Value range: None Default value: None | |
| list_bucket_inventory_callback | Yes | Explanation: Pointer to the inventory rule list callback function. You can record the content of inventory_list to callback_data in this callback. Restrictions: None Value range: None Default value: None |
| Parameter | Type | Mandatory (Yes/No) | Description |
|---|---|---|---|
| inventory_list | Table 4** | Yes | Explanation: Inventory rule array. Each element in the array points to an inventory rule. Restrictions: The array and the memory to which the pointer points will be released by the SDK after the callback. Copy them if you need to keep the data. Value range: None Default value: None |
| inventory_count | unsigned int | Yes | Explanation: Number of inventory rules. Restrictions: None Value range: None Default value: None |
| callback_data | void * | Yes | Explanation: Pointer to the custom callback data. Restrictions: None Value range: None Default value: None |
| Parameter | Type | Mandatory (Yes/No) | Description |
|---|---|---|---|
| id | char * | Yes | Explanation: Inventory rule ID, which uniquely identifies an inventory rule in a bucket. Restrictions: None Value range: The value can contain 1 to 64 characters. Default value: None |
| destination | Yes | Explanation: Destination bucket configuration, which specifies the location for storing inventory files. Restrictions: None Value range: None Default value: None | |
| schedule | char * | Yes | Explanation: Generation frequency of inventories. Restrictions: None Value range:
Default value: None |
| format | char * | Yes | Explanation: Inventory file format. Restrictions: None Value range: CSV Default value: None |
| included_object_versions | char * | Yes | Explanation: Object versions included in the inventories. Restrictions: None Value range:
Default value: None |
| filter | No | Explanation: Filter. Inventories are generated only for objects with the specified prefix. Restrictions: None Value range: None Default value: None | |
| optional_fields | No | Explanation: Optional fields included in the inventories. Restrictions: None Value range: None Default value: None | |
| is_enabled | bool | Yes | Explanation: Whether the inventory rule is enabled. Restrictions: None Value range:
Default value: false |
| Parameter | Type | Mandatory (Yes/No) | Description |
|---|---|---|---|
| bucket | char * | Yes | Explanation: Name of the bucket for storing inventory files. Restrictions: The destination bucket must already exist, and the source bucket owner must have the write permission on the destination bucket. Value range: None Default value: None |
| prefix | char * | No | Explanation: Prefix of the inventory files in the destination bucket. Restrictions: None Value range: None Default value: None |
| Parameter | Type | Mandatory (Yes/No) | Description |
|---|---|---|---|
| prefix | char * | No | Explanation: Object prefix. Inventories are generated only for objects with this prefix. Restrictions: None Value range: None Default value: None |
| Parameter | Type | Mandatory (Yes/No) | Description |
|---|---|---|---|
| field_count | unsigned int | Yes | Explanation: Number of optional fields. Restrictions: None Value range: None Default value: None |
| fields | char ** | Yes | Explanation: Array of optional fields. Restrictions: None Value range: Size, LastModifiedDate, StorageClass, ETag, IsMultipartUploaded, ReplicationStatus, and EncryptionStatus Default value: None |
Sample Code
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 55 56 57 58 59 60 61 62 63 64 65 66 | #include "eSDKOBS.h" #include <stdio.h> #include <string.h> obs_status response_properties_callback(const obs_response_properties *properties, void *callback_data); void response_complete_callback(obs_status status, const obs_error_details *error, void *callback_data); obs_status list_inventory_callback(obs_inventory_configuration **inventory_list, unsigned int inventory_count, void *callback_data); typedef struct InventoryListInfo { unsigned int inventory_count; obs_status ret_status; } InventoryListInfo; int main() { obs_initialize(OBS_INIT_ALL); obs_options options; 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"); options.bucket_options.bucket_name = "example-source-bucket"; obs_response_handler response_handler = {&response_properties_callback, &response_complete_callback}; obs_list_bucket_inventory_handler list_inventory_handler = { response_handler, &list_inventory_callback }; InventoryListInfo info = {0}; info.ret_status = OBS_STATUS_BUTT; list_bucket_inventory(&options, &list_inventory_handler, &info); if (OBS_STATUS_OK == info.ret_status) { printf("list bucket inventory successfully. count: %u\n", info.inventory_count); } else { printf("list bucket inventory failed(%s).\n", obs_get_status_name(info.ret_status)); } obs_deinitialize(); } obs_status list_inventory_callback(obs_inventory_configuration **inventory_list, unsigned int inventory_count, void *callback_data) { InventoryListInfo *info = (InventoryListInfo *)callback_data; info->inventory_count = inventory_count; unsigned int i; for (i = 0; i < inventory_count; i++) { obs_inventory_configuration *config = inventory_list[i]; if (config) { printf("inventory[%u]: id=%s, schedule=%s, enabled=%s\n", i, config->id ? config->id : "", config->schedule ? config->schedule : "", config->is_enabled ? "true" : "false"); } } return OBS_STATUS_OK; } obs_status response_properties_callback(const obs_response_properties *properties, void *callback_data) { (void)properties; (void)callback_data; return OBS_STATUS_OK; } void response_complete_callback(obs_status status, const obs_error_details *error, void *callback_data) { if (callback_data) { ((InventoryListInfo*)callback_data)->ret_status = status; } if (error && error->message) { printf("Error: %s\n", error->message); } } |
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