Updated on 2026-08-03 GMT+08:00

Obtaining a DIS Notification Policy (SDK for C)

If you have any questions during development, post them on the Issues page of GitHub.

Function

This API is used to obtain the DIS notification policy of a specified bucket.

Restrictions

Method

void get_bucket_dis_policy(const obs_options *options,
    obs_get_bucket_dis_policy_handler *handler, void *callback_data);

Request Parameters

Table 1 List of 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

Table 2*

Yes

Explanation:

A callback structure where all members are pointers to callback functions, 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

Table 2 obs_get_bucket_dis_policy_handler

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_dis_policy_callback

Table 3*

Yes

Explanation:

Pointer to the callback function of the DIS notification policy. You can record the content of dis_policy_rules in callback_data in this callback.

Restrictions:

None

Value range:

None

Default value:

None

Table 3 obs_get_bucket_dis_policy_callback

Parameter

Type

Mandatory (Yes/No)

Description

dis_policy_rules_return

Table 4*

Yes

Explanation:

Array of DIS notification rules, including information such as id, stream, and events.

Restrictions:

The structure 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

rule_number

unsigned int

Yes

Explanation:

Number of returned DIS notification 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

Table 4 obs_dis_policy_rule

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

This example obtains the DIS notification policy of a bucket.
 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
#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);
obs_status get_dis_policy_callback(obs_dis_policy_rule *dis_policy_rules_return,
    unsigned int rule_number, void *callback_data);
typedef struct DisPolicyInfo {
    obs_status ret_status;
} DisPolicyInfo;
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";
    obs_response_handler response_handler = {&response_properties_callback, &response_complete_callback};
    obs_get_bucket_dis_policy_handler get_dis_policy_handler = {
        response_handler,
        &get_dis_policy_callback
    };
    DisPolicyInfo dis_policy_info = {0};
    dis_policy_info.ret_status = OBS_STATUS_BUTT;
    // Obtain the DIS notification policy of a bucket.
    get_bucket_dis_policy(&options, &get_dis_policy_handler, &dis_policy_info);
    if (OBS_STATUS_OK == dis_policy_info.ret_status) {
        printf("get bucket dis policy successfully.\n");
    } else {
        printf("get bucket dis policy failed(%s).\n", obs_get_status_name(dis_policy_info.ret_status));
    }
    obs_deinitialize();
}
obs_status get_dis_policy_callback(obs_dis_policy_rule *dis_policy_rules_return,
    unsigned int rule_number, void *callback_data)
{
    if (dis_policy_rules_return) {
        unsigned int i;
        for (i = 0; i < rule_number; i++) {
            printf("rule[%u] id: %s\n", i, dis_policy_rules_return[i].id ? dis_policy_rules_return[i].id : "");
            printf("rule[%u] stream: %s\n", i, dis_policy_rules_return[i].stream ? dis_policy_rules_return[i].stream : "");
            printf("rule[%u] events_number: %u\n", i, dis_policy_rules_return[i].events_number);
        }
    }
    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) { ((DisPolicyInfo*)callback_data)->ret_status = status; }
    if (error && error->message) { printf("Error: %s\n", error->message); }
}