Object ACL now propagates through ACL config, update minio-go library to bing in SetObjectACL() support
This commit is contained in:
@@ -16,6 +16,8 @@
|
||||
|
||||
package main
|
||||
|
||||
import "github.com/minio/minio/pkg/probe"
|
||||
|
||||
// isValidBucketPERM - is provided acl string supported
|
||||
func (b bucketPerms) isValidBucketPERM() bool {
|
||||
switch true {
|
||||
@@ -78,3 +80,12 @@ func (b bucketPerms) isPublic() bool {
|
||||
func (b bucketPerms) isAuthenticated() bool {
|
||||
return b == bucketAuthenticated
|
||||
}
|
||||
|
||||
// getConfigACL - read ACL from config
|
||||
func getConfigACL() (acl string, err *probe.Error) {
|
||||
config, err := getMcConfig()
|
||||
if err != nil {
|
||||
return "", err.Trace()
|
||||
}
|
||||
return config.ACL, nil
|
||||
}
|
||||
|
||||
+3
-2
@@ -108,13 +108,14 @@ func (s *CmdTestSuite) TestNewConfigV2(c *C) {
|
||||
perr = conf.Save(configFile)
|
||||
c.Assert(perr, IsNil)
|
||||
|
||||
confNew := newConfigV2()
|
||||
confNew := newConfigV3()
|
||||
config, perr := quick.New(confNew)
|
||||
c.Assert(perr, IsNil)
|
||||
perr = config.Load(configFile)
|
||||
c.Assert(perr, IsNil)
|
||||
data := config.Data().(*configV2)
|
||||
data := config.Data().(*configV3)
|
||||
|
||||
c.Assert(data.ACL, Equals, "private")
|
||||
type aliases struct {
|
||||
name string
|
||||
url string
|
||||
|
||||
@@ -157,6 +157,11 @@ func getNewClient(urlStr string, auth hostConfig) (client.Client, *probe.Error)
|
||||
s3Config.AppVersion = globalMCVersion
|
||||
s3Config.AppComments = []string{os.Args[0], runtime.GOOS, runtime.GOARCH}
|
||||
s3Config.HostURL = urlStr
|
||||
acl, err := getConfigACL()
|
||||
if err != nil {
|
||||
return nil, err.Trace()
|
||||
}
|
||||
s3Config.ACL = acl
|
||||
s3Config.Debug = globalDebugFlag
|
||||
s3Client, err := s3.New(s3Config)
|
||||
if err != nil {
|
||||
|
||||
+5
-6
@@ -168,7 +168,7 @@ func listAliases() {
|
||||
fatalIf(err.Trace(configPath), "Unable to load config path")
|
||||
|
||||
// convert interface{} back to its original struct
|
||||
newConf := config.Data().(*configV2)
|
||||
newConf := config.Data().(*configV3)
|
||||
for k, v := range newConf.Aliases {
|
||||
console.Println(AliasMessage{
|
||||
op: "list",
|
||||
@@ -183,7 +183,7 @@ func removeAlias(alias string) {
|
||||
if alias == "" {
|
||||
fatalIf(errDummy().Trace(), "Alias or URL cannot be empty.")
|
||||
}
|
||||
conf := newConfigV2()
|
||||
conf := newConfigV3()
|
||||
config, err := quick.New(conf)
|
||||
fatalIf(err.Trace(conf.Version), "Failed to initialize ‘quick’ configuration data structure.")
|
||||
|
||||
@@ -196,8 +196,7 @@ func removeAlias(alias string) {
|
||||
fatalIf(errDummy().Trace(), fmt.Sprintf("Alias name ‘%s’ is invalid, valid examples are: mybucket, Area51, Grand-Nagus", alias))
|
||||
}
|
||||
// convert interface{} back to its original struct
|
||||
newConf := config.Data().(*configV2)
|
||||
|
||||
newConf := config.Data().(*configV3)
|
||||
if _, ok := newConf.Aliases[alias]; !ok {
|
||||
fatalIf(errDummy().Trace(), fmt.Sprintf("Alias ‘%s’ does not exist.", alias))
|
||||
}
|
||||
@@ -220,7 +219,7 @@ func addAlias(alias, url string) {
|
||||
if alias == "" || url == "" {
|
||||
fatalIf(errDummy().Trace(), "Alias or URL cannot be empty.")
|
||||
}
|
||||
conf := newConfigV2()
|
||||
conf := newConfigV3()
|
||||
config, err := quick.New(conf)
|
||||
fatalIf(err.Trace(conf.Version), "Failed to initialize ‘quick’ configuration data structure.")
|
||||
|
||||
@@ -238,7 +237,7 @@ func addAlias(alias, url string) {
|
||||
fatalIf(errDummy().Trace(), fmt.Sprintf("Alias name ‘%s’ is invalid, valid examples are: mybucket, Area51, Grand-Nagus", alias))
|
||||
}
|
||||
// convert interface{} back to its original struct
|
||||
newConf := config.Data().(*configV2)
|
||||
newConf := config.Data().(*configV3)
|
||||
if oldURL, ok := newConf.Aliases[alias]; ok {
|
||||
fatalIf(errDummy().Trace(), fmt.Sprintf("Alias ‘%s’ already exists for ‘%s’.", alias, oldURL))
|
||||
}
|
||||
|
||||
@@ -34,6 +34,13 @@ type configV2 struct {
|
||||
Hosts map[string]hostConfig
|
||||
}
|
||||
|
||||
type configV3 struct {
|
||||
Version string
|
||||
ACL string
|
||||
Aliases map[string]string
|
||||
Hosts map[string]hostConfig
|
||||
}
|
||||
|
||||
// for backward compatibility
|
||||
type configV101 configV2
|
||||
type configV1 configV2
|
||||
@@ -105,7 +112,7 @@ func mustGetMcConfigPath() string {
|
||||
}
|
||||
|
||||
// getMcConfig - reads configuration file and returns config
|
||||
func getMcConfig() (*configV2, *probe.Error) {
|
||||
func getMcConfig() (*configV3, *probe.Error) {
|
||||
if !isMcConfigExists() {
|
||||
return nil, errInvalidArgument().Trace()
|
||||
}
|
||||
@@ -117,10 +124,10 @@ func getMcConfig() (*configV2, *probe.Error) {
|
||||
|
||||
// Cached in private global variable.
|
||||
if v := cache.Get(); v != nil { // Use previously cached config.
|
||||
return v.(quick.Config).Data().(*configV2), nil
|
||||
return v.(quick.Config).Data().(*configV3), nil
|
||||
}
|
||||
|
||||
conf := newConfigV2()
|
||||
conf := newConfigV3()
|
||||
qconf, err := quick.New(conf)
|
||||
if err != nil {
|
||||
return nil, err.Trace()
|
||||
@@ -131,12 +138,12 @@ func getMcConfig() (*configV2, *probe.Error) {
|
||||
return nil, err.Trace()
|
||||
}
|
||||
cache.Put(qconf)
|
||||
return qconf.Data().(*configV2), nil
|
||||
return qconf.Data().(*configV3), nil
|
||||
|
||||
}
|
||||
|
||||
// mustGetMcConfig - reads configuration file and returns configs, exits on error
|
||||
func mustGetMcConfig() *configV2 {
|
||||
func mustGetMcConfig() *configV3 {
|
||||
config, err := getMcConfig()
|
||||
fatalIf(err.Trace(), "Unable to get mcConfig.")
|
||||
|
||||
@@ -179,6 +186,8 @@ func migrateConfig() {
|
||||
migrateConfigV1ToV101()
|
||||
// Migrate config V101 to V2
|
||||
migrateConfigV101ToV2()
|
||||
// Migrate config V2 to V3
|
||||
migrateConfigV2ToV3()
|
||||
}
|
||||
|
||||
func migrateConfigV1ToV101() {
|
||||
@@ -243,6 +252,31 @@ func migrateConfigV101ToV2() {
|
||||
}
|
||||
}
|
||||
|
||||
func migrateConfigV2ToV3() {
|
||||
if !isMcConfigExists() {
|
||||
return
|
||||
}
|
||||
mcConfigV2, err := quick.Load(mustGetMcConfigPath(), newConfigV2())
|
||||
fatalIf(err.Trace(), "Unable to load config.")
|
||||
|
||||
// update to newer version
|
||||
if mcConfigV2.Version() == "2" {
|
||||
confV3 := new(configV3)
|
||||
confV3.Aliases = mcConfigV2.Data().(*configV2).Aliases
|
||||
confV3.Hosts = mcConfigV2.Data().(*configV2).Hosts
|
||||
confV3.Version = globalMCConfigVersion
|
||||
confV3.ACL = "private"
|
||||
|
||||
mcNewConfigV3, err := quick.New(confV3)
|
||||
fatalIf(err.Trace(), "Unable to initialize quick config.")
|
||||
|
||||
err = mcNewConfigV3.Save(mustGetMcConfigPath())
|
||||
fatalIf(err.Trace(), "Unable to save config.")
|
||||
|
||||
console.Infof("Successfully migrated %s from version ‘2’ to version: ‘3’.\n", mustGetMcConfigPath())
|
||||
}
|
||||
}
|
||||
|
||||
// newConfigV1() - get new config version 1.0.0
|
||||
func newConfigV1() *configV1 {
|
||||
conf := new(configV1)
|
||||
@@ -262,7 +296,6 @@ func newConfigV101() *configV101 {
|
||||
// exits silently without providing any errors
|
||||
conf.Hosts = make(map[string]hostConfig)
|
||||
conf.Aliases = make(map[string]string)
|
||||
|
||||
return conf
|
||||
}
|
||||
|
||||
@@ -270,6 +303,18 @@ func newConfigV101() *configV101 {
|
||||
func newConfigV2() *configV2 {
|
||||
conf := new(configV2)
|
||||
conf.Version = globalMCConfigVersion
|
||||
// make sure to allocate map's otherwise Golang
|
||||
// exits silently without providing any errors
|
||||
conf.Hosts = make(map[string]hostConfig)
|
||||
conf.Aliases = make(map[string]string)
|
||||
return conf
|
||||
}
|
||||
|
||||
// newConfigV3 - get new config version 3
|
||||
func newConfigV3() *configV3 {
|
||||
conf := new(configV3)
|
||||
conf.Version = globalMCConfigVersion
|
||||
|
||||
// make sure to allocate map's otherwise Golang
|
||||
// exits silently without providing any errors
|
||||
conf.Hosts = make(map[string]hostConfig)
|
||||
@@ -310,13 +355,14 @@ func newConfigV2() *configV2 {
|
||||
aliases["dl"] = "https://dl.minio.io:9000"
|
||||
aliases["localhost"] = "http://localhost:9000"
|
||||
conf.Aliases = aliases
|
||||
conf.ACL = "private"
|
||||
|
||||
return conf
|
||||
}
|
||||
|
||||
// newConfig - get new config interface
|
||||
func newConfig() (config quick.Config, err *probe.Error) {
|
||||
conf := newConfigV2()
|
||||
conf := newConfigV3()
|
||||
config, err = quick.New(conf)
|
||||
if err != nil {
|
||||
return nil, err.Trace()
|
||||
|
||||
@@ -38,7 +38,6 @@ package main
|
||||
|
||||
// Version autogenerated
|
||||
const Version = {{if .Date}}"{{.Date}}"{{else}}""{{end}}
|
||||
|
||||
`
|
||||
t := template.Must(template.New("version").Parse(versionTemplate))
|
||||
versionFile, err := os.OpenFile("version.go", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@ var (
|
||||
|
||||
// mc configuration related constants.
|
||||
const (
|
||||
globalMCConfigVersion = "2"
|
||||
globalMCConfigVersion = "3"
|
||||
globalMCVersion = Version
|
||||
|
||||
globalMCConfigDir = ".mc/"
|
||||
|
||||
@@ -38,6 +38,7 @@ type Client interface {
|
||||
Share(expires time.Duration) (string, *probe.Error)
|
||||
GetObject(offset, length int64) (body io.ReadCloser, size int64, err *probe.Error)
|
||||
PutObject(size int64, data io.Reader) *probe.Error
|
||||
SetObjectACL(acl string) *probe.Error
|
||||
|
||||
// URL returns back internal url
|
||||
URL() *URL
|
||||
|
||||
+21
-3
@@ -75,8 +75,26 @@ func (f *fsClient) fsStat() (os.FileInfo, *probe.Error) {
|
||||
return st, nil
|
||||
}
|
||||
|
||||
// SetObjectACL - set new acl
|
||||
func (f *fsClient) SetObjectACL(acl string) *probe.Error {
|
||||
if !isValidACL(acl) {
|
||||
return probe.NewError(client.InvalidACLType{ACL: acl})
|
||||
}
|
||||
_, err := os.Stat(f.path)
|
||||
if err != nil {
|
||||
return probe.NewError(err)
|
||||
}
|
||||
err = os.Chmod(f.path, aclToPerm(acl))
|
||||
if err != nil {
|
||||
return probe.NewError(err)
|
||||
}
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
// PutObject - create a new file
|
||||
func (f *fsClient) PutObject(size int64, data io.Reader) *probe.Error {
|
||||
// for filesystem we will not support any ACL's in PutObject()
|
||||
objectDir, _ := filepath.Split(f.path)
|
||||
objectPath := f.path
|
||||
if objectDir != "" {
|
||||
@@ -349,8 +367,8 @@ func (f *fsClient) listRecursiveInRoutine(contentCh chan client.ContentOnChannel
|
||||
}
|
||||
}
|
||||
|
||||
// isValidBucketACL - is acl a valid ACL?
|
||||
func isValidBucketACL(acl string) bool {
|
||||
// isValidACL - is acl a valid ACL?
|
||||
func isValidACL(acl string) bool {
|
||||
switch acl {
|
||||
case "private":
|
||||
fallthrough
|
||||
@@ -394,7 +412,7 @@ func (f *fsClient) MakeBucket() *probe.Error {
|
||||
|
||||
// SetBucketACL - create a new bucket
|
||||
func (f *fsClient) SetBucketACL(acl string) *probe.Error {
|
||||
if !isValidBucketACL(acl) {
|
||||
if !isValidACL(acl) {
|
||||
return probe.NewError(client.InvalidACLType{ACL: acl})
|
||||
}
|
||||
err := os.MkdirAll(f.path, aclToPerm(acl))
|
||||
|
||||
+21
-4
@@ -39,6 +39,9 @@ type Config struct {
|
||||
AppComments []string
|
||||
Debug bool
|
||||
|
||||
// Used for Bucket/Object ACL
|
||||
ACL string
|
||||
|
||||
// Used for SSL transport layer
|
||||
CertPEM string
|
||||
KeyPEM string
|
||||
@@ -52,6 +55,7 @@ type TLSConfig struct {
|
||||
|
||||
type s3Client struct {
|
||||
api minio.API
|
||||
acl string
|
||||
hostURL *client.URL
|
||||
}
|
||||
|
||||
@@ -83,7 +87,7 @@ func New(config *Config) (client.Client, *probe.Error) {
|
||||
if err != nil {
|
||||
return nil, probe.NewError(err)
|
||||
}
|
||||
return &s3Client{api: api, hostURL: u}, nil
|
||||
return &s3Client{api: api, hostURL: u, acl: config.ACL}, nil
|
||||
}
|
||||
|
||||
// URL get url
|
||||
@@ -117,7 +121,7 @@ func (c *s3Client) PutObject(size int64, data io.Reader) *probe.Error {
|
||||
// for a multipart upload and there is no need to cross verify,
|
||||
// invidual parts are properly verified
|
||||
bucket, object := c.url2BucketAndObject()
|
||||
err := c.api.PutObject(bucket, object, "application/octet-stream", size, data)
|
||||
err := c.api.PutObject(bucket, object, "application/octet-stream", minio.ACL(c.acl), size, data)
|
||||
if err != nil {
|
||||
errResponse := minio.ToErrorResponse(err)
|
||||
if errResponse != nil {
|
||||
@@ -130,13 +134,26 @@ func (c *s3Client) PutObject(size int64, data io.Reader) *probe.Error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetObjectACL - set object acl
|
||||
func (c *s3Client) SetObjectACL(acl string) *probe.Error {
|
||||
bucket, object := c.url2BucketAndObject()
|
||||
if object == "" {
|
||||
return probe.NewError(client.InvalidQueryURL{URL: c.hostURL.String()})
|
||||
}
|
||||
err := c.api.SetObjectACL(bucket, object, minio.ACL(acl))
|
||||
if err != nil {
|
||||
return probe.NewError(err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// MakeBucket - make a new bucket
|
||||
func (c *s3Client) MakeBucket() *probe.Error {
|
||||
bucket, object := c.url2BucketAndObject()
|
||||
if object != "" {
|
||||
return probe.NewError(client.InvalidQueryURL{URL: c.hostURL.String()})
|
||||
}
|
||||
err := c.api.MakeBucket(bucket, minio.BucketACL("private"))
|
||||
err := c.api.MakeBucket(bucket, minio.ACL("private"))
|
||||
if err != nil {
|
||||
return probe.NewError(err)
|
||||
}
|
||||
@@ -149,7 +166,7 @@ func (c *s3Client) SetBucketACL(acl string) *probe.Error {
|
||||
if object != "" {
|
||||
return probe.NewError(client.InvalidQueryURL{URL: c.hostURL.String()})
|
||||
}
|
||||
err := c.api.SetBucketACL(bucket, minio.BucketACL(acl))
|
||||
err := c.api.SetBucketACL(bucket, minio.ACL(acl))
|
||||
if err != nil {
|
||||
return probe.NewError(err)
|
||||
}
|
||||
|
||||
+2
-2
@@ -41,8 +41,8 @@
|
||||
"canonical": "github.com/minio/minio-go",
|
||||
"comment": "",
|
||||
"local": "vendor/github.com/minio/minio-go",
|
||||
"revision": "7860bcf566f9e641f94a4d85ac60a4f3a0883f46",
|
||||
"revisionTime": "2015-08-28T00:38:53-07:00"
|
||||
"revision": "1e3ce581b7c50b431bb68db5d03d59927ce4d1fd",
|
||||
"revisionTime": "2015-08-28T19:47:26-07:00"
|
||||
},
|
||||
{
|
||||
"canonical": "github.com/minio/minio/pkg/probe",
|
||||
|
||||
Generated
Vendored
+18
-18
@@ -16,27 +16,27 @@
|
||||
|
||||
package minio
|
||||
|
||||
// BucketACL - bucket level access control
|
||||
type BucketACL string
|
||||
// ACL - level access control
|
||||
type ACL string
|
||||
|
||||
// different types of ACL's currently supported for buckets
|
||||
// different types of ACL's currently supported
|
||||
const (
|
||||
bucketPrivate = BucketACL("private")
|
||||
bucketReadOnly = BucketACL("public-read")
|
||||
bucketPublic = BucketACL("public-read-write")
|
||||
bucketAuthenticated = BucketACL("authenticated-read")
|
||||
Private = ACL("private")
|
||||
ReadOnly = ACL("public-read")
|
||||
Public = ACL("public-read-write")
|
||||
Authenticated = ACL("authenticated-read")
|
||||
)
|
||||
|
||||
// String printer helper
|
||||
func (b BucketACL) String() string {
|
||||
func (b ACL) String() string {
|
||||
if string(b) == "" {
|
||||
return "private"
|
||||
}
|
||||
return string(b)
|
||||
}
|
||||
|
||||
// isValidBucketACL - is provided acl string supported
|
||||
func (b BucketACL) isValidBucketACL() bool {
|
||||
// isValidACL - is provided acl string supported
|
||||
func (b ACL) isValidACL() bool {
|
||||
switch true {
|
||||
case b.isPrivate():
|
||||
fallthrough
|
||||
@@ -55,21 +55,21 @@ func (b BucketACL) isValidBucketACL() bool {
|
||||
}
|
||||
|
||||
// IsPrivate - is acl Private
|
||||
func (b BucketACL) isPrivate() bool {
|
||||
return b == bucketPrivate
|
||||
func (b ACL) isPrivate() bool {
|
||||
return b == Private
|
||||
}
|
||||
|
||||
// IsPublicRead - is acl PublicRead
|
||||
func (b BucketACL) isReadOnly() bool {
|
||||
return b == bucketReadOnly
|
||||
func (b ACL) isReadOnly() bool {
|
||||
return b == ReadOnly
|
||||
}
|
||||
|
||||
// IsPublicReadWrite - is acl PublicReadWrite
|
||||
func (b BucketACL) isPublic() bool {
|
||||
return b == bucketPublic
|
||||
func (b ACL) isPublic() bool {
|
||||
return b == Public
|
||||
}
|
||||
|
||||
// IsAuthenticated - is acl AuthenticatedRead
|
||||
func (b BucketACL) isAuthenticated() bool {
|
||||
return b == bucketAuthenticated
|
||||
func (b ACL) isAuthenticated() bool {
|
||||
return b == Authenticated
|
||||
}
|
||||
+101
-8
@@ -88,13 +88,10 @@ func (a apiV1) putBucketRequest(bucket, acl, location string) (*request, error)
|
||||
r.req.ContentLength = int64(createBucketConfigBuffer.Len())
|
||||
}
|
||||
// by default bucket is private
|
||||
switch {
|
||||
case acl != "":
|
||||
r.Set("x-amz-acl", "private")
|
||||
if acl != "" {
|
||||
r.Set("x-amz-acl", acl)
|
||||
default:
|
||||
r.Set("x-amz-acl", "private")
|
||||
}
|
||||
|
||||
return r, nil
|
||||
}
|
||||
|
||||
@@ -523,7 +520,7 @@ func (a apiV1) putObjectUnAuthenticated(bucket, object, contentType string, size
|
||||
}
|
||||
|
||||
// putObjectRequest wrapper creates a new PutObject request
|
||||
func (a apiV1) putObjectRequest(bucket, object, contentType string, md5SumBytes []byte, size int64, body io.ReadSeeker) (*request, error) {
|
||||
func (a apiV1) putObjectRequest(bucket, object, contentType, acl string, md5SumBytes []byte, size int64, body io.ReadSeeker) (*request, error) {
|
||||
if strings.TrimSpace(contentType) == "" {
|
||||
contentType = "application/octet-stream"
|
||||
}
|
||||
@@ -540,6 +537,11 @@ func (a apiV1) putObjectRequest(bucket, object, contentType string, md5SumBytes
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
r.Set("x-amz-acl", "private")
|
||||
if acl != "" {
|
||||
r.Set("x-amz-acl", acl)
|
||||
}
|
||||
// set Content-MD5 as base64 encoded md5
|
||||
r.Set("Content-MD5", base64.StdEncoding.EncodeToString(md5SumBytes))
|
||||
r.Set("Content-Type", contentType)
|
||||
@@ -549,8 +551,8 @@ func (a apiV1) putObjectRequest(bucket, object, contentType string, md5SumBytes
|
||||
|
||||
// putObject - add an object to a bucket
|
||||
// NOTE: You must have WRITE permissions on a bucket to add an object to it.
|
||||
func (a apiV1) putObject(bucket, object, contentType string, md5SumBytes []byte, size int64, body io.ReadSeeker) (ObjectStat, error) {
|
||||
req, err := a.putObjectRequest(bucket, object, contentType, md5SumBytes, size, body)
|
||||
func (a apiV1) putObject(bucket, object, contentType, acl string, md5SumBytes []byte, size int64, body io.ReadSeeker) (ObjectStat, error) {
|
||||
req, err := a.putObjectRequest(bucket, object, contentType, acl, md5SumBytes, size, body)
|
||||
if err != nil {
|
||||
return ObjectStat{}, err
|
||||
}
|
||||
@@ -577,6 +579,97 @@ func (a apiV1) putObject(bucket, object, contentType string, md5SumBytes []byte,
|
||||
return metadata, nil
|
||||
}
|
||||
|
||||
// putObjectACLRequest wrapper creates a new PutObjectACL request
|
||||
func (a apiV1) putObjectACLRequest(bucket, object, acl string) (*request, error) {
|
||||
encodedObject, err := urlEncodeName(object)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
op := &operation{
|
||||
HTTPServer: a.config.Endpoint,
|
||||
HTTPMethod: "PUT",
|
||||
HTTPPath: separator + bucket + separator + encodedObject + "?acl",
|
||||
}
|
||||
r, err := newRequest(op, a.config, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
r.Set("x-amz-acl", acl)
|
||||
return r, nil
|
||||
}
|
||||
|
||||
// putObject - add an object to a bucket
|
||||
// NOTE: You must have WRITE permissions on a bucket to add an object to it.
|
||||
func (a apiV1) putObjectACL(bucket, object, acl string) error {
|
||||
req, err := a.putObjectACLRequest(bucket, object, acl)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
resp, err := req.Do()
|
||||
defer closeResp(resp)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if resp != nil {
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return BodyToErrorResponse(resp.Body, a.config.AcceptType)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// getObjectACLRequest wrapper creates a new getObjectACL request
|
||||
func (a apiV1) getObjectACLRequest(bucket, object string) (*request, error) {
|
||||
encodedObject, err := urlEncodeName(object)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
op := &operation{
|
||||
HTTPServer: a.config.Endpoint,
|
||||
HTTPMethod: "GET",
|
||||
HTTPPath: separator + bucket + separator + encodedObject + "?acl",
|
||||
}
|
||||
req, err := newRequest(op, a.config, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return req, nil
|
||||
}
|
||||
|
||||
// getObjectACL get the acl information on an existing bucket
|
||||
func (a apiV1) getObjectACL(bucket, object string) (accessControlPolicy, error) {
|
||||
req, err := a.getObjectACLRequest(bucket, object)
|
||||
if err != nil {
|
||||
return accessControlPolicy{}, err
|
||||
}
|
||||
resp, err := req.Do()
|
||||
defer closeResp(resp)
|
||||
if err != nil {
|
||||
return accessControlPolicy{}, err
|
||||
}
|
||||
if resp != nil {
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return accessControlPolicy{}, BodyToErrorResponse(resp.Body, a.config.AcceptType)
|
||||
}
|
||||
}
|
||||
policy := accessControlPolicy{}
|
||||
err = acceptTypeDecoder(resp.Body, a.config.AcceptType, &policy)
|
||||
if err != nil {
|
||||
return accessControlPolicy{}, err
|
||||
}
|
||||
if policy.AccessControlList.Grant == nil {
|
||||
errorResponse := ErrorResponse{
|
||||
Code: "InternalError",
|
||||
Message: "Access control Grant list is empty, please report this at https://github.com/minio/minio-go/issues",
|
||||
Resource: separator + bucket + separator + object,
|
||||
RequestID: resp.Header.Get("x-amz-request-id"),
|
||||
HostID: resp.Header.Get("x-amz-id-2"),
|
||||
}
|
||||
return accessControlPolicy{}, errorResponse
|
||||
}
|
||||
return policy, nil
|
||||
}
|
||||
|
||||
func (a apiV1) presignedGetObjectRequest(bucket, object string, expires, offset, length int64) (*request, error) {
|
||||
encodedObject, err := urlEncodeName(object)
|
||||
if err != nil {
|
||||
|
||||
+93
-18
@@ -44,11 +44,11 @@ type API interface {
|
||||
|
||||
// BucketAPI - bucket specific Read/Write/Stat interface
|
||||
type BucketAPI interface {
|
||||
MakeBucket(bucket string, cannedACL BucketACL) error
|
||||
MakeBucket(bucket string, cannedACL ACL) error
|
||||
BucketExists(bucket string) error
|
||||
RemoveBucket(bucket string) error
|
||||
SetBucketACL(bucket string, cannedACL BucketACL) error
|
||||
GetBucketACL(bucket string) (BucketACL, error)
|
||||
SetBucketACL(bucket string, acl ACL) error
|
||||
GetBucketACL(bucket string) (ACL, error)
|
||||
|
||||
ListBuckets() <-chan BucketStatCh
|
||||
ListObjects(bucket, prefix string, recursive bool) <-chan ObjectStatCh
|
||||
@@ -61,7 +61,9 @@ type BucketAPI interface {
|
||||
type ObjectAPI interface {
|
||||
GetObject(bucket, object string) (io.ReadCloser, ObjectStat, error)
|
||||
GetPartialObject(bucket, object string, offset, length int64) (io.ReadCloser, ObjectStat, error)
|
||||
PutObject(bucket, object, contentType string, size int64, data io.Reader) error
|
||||
PutObject(bucket, object, contentType string, acl ACL, size int64, data io.Reader) error
|
||||
SetObjectACL(bucket, object string, acl ACL) error
|
||||
GetObjectACL(bucket, object string) (ACL, error)
|
||||
StatObject(bucket, object string) (ObjectStat, error)
|
||||
RemoveObject(bucket, object string) error
|
||||
|
||||
@@ -499,13 +501,16 @@ func (a apiV2) listMultipartUploadsRecursiveInRoutine(bucket, object string, ch
|
||||
// You must have WRITE permissions on a bucket to create an object
|
||||
//
|
||||
// This version of PutObject automatically does multipart for more than 5MB worth of data
|
||||
func (a apiV2) PutObject(bucket, object, contentType string, size int64, data io.Reader) error {
|
||||
func (a apiV2) PutObject(bucket, object, contentType string, acl ACL, size int64, data io.Reader) error {
|
||||
if err := invalidBucketError(bucket); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := invalidArgumentError(object); err != nil {
|
||||
return err
|
||||
}
|
||||
if !acl.isValidACL() {
|
||||
return invalidArgumentError("")
|
||||
}
|
||||
// for un-authenticated requests do not initiated multipart operation
|
||||
//
|
||||
// NOTE: this behavior is only kept valid for S3, since S3 doesn't
|
||||
@@ -534,7 +539,7 @@ func (a apiV2) PutObject(bucket, object, contentType string, size int64, data io
|
||||
Resource: separator + bucket + separator + object,
|
||||
}
|
||||
}
|
||||
_, err := a.putObject(bucket, object, contentType, part.MD5Sum, part.Len, part.ReadSeeker)
|
||||
_, err := a.putObject(bucket, object, contentType, string(acl), part.MD5Sum, part.Len, part.ReadSeeker)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -554,13 +559,83 @@ func (a apiV2) PutObject(bucket, object, contentType string, size int64, data io
|
||||
}
|
||||
}
|
||||
if !inProgress {
|
||||
return a.newObjectUpload(bucket, object, contentType, size, data)
|
||||
if err := a.newObjectUpload(bucket, object, contentType, size, data); err != nil {
|
||||
return err
|
||||
}
|
||||
return a.putObjectACL(bucket, object, string(acl))
|
||||
}
|
||||
return a.continueObjectUpload(bucket, object, inProgressUploadID, size, data)
|
||||
if err := a.continueObjectUpload(bucket, object, inProgressUploadID, size, data); err != nil {
|
||||
return err
|
||||
}
|
||||
return a.putObjectACL(bucket, object, string(acl))
|
||||
}
|
||||
return errors.New("Unexpected control flow, please report this error at https://github.com/minio/minio-go/issues")
|
||||
}
|
||||
|
||||
// GetObjectACL get the permissions on an existing object
|
||||
//
|
||||
// Returned values are:
|
||||
//
|
||||
// private - owner gets full access
|
||||
// public-read - owner gets full access, others get read access
|
||||
// public-read-write - owner gets full access, others get full access too
|
||||
// authenticated-read - owner gets full access, authenticated users get read access
|
||||
//
|
||||
func (a apiV2) GetObjectACL(bucket, object string) (ACL, error) {
|
||||
if err := invalidBucketError(bucket); err != nil {
|
||||
return "", err
|
||||
}
|
||||
if err := invalidArgumentError(object); err != nil {
|
||||
return "", err
|
||||
}
|
||||
policy, err := a.getObjectACL(bucket, object)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
grants := policy.AccessControlList.Grant
|
||||
switch {
|
||||
case len(grants) == 1:
|
||||
if grants[0].Grantee.URI == "" && grants[0].Permission == "FULL_CONTROL" {
|
||||
return ACL("private"), nil
|
||||
}
|
||||
case len(grants) == 2:
|
||||
for _, g := range grants {
|
||||
if g.Grantee.URI == "http://acs.amazonaws.com/groups/global/AuthenticatedUsers" && g.Permission == "READ" {
|
||||
return ACL("authenticated-read"), nil
|
||||
}
|
||||
if g.Grantee.URI == "http://acs.amazonaws.com/groups/global/AllUsers" && g.Permission == "READ" {
|
||||
return ACL("public-read"), nil
|
||||
}
|
||||
}
|
||||
case len(grants) == 3:
|
||||
for _, g := range grants {
|
||||
if g.Grantee.URI == "http://acs.amazonaws.com/groups/global/AllUsers" && g.Permission == "WRITE" {
|
||||
return ACL("public-read-write"), nil
|
||||
}
|
||||
}
|
||||
}
|
||||
return "", ErrorResponse{
|
||||
Code: "NoSuchObjectPolicy",
|
||||
Message: "The specified object does not have a access policy.",
|
||||
Resource: separator + bucket + separator + object,
|
||||
RequestID: "minio",
|
||||
}
|
||||
}
|
||||
|
||||
// SetObjectACL set object acl's
|
||||
func (a apiV2) SetObjectACL(bucket, object string, acl ACL) error {
|
||||
if err := invalidBucketError(bucket); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := invalidArgumentError(object); err != nil {
|
||||
return err
|
||||
}
|
||||
if !acl.isValidACL() {
|
||||
return invalidArgumentError("")
|
||||
}
|
||||
return a.putObjectACL(bucket, object, string(acl))
|
||||
}
|
||||
|
||||
// StatObject verify if object exists and you have permission to access it
|
||||
func (a apiV2) StatObject(bucket, object string) (ObjectStat, error) {
|
||||
if err := invalidBucketError(bucket); err != nil {
|
||||
@@ -602,11 +677,11 @@ func (a apiV2) RemoveObject(bucket, object string) error {
|
||||
//
|
||||
// [ us-west-1 | us-west-2 | eu-west-1 | eu-central-1 | ap-southeast-1 | ap-northeast-1 | ap-southeast-2 | sa-east-1 ]
|
||||
// Default - US standard
|
||||
func (a apiV2) MakeBucket(bucket string, acl BucketACL) error {
|
||||
func (a apiV2) MakeBucket(bucket string, acl ACL) error {
|
||||
if err := invalidBucketError(bucket); err != nil {
|
||||
return err
|
||||
}
|
||||
if !acl.isValidBucketACL() {
|
||||
if !acl.isValidACL() {
|
||||
return invalidArgumentError("")
|
||||
}
|
||||
location := a.config.Region
|
||||
@@ -628,11 +703,11 @@ func (a apiV2) MakeBucket(bucket string, acl BucketACL) error {
|
||||
// public-read-write - owner gets full access, all others get full access too
|
||||
// authenticated-read - owner gets full access, authenticated users get read access
|
||||
//
|
||||
func (a apiV2) SetBucketACL(bucket string, acl BucketACL) error {
|
||||
func (a apiV2) SetBucketACL(bucket string, acl ACL) error {
|
||||
if err := invalidBucketError(bucket); err != nil {
|
||||
return err
|
||||
}
|
||||
if !acl.isValidBucketACL() {
|
||||
if !acl.isValidACL() {
|
||||
return invalidArgumentError("")
|
||||
}
|
||||
return a.putBucketACL(bucket, string(acl))
|
||||
@@ -647,7 +722,7 @@ func (a apiV2) SetBucketACL(bucket string, acl BucketACL) error {
|
||||
// public-read-write - owner gets full access, others get full access too
|
||||
// authenticated-read - owner gets full access, authenticated users get read access
|
||||
//
|
||||
func (a apiV2) GetBucketACL(bucket string) (BucketACL, error) {
|
||||
func (a apiV2) GetBucketACL(bucket string) (ACL, error) {
|
||||
if err := invalidBucketError(bucket); err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -659,28 +734,28 @@ func (a apiV2) GetBucketACL(bucket string) (BucketACL, error) {
|
||||
switch {
|
||||
case len(grants) == 1:
|
||||
if grants[0].Grantee.URI == "" && grants[0].Permission == "FULL_CONTROL" {
|
||||
return BucketACL("private"), nil
|
||||
return ACL("private"), nil
|
||||
}
|
||||
case len(grants) == 2:
|
||||
for _, g := range grants {
|
||||
if g.Grantee.URI == "http://acs.amazonaws.com/groups/global/AuthenticatedUsers" && g.Permission == "READ" {
|
||||
return BucketACL("authenticated-read"), nil
|
||||
return ACL("authenticated-read"), nil
|
||||
}
|
||||
if g.Grantee.URI == "http://acs.amazonaws.com/groups/global/AllUsers" && g.Permission == "READ" {
|
||||
return BucketACL("public-read"), nil
|
||||
return ACL("public-read"), nil
|
||||
}
|
||||
}
|
||||
case len(grants) == 3:
|
||||
for _, g := range grants {
|
||||
if g.Grantee.URI == "http://acs.amazonaws.com/groups/global/AllUsers" && g.Permission == "WRITE" {
|
||||
return BucketACL("public-read-write"), nil
|
||||
return ACL("public-read-write"), nil
|
||||
}
|
||||
}
|
||||
}
|
||||
return "", ErrorResponse{
|
||||
Code: "NoSuchBucketPolicy",
|
||||
Message: "The specified bucket does not have a bucket policy.",
|
||||
Resource: "/" + bucket,
|
||||
Resource: separator + bucket,
|
||||
RequestID: "minio",
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -30,7 +30,7 @@ func TestACLTypes(t *testing.T) {
|
||||
"invalid": false,
|
||||
}
|
||||
for acl, ok := range want {
|
||||
if BucketACL(acl).isValidBucketACL() != ok {
|
||||
if ACL(acl).isValidACL() != ok {
|
||||
t.Fatal("Error")
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -64,7 +64,7 @@ func TestBucketOperations(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Errorf("Error")
|
||||
}
|
||||
if acl != minio.BucketACL("private") {
|
||||
if acl != minio.ACL("private") {
|
||||
t.Fatalf("Error")
|
||||
}
|
||||
|
||||
@@ -160,7 +160,7 @@ func TestObjectOperations(t *testing.T) {
|
||||
t.Fatalf("Error")
|
||||
}
|
||||
data := []byte("Hello, World")
|
||||
err = a.PutObject("bucket", "object", "", int64(len(data)), bytes.NewReader(data))
|
||||
err = a.PutObject("bucket", "object", "", minio.ACL("private"), int64(len(data)), bytes.NewReader(data))
|
||||
if err != nil {
|
||||
t.Fatalf("Error")
|
||||
}
|
||||
|
||||
@@ -5,4 +5,3 @@ package main
|
||||
|
||||
// Version autogenerated
|
||||
const Version = "2015-08-28T19:20:08.123385413Z"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user