diff --git a/README.md b/README.md index bc1d1098..04b1d85b 100644 --- a/README.md +++ b/README.md @@ -12,13 +12,24 @@ mc - unified command line interface for Minio Object Storage compatible with Ama ### Commands ``` -# mc --help -... -... -... +NAME: + mc - Unified command line interface for Minio Object Storage + +USAGE: + mc [global options] command [command options] [arguments...] + +VERSION: + 0.1.0 + +AUTHOR: + Minio Community + COMMANDS: - s3 - s3api + cp + ls + mb + sync + configure help, h Shows a list of commands or help for one command GLOBAL OPTIONS: @@ -26,49 +37,6 @@ GLOBAL OPTIONS: --version, -v print the version ``` -### Sub-Commands -``` -# mc s3 --help -NAME: - mc s3 - - -USAGE: - mc s3 command [command options] [arguments...] - -COMMANDS: - cp - ls - mb - sync - help, h Shows a list of commands or help for one command - -OPTIONS: - --help, -h show help - -``` - -``` -# mc s3api --help -NAME: - mc s3api - - -USAGE: - mc s3api command [command options] [arguments...] - -COMMANDS: - get-object - put-object - put-bucket - list-objects - list-buckets - configure - help, h Shows a list of commands or help for one command - -OPTIONS: - --help, -h show help - -``` - ## Contribute [Contribute to mc](./CONTRIBUTING.md) diff --git a/common.go b/common.go index 983169bf..a73d4c93 100644 --- a/common.go +++ b/common.go @@ -25,32 +25,11 @@ import ( "github.com/minio-io/mc/pkg/s3" ) -var Options = []cli.Command{ - { - Name: "s3", - Usage: "", - Subcommands: subS3Options, - }, - { - Name: "s3api", - Usage: "", - Subcommands: subS3APIOptions, - }, -} - -var subS3Options = []cli.Command{ +var options = []cli.Command{ Cp, Ls, Mb, Sync, -} - -var subS3APIOptions = []cli.Command{ - GetObject, - PutObject, - PutBucket, - ListObjects, - ListBuckets, Configure, } diff --git a/configure.go b/configure.go index 39966f80..1b22c4e9 100644 --- a/configure.go +++ b/configure.go @@ -22,7 +22,7 @@ func parseConfigureInput(c *cli.Context) (accessKey, secretKey string, err error return accessKey, secretKey, nil } -func doS3Configure(c *cli.Context) { +func doConfigure(c *cli.Context) { var err error var jAuth []byte var accessKey, secretKey string diff --git a/docs/index.md b/docs/index.md index 466f0175..dea416c2 100644 --- a/docs/index.md +++ b/docs/index.md @@ -12,59 +12,27 @@ mc - unified command line interface for Minio Object Storage compatible with Ama ### Commands ``` -# mc --help -... -... -... -COMMANDS: - s3 - s3api - help, h Shows a list of commands or help for one command - -GLOBAL OPTIONS: - --help, -h show help - --version, -v print the version -``` - -### Sub-Commands -``` -# mc s3 --help NAME: - mc s3 - + mc - Unified command line interface for Minio Object Storage USAGE: - mc s3 command [command options] [arguments...] + mc [global options] command [command options] [arguments...] + +VERSION: + 0.1.0 + +AUTHOR: + Minio Community COMMANDS: cp ls mb sync - help, h Shows a list of commands or help for one command - -OPTIONS: - --help, -h show help - -``` - -``` -# mc s3api --help -NAME: - mc s3api - - -USAGE: - mc s3api command [command options] [arguments...] - -COMMANDS: - get-object - put-object - put-bucket - list-objects - list-buckets configure help, h Shows a list of commands or help for one command -OPTIONS: - --help, -h show help - -``` +GLOBAL OPTIONS: + --help, -h show help + --version, -v print the version +``` \ No newline at end of file diff --git a/main.go b/main.go index d6cae676..4a115537 100644 --- a/main.go +++ b/main.go @@ -27,7 +27,7 @@ func main() { app.Name = "mc" app.Usage = "Unified command line interface for Minio Object Storage" app.Version = "0.1.0" - app.Commands = Options + app.Commands = options app.Author = "Minio Community" app.Run(os.Args) } diff --git a/s3-api-options.go b/s3-api-options.go deleted file mode 100644 index 054cd129..00000000 --- a/s3-api-options.go +++ /dev/null @@ -1,129 +0,0 @@ -/* - * 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 ( - "github.com/codegangsta/cli" -) - -var GetObject = cli.Command{ - Name: "get-object", - Usage: "", - Description: "Retrieves objects from Amazon S3.", - Action: doGetObject, - Flags: []cli.Flag{ - cli.StringFlag{ - Name: "bucket", - Value: "", - Usage: "bucket name", - }, - cli.StringFlag{ - Name: "key", - Value: "", - Usage: "path to Object", - }, - }, -} - -var PutObject = cli.Command{ - Name: "put-object", - Usage: "", - Description: "Adds an object to a bucket.", - Action: doPutObject, - Flags: []cli.Flag{ - cli.StringFlag{ - Name: "bucket", - Value: "", - Usage: "bucket name", - }, - cli.StringFlag{ - Name: "key", - Value: "", - Usage: "Object name", - }, - cli.StringFlag{ - Name: "body", - Value: "", - Usage: "Object blob", - }, - }, -} - -var PutBucket = cli.Command{ - Name: "put-bucket", - Usage: "", - Description: "Adds an object to a bucket.", - Action: doPutBucket, - Flags: []cli.Flag{ - cli.StringFlag{ - Name: "bucket", - Value: "", - Usage: "bucket name", - }, - }, -} - -var ListObjects = cli.Command{ - Name: "list-objects", - Usage: "", - Description: `Returns some or all (up to 1000) of the objects in a bucket. - You can use the request parameters as selection criteria to - return a subset of the objects in a bucket.`, - Action: doListObjects, - Flags: []cli.Flag{ - cli.StringFlag{ - Name: "bucket", - Value: "", - Usage: "Bucket name", - }, - }, -} - -var ListBuckets = cli.Command{ - Name: "list-buckets", - Usage: "", - Description: `Returns a list of all buckets owned by the authenticated - sender of the request.`, - Action: doListBuckets, -} - -var Configure = cli.Command{ - Name: "configure", - Usage: "", - Description: `Configure minio client configuration data. If your config - file does not exist (the default location is ~/.s3auth), it will be - automatically created for you. Note that the configure command only writes - values to the config file. It does not use any configuration values from - the environment variables.`, - Action: doS3Configure, - Flags: []cli.Flag{ - cli.StringFlag{ - Name: "accesskey", - Value: "", - Usage: "AWS access key id", - }, - cli.StringFlag{ - Name: "secretkey", - Value: "", - Usage: "AWS secret key id", - }, - }, -} - -const ( - AUTH = ".auth" -) diff --git a/s3-fs-cp.go b/s3-fs-cp.go index c0346484..937938c1 100644 --- a/s3-fs-cp.go +++ b/s3-fs-cp.go @@ -17,6 +17,8 @@ package main import ( + "bytes" + "crypto/md5" "hash" "io" "log" @@ -33,6 +35,32 @@ import ( // - // - +func getPutMetadata(reader io.Reader) (md5hash hash.Hash, bodyBuf io.Reader, size int64, err error) { + md5hash = md5.New() + var length int + var bodyBuffer bytes.Buffer + + for err == nil { + byteBuffer := make([]byte, 1024*1024) + length, err = reader.Read(byteBuffer) + // While hash.Write() wouldn't mind a Nil 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 + } + md5hash.Write(byteBuffer) + } + if err != io.EOF { + return nil, nil, 0, err + } + return md5hash, &bodyBuffer, int64(bodyBuffer.Len()), nil +} + func parseCpOptions(c *cli.Context) (fsoptions fsOptions, err error) { switch len(c.Args()) { case 1: diff --git a/s3-fs-options.go b/s3-fs-options.go index 6392e871..d90f26f9 100644 --- a/s3-fs-options.go +++ b/s3-fs-options.go @@ -48,6 +48,29 @@ var Sync = cli.Command{ Action: doFsSync, } +var Configure = cli.Command{ + Name: "configure", + Usage: "", + Description: `Configure minio client configuration data. If your config + file does not exist (the default location is ~/.s3auth), it will be + automatically created for you. Note that the configure command only writes + values to the config file. It does not use any configuration values from + the environment variables.`, + Action: doConfigure, + Flags: []cli.Flag{ + cli.StringFlag{ + Name: "accesskey", + Value: "", + Usage: "AWS access key id", + }, + cli.StringFlag{ + Name: "secretkey", + Value: "", + Usage: "AWS secret key id", + }, + }, +} + type fsOptions struct { bucket string body string @@ -56,5 +79,9 @@ type fsOptions struct { isput bool } +const ( + AUTH = ".auth" +) + func doFsSync(c *cli.Context) { } diff --git a/s3-get-object.go b/s3-get-object.go deleted file mode 100644 index 2c5b0094..00000000 --- a/s3-get-object.go +++ /dev/null @@ -1,68 +0,0 @@ -/* - * 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 ( - "io" - "log" - "os" - - "github.com/codegangsta/cli" - "github.com/minio-io/mc/pkg/s3" -) - -func parseGetObjectInput(c *cli.Context) (bucket, key string, err error) { - bucket = c.String("bucket") - key = c.String("key") - if bucket == "" { - return "", "", bucketNameErr - } - if key == "" { - return "", "", objectNameErr - } - - return bucket, key, nil -} - -func doGetObject(c *cli.Context) { - var bucket, key string - var err error - var objectReader io.ReadCloser - var objectSize int64 - - var auth *s3.Auth - auth, err = getAWSEnvironment() - if err != nil { - log.Fatal(err) - } - - bucket, key, err = parseGetObjectInput(c) - if err != nil { - log.Fatal(err) - } - - s3c := s3.NewS3Client(auth) - objectReader, objectSize, err = s3c.Get(bucket, key) - if err != nil { - log.Fatal(err) - } - - _, err = io.CopyN(os.Stdout, objectReader, objectSize) - if err != nil { - log.Fatal(err) - } -} diff --git a/s3-list-buckets.go b/s3-list-buckets.go deleted file mode 100644 index c40ef4d3..00000000 --- a/s3-list-buckets.go +++ /dev/null @@ -1,32 +0,0 @@ -package main - -import ( - "log" - - "github.com/codegangsta/cli" - "github.com/minio-io/mc/pkg/s3" -) - -func dumpBuckets(v []*s3.Bucket) { - for _, b := range v { - log.Printf("Bucket :%#v", b) - } -} - -func doListBuckets(c *cli.Context) { - var err error - var auth *s3.Auth - auth, err = getAWSEnvironment() - if err != nil { - log.Fatal(err) - } - - var buckets []*s3.Bucket - s3c := s3.NewS3Client(auth) - buckets, err = s3c.Buckets() - if err != nil { - log.Fatal(err) - } - - dumpBuckets(buckets) -} diff --git a/s3-list-objects.go b/s3-list-objects.go deleted file mode 100644 index 3fa6dfd7..00000000 --- a/s3-list-objects.go +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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/s3" -) - -func parseListObjectsInput(c *cli.Context) (bucket string, err error) { - bucket = c.String("bucket") - if bucket == "" { - return "", bucketNameErr - } - return bucket, nil -} - -func doListObjects(c *cli.Context) { - var err error - var auth *s3.Auth - var bucket string - - auth, err = getAWSEnvironment() - if err != nil { - log.Fatal(err) - } - - bucket, err = parseListObjectsInput(c) - if err != nil { - log.Fatal(err) - } - - var items []*s3.Item - s3c := s3.NewS3Client(auth) - // Gets 1000 maxkeys supported with GET Bucket API - items, err = s3c.GetBucket(bucket, "", s3.MAX_OBJECT_LIST) - if err != nil { - log.Fatal(err) - } - - for _, item := range items { - log.Println(item) - } -} diff --git a/s3-put-bucket.go b/s3-put-bucket.go deleted file mode 100644 index 1daa463d..00000000 --- a/s3-put-bucket.go +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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/s3" -) - -func parsePutBucketInput(c *cli.Context) (bucket string, err error) { - bucket = c.String("bucket") - - if bucket == "" { - return "", bucketNameErr - } - - return bucket, nil -} - -func doPutBucket(c *cli.Context) { - var err error - var bucket string - var auth *s3.Auth - auth, err = getAWSEnvironment() - if err != nil { - log.Fatal(err) - } - - bucket, err = parsePutBucketInput(c) - if err != nil { - log.Fatal(err) - } - s3c := s3.NewS3Client(auth) - err = s3c.PutBucket(bucket) - if err != nil { - log.Fatal(err) - } -} diff --git a/s3-put-object.go b/s3-put-object.go deleted file mode 100644 index 428d8a2d..00000000 --- a/s3-put-object.go +++ /dev/null @@ -1,109 +0,0 @@ -/* - * 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" - "crypto/md5" - "hash" - "io" - "log" - "os" - - "github.com/codegangsta/cli" - "github.com/minio-io/mc/pkg/s3" -) - -func getPutMetadata(reader io.Reader) (md5hash hash.Hash, bodyBuf io.Reader, size int64, err error) { - md5hash = md5.New() - var length int - var bodyBuffer bytes.Buffer - - for err == nil { - byteBuffer := make([]byte, 1024*1024) - length, err = reader.Read(byteBuffer) - // While hash.Write() wouldn't mind a Nil 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 - } - md5hash.Write(byteBuffer) - } - if err != io.EOF { - return nil, nil, 0, err - } - return md5hash, &bodyBuffer, int64(bodyBuffer.Len()), nil -} - -func parsePutObjectInput(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 doPutObject(c *cli.Context) { - var err error - var md5hash hash.Hash - var bucket, key, body string - var auth *s3.Auth - auth, err = getAWSEnvironment() - if err != nil { - log.Fatal(err) - } - - bucket, key, body, err = parsePutObjectInput(c) - if err != nil { - log.Fatal(err) - } - s3c := s3.NewS3Client(auth) - var bodyFile *os.File - bodyFile, err = os.Open(body) - if err != nil { - log.Fatal(err) - } - - var bodyBuffer io.Reader - var size int64 - md5hash, bodyBuffer, size, err = getPutMetadata(bodyFile) - if err != nil { - log.Fatal(err) - } - - err = s3c.Put(bucket, key, md5hash, size, bodyBuffer) - if err != nil { - log.Fatal(err) - } -}