Obtaining the Direct Reading Configuration of a Bucket
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.
If direct reading is configured for a bucket, you can call this API to obtain the direct reading status of the bucket. For more information about direct reading, see Direct Reading.
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
func (obsClient ObsClient) GetBucketDirectColdAccess(BucketName *string) (output *GetBucketDirectColdAccessOutput, err error)
Request Parameters
| Parameter | Type | Mandatory (Yes/No) | Description |
|---|---|---|---|
| BucketName | string | Yes | Explanation: Bucket name. Restrictions:
Value range: None Default value: None |
Responses
| Parameter | Type | Description |
|---|---|---|
| output | Explanation: Returned results. For details, see Table 3. Value range: None | |
| err | error | Explanation: The error message returned by the server. Value range: None |
| Parameter | Type | Description |
|---|---|---|
| StatusCode | int | Explanation: HTTP status code. Value range: A status code is a group of digits that can be 2xx (indicating successes) or 4xx or 5xx (indicating errors). It indicates the status of a response. For more information, see Status Code. |
| RequestId | string | Explanation: Request ID returned by the OBS server. Value range: None |
| ResponseHeaders | map[string][]string | Explanation: HTTP response headers. Value range: None |
| DirectColdAccessConfiguration | Yes Explanation: Direct reading configuration of a bucket. Value range: See Table 4. |
| Parameter | Type | Mandatory (Yes/No) | Description |
|---|---|---|---|
| Status | Yes | Explanation: Direct reading status of a bucket Value range: See Table 5. Default value: None |
Sample Code
This example returns the direct reading configuration of bucket examplebucket.
package main
import (
"fmt"
"os"
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 an obsClient instance.
// If you use a temporary AK/SK pair and a security token to access OBS, use the obs.WithSecurityToken method to specify a security token when creating an instance.
obsClient, err := obs.New(ak, sk, endPoint, obs.WithSecurityToken(securityToken))
if err != nil {
fmt.Printf("Create obsClient error, errMsg: %s", err.Error())
}
// Specify a bucket name.
bucketName := "examplebucket"
// Obtain the direct reading configuration of the bucket.
output, err := obsClient.GetBucketDirectColdAccess(bucketName)
if err == nil {
fmt.Printf("Get bucket(%s)'s direct cold successful!\n", bucketName)
fmt.Printf("Direct cold access status: %s\n", output.Status)
fmt.Printf("RequestId:%s\n", output.RequestId)
return
}
fmt.Printf("Get bucket(%s)'s direct cold fail!\n", bucketName)
if obsError, ok := err.(obs.ObsError); ok {
fmt.Println("An ObsError was found, which means your request sent to OBS was rejected with an error response.")
fmt.Println(obsError.Error())
} else {
fmt.Println("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network.")
fmt.Println(err)
}
} 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