From bf55591c646999ba3d3e310b7a2b31725794be6a Mon Sep 17 00:00:00 2001 From: Remco Verhoef Date: Mon, 8 May 2017 15:42:48 -0700 Subject: [PATCH] Make every backend responsible for parsing its own arguments, fixes #4293 --- cmd/gateway-azure.go | 18 ++++++++++++++++-- cmd/gateway-gcs-layer.go | 21 +++++++++++++++------ cmd/gateway-s3.go | 15 ++++++++++++++- 3 files changed, 45 insertions(+), 9 deletions(-) diff --git a/cmd/gateway-azure.go b/cmd/gateway-azure.go index 2a4640af7..bb7a19349 100644 --- a/cmd/gateway-azure.go +++ b/cmd/gateway-azure.go @@ -20,11 +20,13 @@ import ( "crypto/md5" "encoding/base64" "encoding/hex" + "errors" "fmt" "hash" "io" "net/http" "net/url" + "os" "strconv" "strings" "sync" @@ -153,11 +155,23 @@ func azureToObjectError(err error, params ...string) error { return e } -// Inits azure blob storage client and returns azureObjects. -func newAzureLayer(endPoint string, account, key string, secure bool) (GatewayLayer, error) { +// Inits azure blob storage client and returns AzureObjects. +func newAzureLayer(args []string) (GatewayLayer, error) { + endPoint, secure, err := parseGatewayEndpoint(args[0]) + if err != nil { + return nil, err + } + if endPoint == "" { endPoint = storage.DefaultBaseURL } + + account := os.Getenv("MINIO_ACCESS_KEY") + key := os.Getenv("MINIO_SECRET_KEY") + if account == "" || key == "" { + return nil, errors.New("No Azure account and key set") + } + c, err := storage.NewClient(account, key, endPoint, globalAzureAPIVersion, secure) if err != nil { return &azureObjects{}, err diff --git a/cmd/gateway-gcs-layer.go b/cmd/gateway-gcs-layer.go index 45e5dc794..1591bc928 100644 --- a/cmd/gateway-gcs-layer.go +++ b/cmd/gateway-gcs-layer.go @@ -161,7 +161,20 @@ type gcsGateway struct { } // newGCSGateway returns gcs gatewaylayer -func newGCSGateway(endpoint string, projectID, secretKey string, secure bool) (GatewayLayer, error) { +func newGCSGateway(args []string) (GatewayLayer, error) { + if len(args) != 1 { + return nil, fmt.Errorf("ProjectID expected") + } + + profile := "default" + // TODO: don't know where to set profile yet + _ = profile + + endpoint := "storage.googleapis.com" + secure := true + + projectID := args[0] + ctx := context.Background() // Creates a client. @@ -170,10 +183,6 @@ func newGCSGateway(endpoint string, projectID, secretKey string, secure bool) (G return nil, err } - if endpoint == "" { - endpoint = "storage.googleapis.com" - } - anonClient, err := minio.NewCore(endpoint, "", "", secure) if err != nil { return nil, err @@ -181,7 +190,7 @@ func newGCSGateway(endpoint string, projectID, secretKey string, secure bool) (G return &gcsGateway{ client: client, - projectID: "minio-166400", + projectID: projectID, ctx: ctx, anonClient: anonClient, }, nil diff --git a/cmd/gateway-s3.go b/cmd/gateway-s3.go index 709153e1f..dde2ddbc2 100644 --- a/cmd/gateway-s3.go +++ b/cmd/gateway-s3.go @@ -18,8 +18,10 @@ package cmd import ( "encoding/hex" + "errors" "io" "net/http" + "os" "path" minio "github.com/minio/minio-go" @@ -97,12 +99,23 @@ type s3Objects struct { } // newS3Gateway returns s3 gatewaylayer -func newS3Gateway(endpoint string, accessKey, secretKey string, secure bool) (GatewayLayer, error) { +func newS3Gateway(args []string) (GatewayLayer, error) { + endpoint, secure, err := parseGatewayEndpoint(args[0]) + if err != nil { + return nil, err + } + if endpoint == "" { endpoint = "s3.amazonaws.com" secure = true } + accessKey := os.Getenv("MINIO_ACCESS_KEY") + secretKey := os.Getenv("MINIO_SECRET_KEY") + if accessKey == "" || secretKey == "" { + return nil, errors.New("No S3 access and secret key") + } + // Initialize minio client object. client, err := minio.NewCore(endpoint, accessKey, secretKey, secure) if err != nil {