Implement minio 'put-bucket'
This commit is contained in:
@@ -7,11 +7,12 @@ getdeps: checkdeps
|
||||
@go get github.com/tools/godep && echo "Installed godep"
|
||||
@go get golang.org/x/tools/cmd/cover && echo "Installed cover"
|
||||
|
||||
install: s3 uri
|
||||
install: pkgs uri
|
||||
@godep go install github.com/minio-io/mc && echo "Installed mc"
|
||||
|
||||
s3:
|
||||
pkgs:
|
||||
@godep go test -race -coverprofile=cover.out github.com/minio-io/mc/pkg/s3
|
||||
@godep go test -race -coverprofile=cover.out github.com/minio-io/mc/pkg/minio
|
||||
|
||||
uri:
|
||||
@godep go test -race -coverprofile=cover.out github.com/minio-io/mc/pkg/uri
|
||||
|
||||
@@ -62,6 +62,7 @@ var subS3APIOptions = []cli.Command{
|
||||
var subMinioApiOptions = []cli.Command{
|
||||
MinioGetObject,
|
||||
MinioPutObject,
|
||||
MinioPutBucket,
|
||||
MinioListObjects,
|
||||
MinioListBuckets,
|
||||
MinioConfigure,
|
||||
|
||||
+15
-1
@@ -39,7 +39,7 @@ var MinioGetObject = cli.Command{
|
||||
},
|
||||
}
|
||||
|
||||
var MinioPutObject = cli.Command{
|
||||
var MinioPutBucket = cli.Command{
|
||||
Name: "put-object",
|
||||
Usage: "",
|
||||
Description: "Adds an object to a bucket.",
|
||||
@@ -63,6 +63,20 @@ var MinioPutObject = cli.Command{
|
||||
},
|
||||
}
|
||||
|
||||
var MinioPutObject = cli.Command{
|
||||
Name: "put-bucket",
|
||||
Usage: "",
|
||||
Description: "Creates a new bucket.",
|
||||
Action: minioPutBucket,
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "bucket",
|
||||
Value: "",
|
||||
Usage: "bucket name",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
var MinioListObjects = cli.Command{
|
||||
Name: "list-objects",
|
||||
Usage: "",
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Mini Object Storage, (C) 2014,2015 Minio, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"github.com/codegangsta/cli"
|
||||
"github.com/minio-io/mc/pkg/minio"
|
||||
)
|
||||
|
||||
func minioPutBucket(c *cli.Context) {
|
||||
var bucket, hostname string
|
||||
var err error
|
||||
|
||||
hostname, err = getMinioEnvironment()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
bucket = c.String("bucket")
|
||||
if bucket == "" {
|
||||
log.Fatal(bucketNameErr)
|
||||
}
|
||||
|
||||
mc := minio.NewMinioClient(hostname)
|
||||
err = mc.PutBucket(bucket)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
@@ -190,24 +190,6 @@ type listBucketResults struct {
|
||||
Marker string
|
||||
}
|
||||
|
||||
// BucketLocation returns the Minio hostname to be used with the given bucket.
|
||||
func (c *Client) BucketLocation(bucket string, hostname string) (location string, err error) {
|
||||
url_ := fmt.Sprintf("http://%s/%s/?location", hostname, url.QueryEscape(bucket))
|
||||
req := newReq(url_)
|
||||
res, err := c.transport().RoundTrip(req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
var xres xmlLocationConstraint
|
||||
if err := xml.NewDecoder(res.Body).Decode(&xres); err != nil {
|
||||
return "", err
|
||||
}
|
||||
if xres.Location == "" {
|
||||
return "localhost", nil
|
||||
}
|
||||
return "minio-" + xres.Location + "." + hostname, nil
|
||||
}
|
||||
|
||||
// GetBucket (List Objects) returns 0 to maxKeys (inclusive) items from the
|
||||
// provided bucket. Keys before startAt will be skipped. (This is the MINIO
|
||||
// 'marker' value). If the length of the returned items is equal to
|
||||
@@ -392,9 +374,3 @@ type xmlError struct {
|
||||
Endpoint string
|
||||
StringToSignBytes string
|
||||
}
|
||||
|
||||
// xmlLocationConstraint is the LocationConstraint returned from BucketLocation.
|
||||
type xmlLocationConstraint struct {
|
||||
XMLName xml.Name `xml:"LocationConstraint"`
|
||||
Location string `xml:",chardata"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user