A bucket is a container for objects stored in OSS. Every object is contained in a bucket. This topic describes how to configure and obtain the access control list (ACL) of a bucket.
Configure the ACL of a bucket
The following table describes the ACLs for buckets.
For more information about ACLs, see Access control in OSS Developer Guide. For the complete code used to configure the ACL of a bucket, visit GitHub.
ACL | Description | Value |
---|---|---|
Private | Only the owner or authorized users of a bucket have the read and write permissions on objects in the bucket. | oss.ACLPrivate |
Public read | Only the owner or authorized users of a bucket have the read and write permissions on objects in the bucket. Other users have only the read permissions on the objects in the bucket. Exercise caution when you grant this permission. | oss.ACLPublicRead |
Public read/write | All users have the read and write permissions on all objects in the bucket. Exercise caution when you grant this permission. | oss.ACLPublicReadWrite |
The following code provides an example on how to configure the ACL for a bucket:
package main
import (
"fmt"
"os"
"github.com/aliyun/aliyun-oss-go-sdk/oss"
)
func main() {
// Create an OSSClient instance.
client, err := oss.New("<yourEndpoint>", "<yourAccessKeyId>", "<yourAccessKeySecret>")
if err ! = nil {
fmt.Println("Error:", err)
os.Exit(-1)
}
// Set the ACL of the bucket to public read.
err = client.SetBucketACL("<yourBucketName>", oss.ACLPublicRead)
if err ! = nil {
fmt.Println("Error:", err)
os.Exit(-1)
}
}
For more information about how to configure the ACL for a bucket, see PutBucketACL.
Obtain the ACL of a bucket
The following code provides an example on how to obtain the ACL of a bucket:
package main
import (
"fmt"
"os"
"github.com/aliyun/aliyun-oss-go-sdk/oss"
)
func main() {
// Create an OSSClient instance.
client, err := oss.New("<yourEndpoint>", "<yourAccessKeyId>", "<yourAccessKeySecret>")
if err ! = nil {
fmt.Println("Error:", err)
os.Exit(-1)
}
// Obtain the ACL of the bucket.
aclRes, err := client.GetBucketACL("<yourBucketName>")
if err ! = nil {
fmt.Println("Error:", err)
os.Exit(-1)
}
fmt.Println("Bucket ACL:", aclRes.ACL)
}
For more information about how to obtain the ACL of a bucket, see GetBucketAcl.