mirror of
https://github.com/minio/minio.git
synced 2025-01-26 06:03:17 -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"
|
"time"
|
||||||
|
|
||||||
"github.com/Azure/azure-sdk-for-go/storage"
|
"github.com/Azure/azure-sdk-for-go/storage"
|
||||||
|
"github.com/minio/cli"
|
||||||
"github.com/minio/minio-go/pkg/policy"
|
"github.com/minio/minio-go/pkg/policy"
|
||||||
"github.com/minio/sha256-simd"
|
"github.com/minio/sha256-simd"
|
||||||
)
|
)
|
||||||
@ -156,14 +157,20 @@ func azureToObjectError(err error, params ...string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Inits azure blob storage client and returns AzureObjects.
|
// Inits azure blob storage client and returns AzureObjects.
|
||||||
func newAzureLayer(args []string) (GatewayLayer, error) {
|
func newAzureLayer(args cli.Args) (GatewayLayer, error) {
|
||||||
endPoint, secure, err := parseGatewayEndpoint(args[0])
|
|
||||||
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if endPoint == "" {
|
|
||||||
endPoint = storage.DefaultBaseURL
|
|
||||||
}
|
}
|
||||||
|
|
||||||
account := os.Getenv("MINIO_ACCESS_KEY")
|
account := os.Getenv("MINIO_ACCESS_KEY")
|
||||||
|
@ -17,32 +17,24 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
|
"encoding/base64"
|
||||||
|
"encoding/hex"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"hash"
|
"hash"
|
||||||
"io"
|
"io"
|
||||||
|
"path"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"encoding/hex"
|
|
||||||
|
|
||||||
"cloud.google.com/go/storage"
|
"cloud.google.com/go/storage"
|
||||||
|
|
||||||
"google.golang.org/api/googleapi"
|
"google.golang.org/api/googleapi"
|
||||||
"google.golang.org/api/iterator"
|
"google.golang.org/api/iterator"
|
||||||
|
|
||||||
"encoding/base64"
|
"github.com/minio/cli"
|
||||||
|
|
||||||
"bytes"
|
|
||||||
|
|
||||||
// this package contains the url code of go 1.8
|
|
||||||
// due to compatibility with older versions
|
|
||||||
// copied it to our rep
|
|
||||||
|
|
||||||
"path"
|
|
||||||
|
|
||||||
minio "github.com/minio/minio-go"
|
minio "github.com/minio/minio-go"
|
||||||
"github.com/minio/minio-go/pkg/policy"
|
"github.com/minio/minio-go/pkg/policy"
|
||||||
)
|
)
|
||||||
@ -171,7 +163,7 @@ type gcsGateway struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// newGCSGateway returns gcs gatewaylayer
|
// newGCSGateway returns gcs gatewaylayer
|
||||||
func newGCSGateway(args []string) (GatewayLayer, error) {
|
func newGCSGateway(args cli.Args) (GatewayLayer, error) {
|
||||||
if len(args) != 1 {
|
if len(args) != 1 {
|
||||||
return nil, fmt.Errorf("ProjectID expected")
|
return nil, fmt.Errorf("ProjectID expected")
|
||||||
}
|
}
|
||||||
@ -183,7 +175,7 @@ func newGCSGateway(args []string) (GatewayLayer, error) {
|
|||||||
endpoint := "storage.googleapis.com"
|
endpoint := "storage.googleapis.com"
|
||||||
secure := true
|
secure := true
|
||||||
|
|
||||||
projectID := args[0]
|
projectID := args.First()
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
|
@ -179,7 +179,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// GatewayFn returns the GatewayLayer for the backend
|
// GatewayFn returns the GatewayLayer for the backend
|
||||||
type GatewayFn func([]string) (GatewayLayer, error)
|
type GatewayFn func(cli.Args) (GatewayLayer, error)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
backends = map[gatewayBackend]GatewayFn{
|
backends = map[gatewayBackend]GatewayFn{
|
||||||
|
@ -17,13 +17,15 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/hex"
|
|
||||||
"errors"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
|
||||||
|
"encoding/hex"
|
||||||
|
|
||||||
|
"github.com/minio/cli"
|
||||||
minio "github.com/minio/minio-go"
|
minio "github.com/minio/minio-go"
|
||||||
"github.com/minio/minio-go/pkg/policy"
|
"github.com/minio/minio-go/pkg/policy"
|
||||||
)
|
)
|
||||||
@ -99,15 +101,21 @@ type s3Objects struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// newS3Gateway returns s3 gatewaylayer
|
// newS3Gateway returns s3 gatewaylayer
|
||||||
func newS3Gateway(args []string) (GatewayLayer, error) {
|
func newS3Gateway(args cli.Args) (GatewayLayer, error) {
|
||||||
endpoint, secure, err := parseGatewayEndpoint(args[0])
|
|
||||||
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if endpoint == "" {
|
|
||||||
endpoint = "s3.amazonaws.com"
|
|
||||||
secure = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
accessKey := os.Getenv("MINIO_ACCESS_KEY")
|
accessKey := os.Getenv("MINIO_ACCESS_KEY")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user