mirror of
https://github.com/pgsty/minio.git
synced 2026-07-22 21:50:22 +03:00
gateway: Support for custom endpoint. (#4086)
This commit is contained in:
committed by
Harshavardhana
parent
de204a0a52
commit
c5249c35d3
+32
-3
@@ -19,7 +19,9 @@ package cmd
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/minio/cli"
|
||||
@@ -83,11 +85,11 @@ func mustGetGatewayCredsFromEnv() (accessKey, secretKey string) {
|
||||
//
|
||||
// - Azure Blob Storage.
|
||||
// - Add your favorite backend here.
|
||||
func newGatewayLayer(backendType, accessKey, secretKey string) (GatewayLayer, error) {
|
||||
func newGatewayLayer(backendType, endPoint, accessKey, secretKey string, secure bool) (GatewayLayer, error) {
|
||||
if gatewayBackend(backendType) != azureBackend {
|
||||
return nil, fmt.Errorf("Unrecognized backend type %s", backendType)
|
||||
}
|
||||
return newAzureLayer(accessKey, secretKey)
|
||||
return newAzureLayer(endPoint, accessKey, secretKey, secure)
|
||||
}
|
||||
|
||||
// Initialize a new gateway config.
|
||||
@@ -117,6 +119,28 @@ func newGatewayConfig(accessKey, secretKey, region string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Return endpoint.
|
||||
func parseGatewayEndpoint(arg string) (endPoint string, secure bool, err error) {
|
||||
schemeSpecified := len(strings.Split(arg, "://")) > 1
|
||||
if !schemeSpecified {
|
||||
// Default connection will be "secure".
|
||||
arg = "https://" + arg
|
||||
}
|
||||
u, err := url.Parse(arg)
|
||||
if err != nil {
|
||||
return "", false, err
|
||||
}
|
||||
|
||||
switch u.Scheme {
|
||||
case "http":
|
||||
return u.Host, false, nil
|
||||
case "https":
|
||||
return u.Host, true, nil
|
||||
default:
|
||||
return "", false, fmt.Errorf("Unrecognized scheme %s", u.Scheme)
|
||||
}
|
||||
}
|
||||
|
||||
// Handler for 'minio gateway'.
|
||||
func gatewayMain(ctx *cli.Context) {
|
||||
if !ctx.Args().Present() || ctx.Args().First() == "help" {
|
||||
@@ -142,10 +166,15 @@ func gatewayMain(ctx *cli.Context) {
|
||||
// First argument is selected backend type.
|
||||
backendType := ctx.Args().First()
|
||||
|
||||
// Second argument is endpoint. If no endpoint is specified then the
|
||||
// gateway implementation should use a default setting.
|
||||
endPoint, secure, err := parseGatewayEndpoint(ctx.Args().Get(1))
|
||||
fatalIf(err, "Unable to parse endpoint")
|
||||
|
||||
// Create certs path for SSL configuration.
|
||||
fatalIf(createConfigDir(), "Unable to create configuration directory")
|
||||
|
||||
newObject, err := newGatewayLayer(backendType, accessKey, secretKey)
|
||||
newObject, err := newGatewayLayer(backendType, endPoint, accessKey, secretKey, secure)
|
||||
fatalIf(err, "Unable to initialize gateway layer")
|
||||
|
||||
initNSLock(false) // Enable local namespace lock.
|
||||
|
||||
Reference in New Issue
Block a user