mirror of
https://github.com/minio/minio.git
synced 2025-11-10 05:59:43 -05:00
Implement Bucket ACL support
This commit is contained in:
45
pkg/fs/acl.go
Normal file
45
pkg/fs/acl.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package fs
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
// IsPrivateBucket - is private bucket
|
||||
func (fs API) IsPrivateBucket(bucket string) bool {
|
||||
fs.lock.Lock()
|
||||
defer fs.lock.Unlock()
|
||||
// get bucket path
|
||||
bucketDir := filepath.Join(fs.path, bucket)
|
||||
fi, err := os.Stat(bucketDir)
|
||||
if err != nil {
|
||||
return true
|
||||
}
|
||||
return permToACL(fi.Mode()).IsPrivate()
|
||||
}
|
||||
|
||||
// IsPublicBucket - is public bucket
|
||||
func (fs API) IsPublicBucket(bucket string) bool {
|
||||
fs.lock.Lock()
|
||||
defer fs.lock.Unlock()
|
||||
// get bucket path
|
||||
bucketDir := filepath.Join(fs.path, bucket)
|
||||
fi, err := os.Stat(bucketDir)
|
||||
if err != nil {
|
||||
return true
|
||||
}
|
||||
return permToACL(fi.Mode()).IsPublicReadWrite()
|
||||
}
|
||||
|
||||
// IsReadOnlyBucket - is read only bucket
|
||||
func (fs API) IsReadOnlyBucket(bucket string) bool {
|
||||
fs.lock.Lock()
|
||||
defer fs.lock.Unlock()
|
||||
// get bucket path
|
||||
bucketDir := filepath.Join(fs.path, bucket)
|
||||
fi, err := os.Stat(bucketDir)
|
||||
if err != nil {
|
||||
return true
|
||||
}
|
||||
return permToACL(fi.Mode()).IsPublicRead()
|
||||
}
|
||||
@@ -48,12 +48,10 @@ func (fs API) filterObjects(bucket string, content contentInfo, resources Bucket
|
||||
}
|
||||
if metadata.Mode.IsDir() {
|
||||
resources.CommonPrefixes = append(resources.CommonPrefixes, name+resources.Delimiter)
|
||||
sortUnique(resources.CommonPrefixes)
|
||||
return ObjectMetadata{}, resources, nil
|
||||
}
|
||||
case delimitedName != "":
|
||||
resources.CommonPrefixes = append(resources.CommonPrefixes, resources.Prefix+delimitedName)
|
||||
sortUnique(resources.CommonPrefixes)
|
||||
}
|
||||
}
|
||||
// Delimiter present and Prefix is absent
|
||||
@@ -72,12 +70,10 @@ func (fs API) filterObjects(bucket string, content contentInfo, resources Bucket
|
||||
}
|
||||
if metadata.Mode.IsDir() {
|
||||
resources.CommonPrefixes = append(resources.CommonPrefixes, name+resources.Delimiter)
|
||||
sortUnique(resources.CommonPrefixes)
|
||||
return ObjectMetadata{}, resources, nil
|
||||
}
|
||||
case delimitedName != "":
|
||||
resources.CommonPrefixes = append(resources.CommonPrefixes, delimitedName)
|
||||
sortUnique(resources.CommonPrefixes)
|
||||
}
|
||||
// Delimiter is absent and only Prefix is present
|
||||
case resources.Delimiter == "" && resources.Prefix != "":
|
||||
@@ -94,6 +90,6 @@ func (fs API) filterObjects(bucket string, content contentInfo, resources Bucket
|
||||
return ObjectMetadata{}, resources, err.Trace()
|
||||
}
|
||||
}
|
||||
|
||||
sortUnique(resources.CommonPrefixes)
|
||||
return metadata, resources, nil
|
||||
}
|
||||
|
||||
@@ -41,7 +41,11 @@ type CloudStorage interface {
|
||||
CreateObject(bucket, object, md5sum string, size int64, data io.Reader, signature *Signature) (ObjectMetadata, *probe.Error)
|
||||
DeleteObject(bucket, object string) *probe.Error
|
||||
|
||||
// Multipart API
|
||||
Multipart
|
||||
|
||||
// ACL API
|
||||
ACL
|
||||
}
|
||||
|
||||
// Multipart API
|
||||
@@ -53,3 +57,10 @@ type Multipart interface {
|
||||
ListMultipartUploads(bucket string, resources BucketMultipartResourcesMetadata) (BucketMultipartResourcesMetadata, *probe.Error)
|
||||
ListObjectParts(bucket, object string, objectResources ObjectResourcesMetadata) (ObjectResourcesMetadata, *probe.Error)
|
||||
}
|
||||
|
||||
// ACL API
|
||||
type ACL interface {
|
||||
IsPublicBucket(bucket string) bool
|
||||
IsPrivateBucket(bucket string) bool
|
||||
IsReadOnlyBucket(bucket string) bool
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user