|
|
@ -31,6 +31,7 @@ import ( |
|
|
|
"strings" |
|
|
|
"strings" |
|
|
|
"time" |
|
|
|
"time" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
etcd "github.com/coreos/etcd/client" |
|
|
|
humanize "github.com/dustin/go-humanize" |
|
|
|
humanize "github.com/dustin/go-humanize" |
|
|
|
"github.com/gorilla/mux" |
|
|
|
"github.com/gorilla/mux" |
|
|
|
"github.com/gorilla/rpc/v2/json2" |
|
|
|
"github.com/gorilla/rpc/v2/json2" |
|
|
@ -135,6 +136,26 @@ func (web *webAPIHandlers) MakeBucket(r *http.Request, args *MakeBucketArgs, rep |
|
|
|
return toJSONError(errInvalidBucketName) |
|
|
|
return toJSONError(errInvalidBucketName) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if globalDNSConfig != nil { |
|
|
|
|
|
|
|
if _, err := globalDNSConfig.Get(args.BucketName); err != nil { |
|
|
|
|
|
|
|
if etcd.IsKeyNotFound(err) { |
|
|
|
|
|
|
|
// Proceed to creating a bucket.
|
|
|
|
|
|
|
|
if err = objectAPI.MakeBucketWithLocation(context.Background(), args.BucketName, globalServerConfig.GetRegion()); err != nil { |
|
|
|
|
|
|
|
return toJSONError(err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if err = globalDNSConfig.Put(args.BucketName); err != nil { |
|
|
|
|
|
|
|
objectAPI.DeleteBucket(context.Background(), args.BucketName) |
|
|
|
|
|
|
|
return toJSONError(err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
reply.UIVersion = browser.UIVersion |
|
|
|
|
|
|
|
return nil |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return toJSONError(err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return toJSONError(errBucketAlreadyExists) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if err := objectAPI.MakeBucketWithLocation(context.Background(), args.BucketName, globalServerConfig.GetRegion()); err != nil { |
|
|
|
if err := objectAPI.MakeBucketWithLocation(context.Background(), args.BucketName, globalServerConfig.GetRegion()); err != nil { |
|
|
|
return toJSONError(err, args.BucketName) |
|
|
|
return toJSONError(err, args.BucketName) |
|
|
|
} |
|
|
|
} |
|
|
@ -176,6 +197,14 @@ func (web *webAPIHandlers) DeleteBucket(r *http.Request, args *RemoveBucketArgs, |
|
|
|
logger.LogIf(ctx, nerr.Err) |
|
|
|
logger.LogIf(ctx, nerr.Err) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if globalDNSConfig != nil { |
|
|
|
|
|
|
|
if err := globalDNSConfig.Delete(args.BucketName); err != nil { |
|
|
|
|
|
|
|
// Deleting DNS entry failed, attempt to create the bucket again.
|
|
|
|
|
|
|
|
objectAPI.MakeBucketWithLocation(ctx, args.BucketName, "") |
|
|
|
|
|
|
|
return toJSONError(err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
reply.UIVersion = browser.UIVersion |
|
|
|
reply.UIVersion = browser.UIVersion |
|
|
|
return nil |
|
|
|
return nil |
|
|
|
} |
|
|
|
} |
|
|
@ -208,16 +237,32 @@ func (web *webAPIHandlers) ListBuckets(r *http.Request, args *WebGenericArgs, re |
|
|
|
if authErr != nil { |
|
|
|
if authErr != nil { |
|
|
|
return toJSONError(authErr) |
|
|
|
return toJSONError(authErr) |
|
|
|
} |
|
|
|
} |
|
|
|
buckets, err := listBuckets(context.Background()) |
|
|
|
// If etcd, dns federation configured list buckets from etcd.
|
|
|
|
if err != nil { |
|
|
|
if globalDNSConfig != nil { |
|
|
|
return toJSONError(err) |
|
|
|
dnsBuckets, err := globalDNSConfig.List() |
|
|
|
} |
|
|
|
if err != nil { |
|
|
|
for _, bucket := range buckets { |
|
|
|
return toJSONError(err) |
|
|
|
reply.Buckets = append(reply.Buckets, WebBucketInfo{ |
|
|
|
} |
|
|
|
Name: bucket.Name, |
|
|
|
for _, dnsRecord := range dnsBuckets { |
|
|
|
CreationDate: bucket.Created, |
|
|
|
bucketName := strings.Trim(dnsRecord.Key, "/") |
|
|
|
}) |
|
|
|
reply.Buckets = append(reply.Buckets, WebBucketInfo{ |
|
|
|
|
|
|
|
Name: bucketName, |
|
|
|
|
|
|
|
CreationDate: dnsRecord.CreationDate, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
buckets, err := listBuckets(context.Background()) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return toJSONError(err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
for _, bucket := range buckets { |
|
|
|
|
|
|
|
reply.Buckets = append(reply.Buckets, WebBucketInfo{ |
|
|
|
|
|
|
|
Name: bucket.Name, |
|
|
|
|
|
|
|
CreationDate: bucket.Created, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
reply.UIVersion = browser.UIVersion |
|
|
|
reply.UIVersion = browser.UIVersion |
|
|
|
return nil |
|
|
|
return nil |
|
|
|
} |
|
|
|
} |
|
|
|