Make every backend responsible for parsing its own arguments, fixes #4293

master
Remco Verhoef 7 years ago committed by Harshavardhana
parent 2d814e340f
commit bf55591c64
  1. 18
      cmd/gateway-azure.go
  2. 21
      cmd/gateway-gcs-layer.go
  3. 15
      cmd/gateway-s3.go

@ -20,11 +20,13 @@ import (
"crypto/md5" "crypto/md5"
"encoding/base64" "encoding/base64"
"encoding/hex" "encoding/hex"
"errors"
"fmt" "fmt"
"hash" "hash"
"io" "io"
"net/http" "net/http"
"net/url" "net/url"
"os"
"strconv" "strconv"
"strings" "strings"
"sync" "sync"
@ -153,11 +155,23 @@ func azureToObjectError(err error, params ...string) error {
return e return e
} }
// Inits azure blob storage client and returns azureObjects. // Inits azure blob storage client and returns AzureObjects.
func newAzureLayer(endPoint string, account, key string, secure bool) (GatewayLayer, error) { func newAzureLayer(args []string) (GatewayLayer, error) {
endPoint, secure, err := parseGatewayEndpoint(args[0])
if err != nil {
return nil, err
}
if endPoint == "" { if endPoint == "" {
endPoint = storage.DefaultBaseURL 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) c, err := storage.NewClient(account, key, endPoint, globalAzureAPIVersion, secure)
if err != nil { if err != nil {
return &azureObjects{}, err return &azureObjects{}, err

@ -161,7 +161,20 @@ type gcsGateway struct {
} }
// newGCSGateway returns gcs gatewaylayer // 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() ctx := context.Background()
// Creates a client. // Creates a client.
@ -170,10 +183,6 @@ func newGCSGateway(endpoint string, projectID, secretKey string, secure bool) (G
return nil, err return nil, err
} }
if endpoint == "" {
endpoint = "storage.googleapis.com"
}
anonClient, err := minio.NewCore(endpoint, "", "", secure) anonClient, err := minio.NewCore(endpoint, "", "", secure)
if err != nil { if err != nil {
return nil, err return nil, err
@ -181,7 +190,7 @@ func newGCSGateway(endpoint string, projectID, secretKey string, secure bool) (G
return &gcsGateway{ return &gcsGateway{
client: client, client: client,
projectID: "minio-166400", projectID: projectID,
ctx: ctx, ctx: ctx,
anonClient: anonClient, anonClient: anonClient,
}, nil }, nil

@ -18,8 +18,10 @@ package cmd
import ( import (
"encoding/hex" "encoding/hex"
"errors"
"io" "io"
"net/http" "net/http"
"os"
"path" "path"
minio "github.com/minio/minio-go" minio "github.com/minio/minio-go"
@ -97,12 +99,23 @@ type s3Objects struct {
} }
// newS3Gateway returns s3 gatewaylayer // 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 == "" { if endpoint == "" {
endpoint = "s3.amazonaws.com" endpoint = "s3.amazonaws.com"
secure = true 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. // Initialize minio client object.
client, err := minio.NewCore(endpoint, accessKey, secretKey, secure) client, err := minio.NewCore(endpoint, accessKey, secretKey, secure)
if err != nil { if err != nil {

Loading…
Cancel
Save