mirror of
https://github.com/minio/minio.git
synced 2024-12-24 22:25:54 -05:00
gateway: Use default params when no args provided (#4315)
For S3 & Azure, use default parameters when no arguments (endpoint) are provided. This also avoids a crash.
This commit is contained in:
parent
b829ec4a6b
commit
5d602034ea
@ -33,6 +33,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/Azure/azure-sdk-for-go/storage"
|
||||
"github.com/minio/cli"
|
||||
"github.com/minio/minio-go/pkg/policy"
|
||||
"github.com/minio/sha256-simd"
|
||||
)
|
||||
@ -156,14 +157,20 @@ func azureToObjectError(err error, params ...string) 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
|
||||
}
|
||||
func newAzureLayer(args cli.Args) (GatewayLayer, error) {
|
||||
|
||||
if endPoint == "" {
|
||||
endPoint = storage.DefaultBaseURL
|
||||
var err error
|
||||
|
||||
// Default endpoint parameters
|
||||
endPoint := storage.DefaultBaseURL
|
||||
secure := true
|
||||
|
||||
// If user provided some parameters
|
||||
if len(args) > 0 {
|
||||
endPoint, secure, err = parseGatewayEndpoint(args.First())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
account := os.Getenv("MINIO_ACCESS_KEY")
|
||||
|
@ -17,32 +17,24 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto/sha256"
|
||||
"encoding/base64"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"hash"
|
||||
"io"
|
||||
"path"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"encoding/hex"
|
||||
|
||||
"cloud.google.com/go/storage"
|
||||
|
||||
"google.golang.org/api/googleapi"
|
||||
"google.golang.org/api/iterator"
|
||||
|
||||
"encoding/base64"
|
||||
|
||||
"bytes"
|
||||
|
||||
// this package contains the url code of go 1.8
|
||||
// due to compatibility with older versions
|
||||
// copied it to our rep
|
||||
|
||||
"path"
|
||||
|
||||
"github.com/minio/cli"
|
||||
minio "github.com/minio/minio-go"
|
||||
"github.com/minio/minio-go/pkg/policy"
|
||||
)
|
||||
@ -171,7 +163,7 @@ type gcsGateway struct {
|
||||
}
|
||||
|
||||
// newGCSGateway returns gcs gatewaylayer
|
||||
func newGCSGateway(args []string) (GatewayLayer, error) {
|
||||
func newGCSGateway(args cli.Args) (GatewayLayer, error) {
|
||||
if len(args) != 1 {
|
||||
return nil, fmt.Errorf("ProjectID expected")
|
||||
}
|
||||
@ -183,7 +175,7 @@ func newGCSGateway(args []string) (GatewayLayer, error) {
|
||||
endpoint := "storage.googleapis.com"
|
||||
secure := true
|
||||
|
||||
projectID := args[0]
|
||||
projectID := args.First()
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
|
@ -179,7 +179,7 @@ const (
|
||||
)
|
||||
|
||||
// GatewayFn returns the GatewayLayer for the backend
|
||||
type GatewayFn func([]string) (GatewayLayer, error)
|
||||
type GatewayFn func(cli.Args) (GatewayLayer, error)
|
||||
|
||||
var (
|
||||
backends = map[gatewayBackend]GatewayFn{
|
||||
|
@ -17,13 +17,15 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
|
||||
"encoding/hex"
|
||||
|
||||
"github.com/minio/cli"
|
||||
minio "github.com/minio/minio-go"
|
||||
"github.com/minio/minio-go/pkg/policy"
|
||||
)
|
||||
@ -99,15 +101,21 @@ type s3Objects struct {
|
||||
}
|
||||
|
||||
// newS3Gateway returns s3 gatewaylayer
|
||||
func newS3Gateway(args []string) (GatewayLayer, error) {
|
||||
endpoint, secure, err := parseGatewayEndpoint(args[0])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
func newS3Gateway(args cli.Args) (GatewayLayer, error) {
|
||||
|
||||
if endpoint == "" {
|
||||
endpoint = "s3.amazonaws.com"
|
||||
secure = true
|
||||
var err error
|
||||
|
||||
// Default endpoint parameters
|
||||
endpoint := "s3.amazonaws.com"
|
||||
secure := true
|
||||
|
||||
// Check if user provided some parameters
|
||||
if len(args) > 0 {
|
||||
// Override default params if the endpoint is provided
|
||||
endpoint, secure, err = parseGatewayEndpoint(args.First())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
accessKey := os.Getenv("MINIO_ACCESS_KEY")
|
||||
|
Loading…
Reference in New Issue
Block a user