mirror of
https://github.com/minio/minio.git
synced 2025-01-14 16:25:01 -05:00
Now donut supports bucket ACL's, bringing in this support for dl.minio.io
This commit is contained in:
parent
f5a51ae1bb
commit
c99d96dbc2
@ -45,13 +45,13 @@ func (server *minioAPI) isValidOp(w http.ResponseWriter, req *http.Request, acce
|
|||||||
|
|
||||||
if stripAccessKey(req) == "" && bucketMetadata.ACL.IsPrivate() {
|
if stripAccessKey(req) == "" && bucketMetadata.ACL.IsPrivate() {
|
||||||
return true
|
return true
|
||||||
// Uncomment this when we have webCli
|
// Uncomment this before release
|
||||||
// writeErrorResponse(w, req, AccessDenied, acceptsContentType, req.URL.Path)
|
// writeErrorResponse(w, req, AccessDenied, acceptsContentType, req.URL.Path)
|
||||||
// return false
|
// return false
|
||||||
}
|
}
|
||||||
if bucketMetadata.ACL.IsPublicRead() && req.Method == "PUT" {
|
if bucketMetadata.ACL.IsPublicRead() && req.Method == "PUT" {
|
||||||
return true
|
return true
|
||||||
// Uncomment this when we have webCli
|
// Uncomment this before release
|
||||||
// writeErrorResponse(w, req, AccessDenied, acceptsContentType, req.URL.Path)
|
// writeErrorResponse(w, req, AccessDenied, acceptsContentType, req.URL.Path)
|
||||||
// return false
|
// return false
|
||||||
}
|
}
|
||||||
|
@ -43,15 +43,18 @@ type bucket struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewBucket - instantiate a new bucket
|
// NewBucket - instantiate a new bucket
|
||||||
func NewBucket(bucketName, aclType, donutName string, nodes map[string]Node) (Bucket, error) {
|
func NewBucket(bucketName, aclType, donutName string, nodes map[string]Node) (Bucket, map[string]string, error) {
|
||||||
errParams := map[string]string{
|
errParams := map[string]string{
|
||||||
"bucketName": bucketName,
|
"bucketName": bucketName,
|
||||||
"donutName": donutName,
|
"donutName": donutName,
|
||||||
"aclType": aclType,
|
"aclType": aclType,
|
||||||
}
|
}
|
||||||
if strings.TrimSpace(bucketName) == "" || strings.TrimSpace(donutName) == "" {
|
if strings.TrimSpace(bucketName) == "" || strings.TrimSpace(donutName) == "" {
|
||||||
return nil, iodine.New(errors.New("invalid argument"), errParams)
|
return nil, nil, iodine.New(errors.New("invalid argument"), errParams)
|
||||||
}
|
}
|
||||||
|
bucketMetadata := make(map[string]string)
|
||||||
|
bucketMetadata["acl"] = aclType
|
||||||
|
bucketMetadata["created"] = time.Now().Format(time.RFC3339Nano)
|
||||||
b := bucket{}
|
b := bucket{}
|
||||||
b.name = bucketName
|
b.name = bucketName
|
||||||
b.acl = aclType
|
b.acl = aclType
|
||||||
@ -59,7 +62,7 @@ func NewBucket(bucketName, aclType, donutName string, nodes map[string]Node) (Bu
|
|||||||
b.donutName = donutName
|
b.donutName = donutName
|
||||||
b.objects = make(map[string]Object)
|
b.objects = make(map[string]Object)
|
||||||
b.nodes = nodes
|
b.nodes = nodes
|
||||||
return b, nil
|
return b, bucketMetadata, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListObjects - list all objects
|
// ListObjects - list all objects
|
||||||
|
@ -133,7 +133,7 @@ func (d disk) MakeFile(filename string) (*os.File, error) {
|
|||||||
if err := os.MkdirAll(path.Dir(filePath), 0700); err != nil {
|
if err := os.MkdirAll(path.Dir(filePath), 0700); err != nil {
|
||||||
return nil, iodine.New(err, nil)
|
return nil, iodine.New(err, nil)
|
||||||
}
|
}
|
||||||
dataFile, err := os.OpenFile(filePath, os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0600)
|
dataFile, err := os.OpenFile(filePath, os.O_WRONLY|os.O_CREATE, 0600)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, iodine.New(err, nil)
|
return nil, iodine.New(err, nil)
|
||||||
}
|
}
|
||||||
|
@ -19,10 +19,10 @@ package donut
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
|
"os"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/minio-io/minio/pkg/iodine"
|
"github.com/minio-io/minio/pkg/iodine"
|
||||||
)
|
)
|
||||||
@ -44,17 +44,25 @@ func (d donut) GetBucketMetadata(bucket string) (map[string]string, error) {
|
|||||||
if _, ok := d.buckets[bucket]; !ok {
|
if _, ok := d.buckets[bucket]; !ok {
|
||||||
return nil, iodine.New(errors.New("bucket does not exist"), nil)
|
return nil, iodine.New(errors.New("bucket does not exist"), nil)
|
||||||
}
|
}
|
||||||
// TODO get this, from whatever is written from SetBucketMetadata
|
metadata, err := d.getDonutBucketMetadata()
|
||||||
metadata := make(map[string]string)
|
if err != nil {
|
||||||
metadata["name"] = bucket
|
return nil, iodine.New(err, nil)
|
||||||
metadata["created"] = time.Now().Format(time.RFC3339Nano)
|
}
|
||||||
metadata["acl"] = "private"
|
return metadata[bucket], nil
|
||||||
return metadata, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetBucketMetadata - set bucket metadata
|
// SetBucketMetadata - set bucket metadata
|
||||||
func (d donut) SetBucketMetadata(bucket string, metadata map[string]string) error {
|
func (d donut) SetBucketMetadata(bucket string, bucketMetadata map[string]string) error {
|
||||||
return errors.New("Not implemented")
|
err := d.getDonutBuckets()
|
||||||
|
if err != nil {
|
||||||
|
return iodine.New(err, nil)
|
||||||
|
}
|
||||||
|
metadata, err := d.getDonutBucketMetadata()
|
||||||
|
if err != nil {
|
||||||
|
return iodine.New(err, nil)
|
||||||
|
}
|
||||||
|
metadata[bucket] = bucketMetadata
|
||||||
|
return d.setDonutBucketMetadata(metadata)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListBuckets - return list of buckets
|
// ListBuckets - return list of buckets
|
||||||
@ -63,7 +71,16 @@ func (d donut) ListBuckets() (results []string, err error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, iodine.New(err, nil)
|
return nil, iodine.New(err, nil)
|
||||||
}
|
}
|
||||||
for name := range d.buckets {
|
metadata, err := d.getDonutBucketMetadata()
|
||||||
|
if err != nil {
|
||||||
|
err = iodine.ToError(err)
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
// valid case
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
return nil, iodine.New(err, nil)
|
||||||
|
}
|
||||||
|
for name := range metadata {
|
||||||
results = append(results, name)
|
results = append(results, name)
|
||||||
}
|
}
|
||||||
sort.Strings(results)
|
sort.Strings(results)
|
||||||
@ -151,6 +168,15 @@ func (d donut) PutObject(bucket, object, expectedMD5Sum string, reader io.ReadCl
|
|||||||
if _, ok := d.buckets[bucket]; !ok {
|
if _, ok := d.buckets[bucket]; !ok {
|
||||||
return iodine.New(errors.New("bucket does not exist"), nil)
|
return iodine.New(errors.New("bucket does not exist"), nil)
|
||||||
}
|
}
|
||||||
|
objectList, err := d.buckets[bucket].ListObjects()
|
||||||
|
if err != nil {
|
||||||
|
return iodine.New(err, nil)
|
||||||
|
}
|
||||||
|
for objectName := range objectList {
|
||||||
|
if objectName == object {
|
||||||
|
return iodine.New(errors.New("object exists"), nil)
|
||||||
|
}
|
||||||
|
}
|
||||||
err = d.buckets[bucket].PutObject(object, reader, expectedMD5Sum, metadata)
|
err = d.buckets[bucket].PutObject(object, reader, expectedMD5Sum, metadata)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return iodine.New(err, errParams)
|
return iodine.New(err, errParams)
|
||||||
@ -177,7 +203,16 @@ func (d donut) GetObject(bucket, object string) (reader io.ReadCloser, size int6
|
|||||||
if _, ok := d.buckets[bucket]; !ok {
|
if _, ok := d.buckets[bucket]; !ok {
|
||||||
return nil, 0, iodine.New(errors.New("bucket does not exist"), errParams)
|
return nil, 0, iodine.New(errors.New("bucket does not exist"), errParams)
|
||||||
}
|
}
|
||||||
|
objectList, err := d.buckets[bucket].ListObjects()
|
||||||
|
if err != nil {
|
||||||
|
return nil, 0, iodine.New(err, nil)
|
||||||
|
}
|
||||||
|
for objectName := range objectList {
|
||||||
|
if objectName == object {
|
||||||
return d.buckets[bucket].GetObject(object)
|
return d.buckets[bucket].GetObject(object)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil, 0, iodine.New(errors.New("object not found"), nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetObjectMetadata - get object metadata
|
// GetObjectMetadata - get object metadata
|
||||||
|
@ -17,15 +17,94 @@
|
|||||||
package donut
|
package donut
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/minio-io/minio/pkg/iodine"
|
"github.com/minio-io/minio/pkg/iodine"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TODO we have to store the acl's
|
/// This file contains all the internal functions used by Object interface
|
||||||
|
|
||||||
|
// getDiskWriters -
|
||||||
|
func (d donut) getBucketMetadataWriters() ([]io.WriteCloser, error) {
|
||||||
|
var writers []io.WriteCloser
|
||||||
|
for _, node := range d.nodes {
|
||||||
|
disks, err := node.ListDisks()
|
||||||
|
if err != nil {
|
||||||
|
return nil, iodine.New(err, nil)
|
||||||
|
}
|
||||||
|
writers = make([]io.WriteCloser, len(disks))
|
||||||
|
for _, disk := range disks {
|
||||||
|
bucketMetaDataWriter, err := disk.MakeFile(path.Join(d.name, bucketMetadataConfig))
|
||||||
|
if err != nil {
|
||||||
|
return nil, iodine.New(err, nil)
|
||||||
|
}
|
||||||
|
writers[disk.GetOrder()] = bucketMetaDataWriter
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return writers, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d donut) getBucketMetadataReaders() ([]io.ReadCloser, error) {
|
||||||
|
var readers []io.ReadCloser
|
||||||
|
for _, node := range d.nodes {
|
||||||
|
disks, err := node.ListDisks()
|
||||||
|
if err != nil {
|
||||||
|
return nil, iodine.New(err, nil)
|
||||||
|
}
|
||||||
|
readers = make([]io.ReadCloser, len(disks))
|
||||||
|
for _, disk := range disks {
|
||||||
|
bucketMetaDataReader, err := disk.OpenFile(path.Join(d.name, bucketMetadataConfig))
|
||||||
|
if err != nil {
|
||||||
|
return nil, iodine.New(err, nil)
|
||||||
|
}
|
||||||
|
readers[disk.GetOrder()] = bucketMetaDataReader
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return readers, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
func (d donut) setDonutBucketMetadata(metadata map[string]map[string]string) error {
|
||||||
|
writers, err := d.getBucketMetadataWriters()
|
||||||
|
if err != nil {
|
||||||
|
return iodine.New(err, nil)
|
||||||
|
}
|
||||||
|
for _, writer := range writers {
|
||||||
|
defer writer.Close()
|
||||||
|
}
|
||||||
|
for _, writer := range writers {
|
||||||
|
jenc := json.NewEncoder(writer)
|
||||||
|
if err := jenc.Encode(metadata); err != nil {
|
||||||
|
return iodine.New(err, nil)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d donut) getDonutBucketMetadata() (map[string]map[string]string, error) {
|
||||||
|
metadata := make(map[string]map[string]string)
|
||||||
|
readers, err := d.getBucketMetadataReaders()
|
||||||
|
if err != nil {
|
||||||
|
return nil, iodine.New(err, nil)
|
||||||
|
}
|
||||||
|
for _, reader := range readers {
|
||||||
|
defer reader.Close()
|
||||||
|
}
|
||||||
|
for _, reader := range readers {
|
||||||
|
jenc := json.NewDecoder(reader)
|
||||||
|
if err := jenc.Decode(&metadata); err != nil {
|
||||||
|
return nil, iodine.New(err, nil)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return metadata, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (d donut) makeDonutBucket(bucketName, acl string) error {
|
func (d donut) makeDonutBucket(bucketName, acl string) error {
|
||||||
err := d.getDonutBuckets()
|
err := d.getDonutBuckets()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -34,7 +113,7 @@ func (d donut) makeDonutBucket(bucketName, acl string) error {
|
|||||||
if _, ok := d.buckets[bucketName]; ok {
|
if _, ok := d.buckets[bucketName]; ok {
|
||||||
return iodine.New(errors.New("bucket exists"), nil)
|
return iodine.New(errors.New("bucket exists"), nil)
|
||||||
}
|
}
|
||||||
bucket, err := NewBucket(bucketName, acl, d.name, d.nodes)
|
bucket, bucketMetadata, err := NewBucket(bucketName, acl, d.name, d.nodes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return iodine.New(err, nil)
|
return iodine.New(err, nil)
|
||||||
}
|
}
|
||||||
@ -54,6 +133,25 @@ func (d donut) makeDonutBucket(bucketName, acl string) error {
|
|||||||
}
|
}
|
||||||
nodeNumber = nodeNumber + 1
|
nodeNumber = nodeNumber + 1
|
||||||
}
|
}
|
||||||
|
metadata, err := d.getDonutBucketMetadata()
|
||||||
|
if err != nil {
|
||||||
|
err = iodine.ToError(err)
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
metadata := make(map[string]map[string]string)
|
||||||
|
metadata[bucketName] = bucketMetadata
|
||||||
|
err = d.setDonutBucketMetadata(metadata)
|
||||||
|
if err != nil {
|
||||||
|
return iodine.New(err, nil)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return iodine.New(err, nil)
|
||||||
|
}
|
||||||
|
metadata[bucketName] = bucketMetadata
|
||||||
|
err = d.setDonutBucketMetadata(metadata)
|
||||||
|
if err != nil {
|
||||||
|
return iodine.New(err, nil)
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,7 +173,7 @@ func (d donut) getDonutBuckets() error {
|
|||||||
}
|
}
|
||||||
bucketName := splitDir[0]
|
bucketName := splitDir[0]
|
||||||
// we dont need this NewBucket once we cache from makeDonutBucket()
|
// we dont need this NewBucket once we cache from makeDonutBucket()
|
||||||
bucket, err := NewBucket(bucketName, "private", d.name, d.nodes)
|
bucket, _, err := NewBucket(bucketName, "private", d.name, d.nodes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return iodine.New(err, nil)
|
return iodine.New(err, nil)
|
||||||
}
|
}
|
||||||
|
@ -235,7 +235,7 @@ func testBucketMetadata(c *check.C, create func() Driver) {
|
|||||||
|
|
||||||
metadata, err := drivers.GetBucketMetadata("string")
|
metadata, err := drivers.GetBucketMetadata("string")
|
||||||
c.Assert(err, check.IsNil)
|
c.Assert(err, check.IsNil)
|
||||||
c.Assert(metadata.Name, check.Equals, "string")
|
c.Assert(metadata.ACL, check.Equals, BucketACL("private"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func testBucketRecreateFails(c *check.C, create func() Driver) {
|
func testBucketRecreateFails(c *check.C, create func() Driver) {
|
||||||
|
@ -150,6 +150,9 @@ func (d donutDriver) CreateBucket(bucketName, acl string) error {
|
|||||||
return iodine.New(drivers.InvalidACL{ACL: acl}, nil)
|
return iodine.New(drivers.InvalidACL{ACL: acl}, nil)
|
||||||
}
|
}
|
||||||
if drivers.IsValidBucket(bucketName) && !strings.Contains(bucketName, ".") {
|
if drivers.IsValidBucket(bucketName) && !strings.Contains(bucketName, ".") {
|
||||||
|
if strings.TrimSpace(acl) == "" {
|
||||||
|
acl = "private"
|
||||||
|
}
|
||||||
return d.donut.MakeBucket(bucketName, acl)
|
return d.donut.MakeBucket(bucketName, acl)
|
||||||
}
|
}
|
||||||
return iodine.New(drivers.BucketNameInvalid{Bucket: bucketName}, nil)
|
return iodine.New(drivers.BucketNameInvalid{Bucket: bucketName}, nil)
|
||||||
@ -173,7 +176,7 @@ func (d donutDriver) GetBucketMetadata(bucketName string) (drivers.BucketMetadat
|
|||||||
return drivers.BucketMetadata{}, iodine.New(drivers.BackendCorrupted{}, nil)
|
return drivers.BucketMetadata{}, iodine.New(drivers.BackendCorrupted{}, nil)
|
||||||
}
|
}
|
||||||
bucketMetadata := drivers.BucketMetadata{
|
bucketMetadata := drivers.BucketMetadata{
|
||||||
Name: metadata["name"],
|
Name: bucketName,
|
||||||
Created: created,
|
Created: created,
|
||||||
ACL: drivers.BucketACL(acl),
|
ACL: drivers.BucketACL(acl),
|
||||||
}
|
}
|
||||||
|
@ -285,6 +285,10 @@ func (memory *memoryDriver) CreateBucket(bucketName, acl string) error {
|
|||||||
}
|
}
|
||||||
memory.lock.RUnlock()
|
memory.lock.RUnlock()
|
||||||
|
|
||||||
|
if strings.TrimSpace(acl) == "" {
|
||||||
|
// default is private
|
||||||
|
acl = "private"
|
||||||
|
}
|
||||||
var newBucket = storedBucket{}
|
var newBucket = storedBucket{}
|
||||||
newBucket.metadata = drivers.BucketMetadata{}
|
newBucket.metadata = drivers.BucketMetadata{}
|
||||||
newBucket.metadata.Name = bucketName
|
newBucket.metadata.Name = bucketName
|
||||||
|
Loading…
Reference in New Issue
Block a user