Bring all errors to common location
This commit is contained in:
@@ -7,8 +7,11 @@ getdeps: checkdeps
|
||||
@go get github.com/tools/godep && echo "Installed godep"
|
||||
@go get golang.org/x/tools/cmd/cover && echo "Installed cover"
|
||||
|
||||
install: s3
|
||||
install: s3 uri
|
||||
@godep go install github.com/minio-io/mc && echo "Installed mc"
|
||||
|
||||
s3:
|
||||
@godep go test -race -coverprofile=cover.out github.com/minio-io/mc/pkg/s3
|
||||
|
||||
uri:
|
||||
@godep go test -race -coverprofile=cover.out github.com/minio-io/mc/pkg/uri
|
||||
|
||||
@@ -18,7 +18,6 @@ package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"os"
|
||||
"path"
|
||||
|
||||
@@ -52,17 +51,14 @@ func getAWSEnvironment() (auth *s3.Auth, err error) {
|
||||
accessKey = os.Getenv("AWS_ACCESS_KEY_ID")
|
||||
secretKey = os.Getenv("AWS_SECRET_ACCESS_KEY")
|
||||
if accessKey == "" && secretKey == "" {
|
||||
errstr := `You can configure your credentials by running "mc configure"`
|
||||
return nil, errors.New(errstr)
|
||||
return nil, missingAccessSecretErr
|
||||
}
|
||||
if accessKey == "" {
|
||||
errstr := `Partial credentials found in the env, missing : AWS_ACCESS_KEY_ID`
|
||||
return nil, errors.New(errstr)
|
||||
return nil, missingAccessErr
|
||||
}
|
||||
|
||||
if secretKey == "" {
|
||||
errstr := `Partial credentials found in the env, missing : AWS_SECRET_ACCESS_KEY`
|
||||
return nil, errors.New(errstr)
|
||||
return nil, missingSecretErr
|
||||
}
|
||||
auth = &s3.Auth{
|
||||
AccessKey: accessKey,
|
||||
|
||||
+2
-3
@@ -2,7 +2,6 @@ package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"log"
|
||||
"os"
|
||||
"path"
|
||||
@@ -15,10 +14,10 @@ func parseConfigureInput(c *cli.Context) (accessKey, secretKey string, err error
|
||||
accessKey = c.String("accesskey")
|
||||
secretKey = c.String("secretkey")
|
||||
if accessKey == "" {
|
||||
return "", "", errors.New("accesskey is mandatory")
|
||||
return "", "", configAccessErr
|
||||
}
|
||||
if secretKey == "" {
|
||||
return "", "", errors.New("secretkey is mandatory")
|
||||
return "", "", configSecretErr
|
||||
}
|
||||
return accessKey, secretKey, nil
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package main
|
||||
|
||||
import "errors"
|
||||
|
||||
// api
|
||||
var objectBlobErr = errors.New("object blob is mandatory")
|
||||
var objectNameErr = errors.New("object name is mandatory")
|
||||
var bucketNameErr = errors.New("bucket name is mandatory")
|
||||
|
||||
// fs
|
||||
var fsPathErr = errors.New("Arguments missing <S3Path> or <LocalPath>")
|
||||
var fsUriErr = errors.New("Invalid URI scheme")
|
||||
|
||||
// configure
|
||||
var configAccessErr = errors.New("accesskey is mandatory")
|
||||
var configSecretErr = errors.New("secretkey is mandatory")
|
||||
|
||||
// common
|
||||
var missingAccessSecretErr = errors.New("You can configure your credentials by running `mc configure`")
|
||||
var missingAccessErr = errors.New("Partial credentials found in the env, missing : AWS_ACCESS_KEY_ID")
|
||||
var missingSecretErr = errors.New("Partial credentials found in the env, missing : AWS_SECRET_ACCESS_KEY")
|
||||
@@ -1,7 +1,6 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"hash"
|
||||
"io"
|
||||
"log"
|
||||
@@ -13,15 +12,20 @@ import (
|
||||
"github.com/minio-io/mc/pkg/uri"
|
||||
)
|
||||
|
||||
// TODO
|
||||
// - <S3Path> <S3Path>
|
||||
// - <S3Path> <S3Bucket>
|
||||
// - <LocalDir> <S3Bucket>
|
||||
|
||||
func parseCpOptions(c *cli.Context) (fsoptions fsOptions, err error) {
|
||||
switch len(c.Args()) {
|
||||
case 1:
|
||||
return fsOptions{}, errors.New("Missing <S3Path> or <LocalPath>")
|
||||
return fsOptions{}, fsPathErr
|
||||
case 2:
|
||||
if strings.HasPrefix(c.Args().Get(0), "s3://") {
|
||||
uri := uri.ParseURI(c.Args().Get(0))
|
||||
if uri.Scheme == "" {
|
||||
return fsOptions{}, errors.New("Invalid URI scheme")
|
||||
return fsOptions{}, fsUriErr
|
||||
}
|
||||
fsoptions.bucket = uri.Server
|
||||
fsoptions.key = uri.Path
|
||||
@@ -31,7 +35,7 @@ func parseCpOptions(c *cli.Context) (fsoptions fsOptions, err error) {
|
||||
} else if strings.HasPrefix(c.Args().Get(1), "s3://") {
|
||||
uri := uri.ParseURI(c.Args().Get(1))
|
||||
if uri.Scheme == "" {
|
||||
return fsOptions{}, errors.New("Invalid URI scheme")
|
||||
return fsOptions{}, fsUriErr
|
||||
}
|
||||
fsoptions.bucket = uri.Server
|
||||
fsoptions.key = c.Args().Get(0)
|
||||
@@ -40,7 +44,7 @@ func parseCpOptions(c *cli.Context) (fsoptions fsOptions, err error) {
|
||||
fsoptions.isput = true
|
||||
}
|
||||
default:
|
||||
return fsOptions{}, errors.New("Arguments missing <S3Path> or <LocalPath>")
|
||||
return fsOptions{}, fsPathErr
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/codegangsta/cli"
|
||||
// "github.com/minio-io/mc/pkg/s3"
|
||||
)
|
||||
|
||||
func parseFsList(c *cli.Context) {
|
||||
}
|
||||
|
||||
func doFsList(c *cli.Context) {
|
||||
}
|
||||
@@ -56,9 +56,6 @@ type fsOptions struct {
|
||||
isput bool
|
||||
}
|
||||
|
||||
func doFsList(c *cli.Context) {
|
||||
}
|
||||
|
||||
func doFsMkdir(c *cli.Context) {
|
||||
}
|
||||
|
||||
|
||||
+2
-3
@@ -17,7 +17,6 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
@@ -30,10 +29,10 @@ func parseGetObjectInput(c *cli.Context) (bucket, key string, err error) {
|
||||
bucket = c.String("bucket")
|
||||
key = c.String("key")
|
||||
if bucket == "" {
|
||||
return "", "", errors.New("bucket name is mandatory")
|
||||
return "", "", bucketNameErr
|
||||
}
|
||||
if key == "" {
|
||||
return "", "", errors.New("object name is mandatory")
|
||||
return "", "", objectNameErr
|
||||
}
|
||||
|
||||
return bucket, key, nil
|
||||
|
||||
+1
-2
@@ -17,7 +17,6 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"log"
|
||||
|
||||
"github.com/codegangsta/cli"
|
||||
@@ -27,7 +26,7 @@ import (
|
||||
func parseListObjectsInput(c *cli.Context) (bucket string, err error) {
|
||||
bucket = c.String("bucket")
|
||||
if bucket == "" {
|
||||
return "", errors.New("bucket name is mandatory")
|
||||
return "", bucketNameErr
|
||||
}
|
||||
return bucket, nil
|
||||
}
|
||||
|
||||
+3
-4
@@ -19,7 +19,6 @@ package main
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/md5"
|
||||
"errors"
|
||||
"hash"
|
||||
"io"
|
||||
"log"
|
||||
@@ -61,15 +60,15 @@ func parsePutObjectInput(c *cli.Context) (bucket, key, body string, err error) {
|
||||
body = c.String("body")
|
||||
|
||||
if bucket == "" {
|
||||
return "", "", "", errors.New("bucket name is mandatory")
|
||||
return "", "", "", bucketNameErr
|
||||
}
|
||||
|
||||
if key == "" {
|
||||
return "", "", "", errors.New("object name is mandatory")
|
||||
return "", "", "", objectNameErr
|
||||
}
|
||||
|
||||
if body == "" {
|
||||
return "", "", "", errors.New("object blob is mandatory")
|
||||
return "", "", "", objectBlobErr
|
||||
}
|
||||
|
||||
return bucket, key, body, nil
|
||||
|
||||
Reference in New Issue
Block a user