diff --git a/minio-api-options.go b/minio-api-options.go index f77ae321..8d9c0064 100644 --- a/minio-api-options.go +++ b/minio-api-options.go @@ -109,14 +109,6 @@ const ( MINIO_AUTH = ".minioauth" ) -func minioPutObject(c *cli.Context) { - //TODO -} - -func minioListBuckets(c *cli.Context) { - //TODO -} - func minioListObjects(c *cli.Context) { //TODO } diff --git a/minio-list-buckets.go b/minio-list-buckets.go new file mode 100644 index 00000000..9c3d1f05 --- /dev/null +++ b/minio-list-buckets.go @@ -0,0 +1,30 @@ +package main + +import ( + "log" + + "github.com/codegangsta/cli" + "github.com/minio-io/mc/pkg/minio" +) + +func minioDumpBuckets(v []*minio.Bucket) { + for _, b := range v { + log.Printf("Bucket :%#v", b) + } +} + +func minioListBuckets(c *cli.Context) { + hostname, err := getMinioEnvironment() + if err != nil { + log.Fatal(err) + } + + var buckets []*minio.Bucket + mc := minio.NewMinioClient(hostname) + buckets, err = mc.Buckets() + if err != nil { + log.Fatal(err) + } + + minioDumpBuckets(buckets) +} diff --git a/minio-put-object.go b/minio-put-object.go new file mode 100644 index 00000000..e5ea9bfa --- /dev/null +++ b/minio-put-object.go @@ -0,0 +1,103 @@ +/* + * 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 ( + "bytes" + "io" + "log" + "os" + + "github.com/codegangsta/cli" + "github.com/minio-io/mc/pkg/minio" +) + +func minioPutMetadata(reader io.Reader) (bodyBuf io.Reader, size int64, err error) { + var length int + var bodyBuffer bytes.Buffer + + for err == nil { + byteBuffer := make([]byte, 1024*1024) + length, err = reader.Read(byteBuffer) + // It is necessary for us to verify this and break + if length == 0 { + break + } + byteBuffer = byteBuffer[0:length] + _, err = bodyBuffer.Write(byteBuffer) + if err != nil { + break + } + } + + if err != io.EOF { + return nil, 0, err + } + return &bodyBuffer, int64(bodyBuffer.Len()), nil +} + +func minioParsePutObjectInput(c *cli.Context) (bucket, key, body string, err error) { + bucket = c.String("bucket") + key = c.String("key") + body = c.String("body") + + if bucket == "" { + return "", "", "", bucketNameErr + } + + if key == "" { + return "", "", "", objectNameErr + } + + if body == "" { + return "", "", "", objectBlobErr + } + + return bucket, key, body, nil +} + +func minioPutObject(c *cli.Context) { + var err error + var bucket, key, body, hostname string + hostname, err = getMinioEnvironment() + if err != nil { + log.Fatal(err) + } + + bucket, key, body, err = minioParsePutObjectInput(c) + if err != nil { + log.Fatal(err) + } + mc := minio.NewMinioClient(hostname) + var bodyFile *os.File + bodyFile, err = os.Open(body) + if err != nil { + log.Fatal(err) + } + + var bodyBuffer io.Reader + var size int64 + bodyBuffer, size, err = minioPutMetadata(bodyFile) + if err != nil { + log.Fatal(err) + } + + err = mc.Put(bucket, key, nil, size, bodyBuffer) + if err != nil { + log.Fatal(err) + } +}