Obtaining a DIS Notification Policy
Function
You can call this API to query the DIS notification policy configured for an OBS bucket. All notification rules configured for the bucket are returned at a time, without pagination.
DIS notification policies are not available for fusion buckets.
Restrictions
- The mapping between OBS regions and endpoints must comply with what is listed in Regions and Endpoints.
- Before calling APIs related to DIS policies, you need to call obs.WithSignature(obs.SignatureObs) to specify the protocol type when initializing the obsClient.
Authorization Information
To call this API, you must be the bucket owner or have the Tenant Administrator permission. To configure the Tenant Administrator permission, you need to use role/policy-based authorization (IAM v3 APIs in the old IAM version). For details, see Using IAM for Authorization.
Method
func (obsClient ObsClient) GetDisPolicy(bucketName string, extensions ...extensionOptions) (output *GetDisPolicyOutput, err error)
Request Parameters
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| bucketName | string | Yes | Explanation: Bucket name. |
Response Parameter Description
| Field | Type | Description |
|---|---|---|
| BaseModel | BaseModel | Explanation: Basic model, including RequestId. |
| Rules | []DisPolicyRule | DIS policy rule list. Restrictions: For the same bucket, prefixes of different rules cannot be the same or contain each other. The same agency is recommended. Value range: The size of the array is from 1 to 10. |
| Field | Type | Description |
|---|---|---|
| ID | string | Rule ID. Value range: [1, 256]. The value must comply with ^[a-zA-Z0-9_-]{1, 256}$. |
| Stream | string | DIS stream name. You need to create a DIS stream first. |
| Project | string | ID of the project to which the DIS stream belongs. |
| Events | []string | OBS event list. A valid value must contain 0 to 1,023 characters. Any characters are allowed. The following event types are supported:
|
| Prefix | string | Object name prefix, key word of object names. Based on the prefix defined by this parameter, enter the key word for filtering objects. A longer string of characters delivers a more accurate filtering result. A maximum of 1,024 characters are supported. It also can be empty. In addition, the total length of the prefix and suffix cannot exceed 1024 characters. |
| Suffix | string | Object name suffix. Key word of object names. Based on the suffix defined by this parameter, enter the key word for filtering objects. A longer string of characters delivers a more accurate filtering result. A maximum of 1,024 characters are supported. It also can be empty. In addition, the total length of the prefix and suffix cannot exceed 1024 characters. |
| Agency | string | IAM agency name. The delegated party must include OBS and be granted the DIS Administrator or DIS User permission. |
Sample Code
This example queries the DIS notification policy configured for bucket examplebucket.
package main
import (
"fmt"
"log"
obs "github.com/huaweicloud/huaweicloud-sdk-go-obs/obs"
)
func main() {
// Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage.
// Obtain an AK/SK pair on the management console. For details, see https://support.huaweicloud.com/intl/en-us/usermanual-ca/ca_01_0003.html.
ak := os.Getenv("AccessKeyID")
sk := os.Getenv("SecretAccessKey")
// (Optional) If you use a temporary AK/SK pair and a security token to access OBS, you are not advised to use hard coding, which may result in information leakage. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways.
securityToken := os.Getenv("SecurityToken")
// Enter the endpoint corresponding to the bucket. CN-Hong Kong is used here as an example. Replace it with the one currently in use.
endPoint := "https://obs.ap-southeast-1.myhuaweicloud.com"
// Create a client.
obsClient, err := obs.New(ak, sk, endPoint, obs.WithSecurityToken(securityToken))
if err != nil {
fmt.Printf("Create obsClient error, errMsg: %s", err.Error())
}
// Obtain the DIS policy.
output, err := client.GetDisPolicy("my-bucket")
if err != nil {
log.Fatalf("Failed to get DIS policy: %v", err)
}
fmt.Printf("Request ID: %s\n", output.RequestId)
fmt.Printf("Total rules: %d\n\n", len(output.Rules))
for i, rule := range output.Rules {
fmt.Printf("[%d] DIS Rule:\n", i+1)
fmt.Printf(" ID: %s\n", rule.ID)
fmt.Printf(" Stream: %s\n", rule.Stream)
fmt.Printf(" Project: %s\n", rule.Project)
fmt.Printf(" Events: %v\n", rule.Events)
fmt.Printf(" Prefix: %s\n", rule.Prefix)
fmt.Printf(" Suffix: %s\n", rule.Suffix)
fmt.Printf(" Agency: %s\n", rule.Agency)
fmt.Println()
}
} Helpful Links
What is your overall rating for this page?
Thank 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