Configuring a DIS Notification Policy (SDK for C)
If you have any questions during development, post them on the Issues page of GitHub.
Function
The DIS notification policy is an event notification function provided by OBS. You can call this API to configure DIS notification rules for a specified bucket. When specified events occur on objects in the bucket, OBS pushes the event information to the DIS data stream.
Restrictions
- To configure a DIS notification policy for a bucket, you must be the bucket owner or have the required permission (obs:bucket:PutBucketDisPolicy granted using IAM or PutBucketDisPolicy 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.
- A maximum of 10 DIS notification rules can be configured for a bucket.
- Each rule ID must be unique within a bucket.
Method
void set_bucket_dis_policy(const obs_options *options,
obs_dis_policy_rule *dis_policy_rules,
unsigned int rule_number,
obs_response_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 |
| dis_policy_rules | Table 2 * | Yes | Explanation: Array of DIS notification policy rules. Each rule defines the event type, DIS stream, and filter criteria. Restrictions: None Value range: None Default value: None |
| rule_number | unsigned int | Yes | Explanation: Number of DIS notification rules. Restrictions: None Value range: 1 to 10 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 |
|---|---|---|---|
| id | char * | Yes | Explanation: Rule ID, which uniquely identifies a DIS event notification rule in a bucket. Restrictions: None Value range: The value can contain 1 to 256 characters and must match the regular expression ^[a-zA-Z0-9_-]{1,256}$. Default value: None |
| stream | char * | Yes | Explanation: Name of the DIS stream to which event information is pushed. Restrictions: None Value range: None Default value: None |
| project | char * | Yes | Explanation: Project ID (tenant ID), which identifies the project to which the DIS stream belongs. Restrictions: None Value range: None Default value: None |
| agency | char * | Yes | Explanation: Name of the agency, which is used to authorize OBS to push events to the DIS stream across accounts. Restrictions: None Value range: None Default value: None |
| events | char ** | Yes | Explanation: Event type array, which specifies the event types that trigger the notification. Restrictions: None Value range: ObjectCreated (which includes ObjectCreated:Put, ObjectCreated:Post, ObjectCreated:Copy, and ObjectCreated:CompleteMultipartUpload) and ObjectRemoved (which includes ObjectRemoved:Delete and ObjectRemoved:DeleteMarkerCreated) Default value: None |
| events_number | unsigned int | Yes | Explanation: Number of elements in the event type array. Restrictions: None Value range: 1 to 10 Default value: None |
| prefix | char * | No | Explanation: Object name prefix. The rule takes effect only for objects whose names contain the specified prefix. Restrictions: None Value range: None Default value: None |
| suffix | char * | No | Explanation: Object name suffix. The rule takes effect only for objects whose names contain the specified suffix. Restrictions: None Value range: None Default value: None |
Sample Code
#include "eSDKOBS.h"
#include <stdio.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);
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-bucket-name";
// Configure a DIS notification rule.
char *events[] = {"ObjectCreated:*"};
obs_dis_policy_rule rule = {0};
rule.id = "rule1";
rule.stream = "dis-stream-example";
rule.project = "project-id-example";
rule.agency = "agency-example";
rule.events = events;
rule.events_number = 1;
rule.prefix = "data/";
rule.suffix = NULL;
obs_dis_policy_rule dis_policy_rules[] = {rule};
obs_response_handler response_handler = {&response_properties_callback, &response_complete_callback};
obs_status ret_status = OBS_STATUS_BUTT;
// Configure a DIS notification policy for the bucket.
set_bucket_dis_policy(&options, dis_policy_rules, 1, &response_handler, &ret_status);
if (OBS_STATUS_OK == ret_status) {
printf("set bucket dis policy successfully.\n");
} else {
printf("set bucket dis policy failed(%s).\n", obs_get_status_name(ret_status));
}
obs_deinitialize();
}
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) { *(obs_status*)callback_data = 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