2017-03-16 15:21:58 -04:00
|
|
|
|
/*
|
|
|
|
|
* Minio Cloud Storage, (C) 2017 Minio, Inc.
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
|
*
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package cmd
|
|
|
|
|
|
|
|
|
|
import (
|
2017-03-23 19:36:00 -04:00
|
|
|
|
"errors"
|
2017-03-16 15:21:58 -04:00
|
|
|
|
"fmt"
|
2017-04-11 20:44:26 -04:00
|
|
|
|
"net/url"
|
2017-03-16 15:21:58 -04:00
|
|
|
|
"os"
|
2017-06-08 14:20:56 -04:00
|
|
|
|
"runtime"
|
2017-04-11 20:44:26 -04:00
|
|
|
|
"strings"
|
2017-06-05 18:18:03 -04:00
|
|
|
|
|
|
|
|
|
"github.com/gorilla/mux"
|
|
|
|
|
"github.com/minio/cli"
|
2017-03-16 15:21:58 -04:00
|
|
|
|
)
|
|
|
|
|
|
2017-06-09 02:28:45 -04:00
|
|
|
|
const azureGatewayTemplate = `NAME:
|
2017-03-16 15:21:58 -04:00
|
|
|
|
{{.HelpName}} - {{.Usage}}
|
|
|
|
|
|
|
|
|
|
USAGE:
|
2017-06-09 02:28:45 -04:00
|
|
|
|
{{.HelpName}} {{if .VisibleFlags}}[FLAGS]{{end}} [ENDPOINT]
|
2017-03-16 15:21:58 -04:00
|
|
|
|
{{if .VisibleFlags}}
|
|
|
|
|
FLAGS:
|
|
|
|
|
{{range .VisibleFlags}}{{.}}
|
|
|
|
|
{{end}}{{end}}
|
2017-06-09 02:28:45 -04:00
|
|
|
|
ENDPOINT:
|
|
|
|
|
Azure server endpoint. Default ENDPOINT is https://core.windows.net
|
2017-04-28 19:42:16 -04:00
|
|
|
|
|
2017-03-16 15:21:58 -04:00
|
|
|
|
ENVIRONMENT VARIABLES:
|
|
|
|
|
ACCESS:
|
2017-06-09 02:28:45 -04:00
|
|
|
|
MINIO_ACCESS_KEY: Username or access key of Azure storage.
|
|
|
|
|
MINIO_SECRET_KEY: Password or secret key of Azure storage.
|
2017-03-16 15:21:58 -04:00
|
|
|
|
|
2017-06-01 12:43:20 -04:00
|
|
|
|
BROWSER:
|
|
|
|
|
MINIO_BROWSER: To disable web browser access, set this value to "off".
|
|
|
|
|
|
2017-03-16 15:21:58 -04:00
|
|
|
|
EXAMPLES:
|
|
|
|
|
1. Start minio gateway server for Azure Blob Storage backend.
|
2017-04-28 19:42:16 -04:00
|
|
|
|
$ export MINIO_ACCESS_KEY=azureaccountname
|
|
|
|
|
$ export MINIO_SECRET_KEY=azureaccountkey
|
2017-06-09 02:28:45 -04:00
|
|
|
|
$ {{.HelpName}}
|
2017-05-08 15:44:08 -04:00
|
|
|
|
|
2017-06-09 02:28:45 -04:00
|
|
|
|
2. Start minio gateway server for Azure Blob Storage backend on custom endpoint.
|
|
|
|
|
$ export MINIO_ACCESS_KEY=azureaccountname
|
|
|
|
|
$ export MINIO_SECRET_KEY=azureaccountkey
|
|
|
|
|
$ {{.HelpName}} https://azure.example.com
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
var azureBackendCmd = cli.Command{
|
|
|
|
|
Name: "azure",
|
|
|
|
|
Usage: "Microsoft Azure Blob Storage.",
|
|
|
|
|
Action: azureGatewayMain,
|
|
|
|
|
CustomHelpTemplate: azureGatewayTemplate,
|
|
|
|
|
Flags: append(serverFlags,
|
|
|
|
|
cli.BoolFlag{
|
|
|
|
|
Name: "quiet",
|
|
|
|
|
Usage: "Disable startup banner.",
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
HideHelpCommand: true,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const s3GatewayTemplate = `NAME:
|
|
|
|
|
{{.HelpName}} - {{.Usage}}
|
|
|
|
|
|
|
|
|
|
USAGE:
|
|
|
|
|
{{.HelpName}} {{if .VisibleFlags}}[FLAGS]{{end}} [ENDPOINT]
|
|
|
|
|
{{if .VisibleFlags}}
|
|
|
|
|
FLAGS:
|
|
|
|
|
{{range .VisibleFlags}}{{.}}
|
|
|
|
|
{{end}}{{end}}
|
|
|
|
|
ENDPOINT:
|
|
|
|
|
S3 server endpoint. Default ENDPOINT is https://s3.amazonaws.com
|
|
|
|
|
|
|
|
|
|
ENVIRONMENT VARIABLES:
|
|
|
|
|
ACCESS:
|
|
|
|
|
MINIO_ACCESS_KEY: Username or access key of S3 storage.
|
|
|
|
|
MINIO_SECRET_KEY: Password or secret key of S3 storage.
|
|
|
|
|
|
|
|
|
|
BROWSER:
|
|
|
|
|
MINIO_BROWSER: To disable web browser access, set this value to "off".
|
2017-05-03 20:55:30 -04:00
|
|
|
|
|
2017-06-09 02:28:45 -04:00
|
|
|
|
EXAMPLES:
|
|
|
|
|
1. Start minio gateway server for AWS S3 backend.
|
2017-05-03 20:55:30 -04:00
|
|
|
|
$ export MINIO_ACCESS_KEY=accesskey
|
|
|
|
|
$ export MINIO_SECRET_KEY=secretkey
|
2017-06-09 02:28:45 -04:00
|
|
|
|
$ {{.HelpName}}
|
2017-05-03 20:55:30 -04:00
|
|
|
|
|
2017-06-09 02:28:45 -04:00
|
|
|
|
2. Start minio gateway server for S3 backend on custom endpoint.
|
2017-05-03 20:55:30 -04:00
|
|
|
|
$ export MINIO_ACCESS_KEY=Q3AM3UQ867SPQQA43P2F
|
|
|
|
|
$ export MINIO_SECRET_KEY=zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG
|
2017-06-09 02:28:45 -04:00
|
|
|
|
$ {{.HelpName}} https://play.minio.io:9000
|
2017-03-16 15:21:58 -04:00
|
|
|
|
`
|
|
|
|
|
|
2017-05-08 15:44:08 -04:00
|
|
|
|
const gcsGatewayTemplate = `NAME:
|
|
|
|
|
{{.HelpName}} - {{.Usage}}
|
|
|
|
|
|
|
|
|
|
USAGE:
|
|
|
|
|
{{.HelpName}} {{if .VisibleFlags}}[FLAGS]{{end}} PROJECTID
|
|
|
|
|
{{if .VisibleFlags}}
|
|
|
|
|
FLAGS:
|
|
|
|
|
{{range .VisibleFlags}}{{.}}
|
|
|
|
|
{{end}}{{end}}
|
|
|
|
|
PROJECTID:
|
|
|
|
|
GCS project id, there are no defaults this is mandatory.
|
|
|
|
|
|
|
|
|
|
ENVIRONMENT VARIABLES:
|
|
|
|
|
ACCESS:
|
|
|
|
|
MINIO_ACCESS_KEY: Username or access key of S3 storage.
|
|
|
|
|
MINIO_SECRET_KEY: Password or secret key of S3 storage.
|
|
|
|
|
|
|
|
|
|
BROWSER:
|
|
|
|
|
MINIO_BROWSER: To disable web browser access, set this value to "off".
|
|
|
|
|
|
|
|
|
|
EXAMPLES:
|
|
|
|
|
1. Start minio gateway server for AWS S3 backend.
|
|
|
|
|
$ export MINIO_ACCESS_KEY=accesskey
|
|
|
|
|
$ export MINIO_SECRET_KEY=secretkey
|
|
|
|
|
$ {{.HelpName}} minio-kubernetes-gcs
|
|
|
|
|
`
|
|
|
|
|
|
2017-06-09 02:28:45 -04:00
|
|
|
|
var s3BackendCmd = cli.Command{
|
|
|
|
|
Name: "s3",
|
|
|
|
|
Usage: "Amazon Simple Storage Service (S3).",
|
|
|
|
|
Action: s3GatewayMain,
|
|
|
|
|
CustomHelpTemplate: s3GatewayTemplate,
|
2017-04-28 19:42:16 -04:00
|
|
|
|
Flags: append(serverFlags,
|
|
|
|
|
cli.BoolFlag{
|
|
|
|
|
Name: "quiet",
|
|
|
|
|
Usage: "Disable startup banner.",
|
2017-04-27 14:26:00 -04:00
|
|
|
|
},
|
|
|
|
|
),
|
2017-03-16 15:21:58 -04:00
|
|
|
|
HideHelpCommand: true,
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-08 15:44:08 -04:00
|
|
|
|
var gcsBackendCmd = cli.Command{
|
|
|
|
|
Name: "gcs",
|
|
|
|
|
Usage: "Google Cloud Storage.",
|
|
|
|
|
Action: gcsGatewayMain,
|
|
|
|
|
CustomHelpTemplate: gcsGatewayTemplate,
|
|
|
|
|
Flags: append(serverFlags,
|
|
|
|
|
cli.BoolFlag{
|
|
|
|
|
Name: "quiet",
|
|
|
|
|
Usage: "Disable startup banner.",
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
HideHelpCommand: true,
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-09 02:28:45 -04:00
|
|
|
|
var gatewayCmd = cli.Command{
|
|
|
|
|
Name: "gateway",
|
|
|
|
|
Usage: "Start object storage gateway.",
|
|
|
|
|
HideHelpCommand: true,
|
2017-05-08 15:44:08 -04:00
|
|
|
|
Subcommands: []cli.Command{azureBackendCmd, s3BackendCmd, gcsBackendCmd},
|
2017-06-09 02:28:45 -04:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-16 15:21:58 -04:00
|
|
|
|
// Represents the type of the gateway backend.
|
|
|
|
|
type gatewayBackend string
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
azureBackend gatewayBackend = "azure"
|
2017-04-27 14:26:00 -04:00
|
|
|
|
s3Backend gatewayBackend = "s3"
|
2017-05-01 13:59:54 -04:00
|
|
|
|
gcsBackend gatewayBackend = "gcs"
|
2017-03-16 15:21:58 -04:00
|
|
|
|
// Add more backends here.
|
|
|
|
|
)
|
|
|
|
|
|
2017-05-08 19:49:41 -04:00
|
|
|
|
// GatewayFn returns the GatewayLayer for the backend
|
|
|
|
|
type GatewayFn func([]string) (GatewayLayer, error)
|
|
|
|
|
|
|
|
|
|
var (
|
|
|
|
|
backends = map[gatewayBackend]GatewayFn{
|
|
|
|
|
azureBackend: newAzureLayer,
|
|
|
|
|
s3Backend: newS3Gateway,
|
|
|
|
|
gcsBackend: newGCSGateway,
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
|
2017-03-16 15:21:58 -04:00
|
|
|
|
// Returns access and secretkey set from environment variables.
|
2017-05-08 17:40:27 -04:00
|
|
|
|
func mustGetGatewayConfigFromEnv() (string, string, string) {
|
2017-03-16 15:21:58 -04:00
|
|
|
|
// Fetch access keys from environment variables.
|
2017-05-08 17:40:27 -04:00
|
|
|
|
accessKey := os.Getenv("MINIO_ACCESS_KEY")
|
|
|
|
|
secretKey := os.Getenv("MINIO_SECRET_KEY")
|
2017-03-16 15:21:58 -04:00
|
|
|
|
if accessKey == "" || secretKey == "" {
|
2017-03-23 19:36:00 -04:00
|
|
|
|
fatalIf(errors.New("Missing credentials"), "Access and secret keys are mandatory to run Minio gateway server.")
|
2017-03-16 15:21:58 -04:00
|
|
|
|
}
|
2017-05-08 17:40:27 -04:00
|
|
|
|
|
|
|
|
|
region := globalMinioDefaultRegion
|
|
|
|
|
if v := os.Getenv("MINIO_REGION"); v != "" {
|
|
|
|
|
region = v
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return accessKey, secretKey, region
|
2017-03-16 15:21:58 -04:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-01 12:43:20 -04:00
|
|
|
|
// Set browser setting from environment variables
|
2017-06-02 17:05:51 -04:00
|
|
|
|
func mustSetBrowserSettingFromEnv() {
|
2017-06-01 12:43:20 -04:00
|
|
|
|
if browser := os.Getenv("MINIO_BROWSER"); browser != "" {
|
|
|
|
|
browserFlag, err := ParseBrowserFlag(browser)
|
|
|
|
|
if err != nil {
|
|
|
|
|
fatalIf(errors.New("invalid value"), "Unknown value ‘%s’ in MINIO_BROWSER environment variable.", browser)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// browser Envs are set globally, this does not represent
|
|
|
|
|
// if browser is turned off or on.
|
|
|
|
|
globalIsEnvBrowser = true
|
|
|
|
|
globalIsBrowserEnabled = bool(browserFlag)
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-06-02 17:05:51 -04:00
|
|
|
|
|
2017-03-16 15:21:58 -04:00
|
|
|
|
// Initialize gateway layer depending on the backend type.
|
|
|
|
|
// Supported backend types are
|
|
|
|
|
//
|
|
|
|
|
// - Azure Blob Storage.
|
2017-05-08 15:44:08 -04:00
|
|
|
|
// - S3 Object Storage.
|
|
|
|
|
// - Google Cloud Storage.
|
2017-03-16 15:21:58 -04:00
|
|
|
|
// - Add your favorite backend here.
|
2017-06-09 02:28:45 -04:00
|
|
|
|
func newGatewayLayer(backendType gatewayBackend, endpoint, accessKey, secretKey string, secure bool) (GatewayLayer, error) {
|
2017-06-01 12:43:20 -04:00
|
|
|
|
|
2017-04-27 14:26:00 -04:00
|
|
|
|
switch gatewayBackend(backendType) {
|
|
|
|
|
case azureBackend:
|
|
|
|
|
return newAzureLayer(endpoint, accessKey, secretKey, secure)
|
|
|
|
|
case s3Backend:
|
|
|
|
|
return newS3Gateway(endpoint, accessKey, secretKey, secure)
|
2017-05-01 13:59:54 -04:00
|
|
|
|
case gcsBackend:
|
|
|
|
|
return newGCSGateway(endpoint, accessKey, secretKey, secure)
|
2017-03-16 15:21:58 -04:00
|
|
|
|
}
|
2017-04-27 14:26:00 -04:00
|
|
|
|
|
|
|
|
|
return nil, fmt.Errorf("Unrecognized backend type %s", backendType)
|
2017-03-16 15:21:58 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Initialize a new gateway config.
|
|
|
|
|
//
|
|
|
|
|
// DO NOT save this config, this is meant to be
|
|
|
|
|
// only used in memory.
|
|
|
|
|
func newGatewayConfig(accessKey, secretKey, region string) error {
|
|
|
|
|
// Initialize server config.
|
2017-06-14 20:27:03 -04:00
|
|
|
|
srvCfg := newServerConfigV19()
|
2017-03-16 15:21:58 -04:00
|
|
|
|
|
|
|
|
|
// If env is set for a fresh start, save them to config file.
|
|
|
|
|
srvCfg.SetCredential(credential{
|
|
|
|
|
AccessKey: accessKey,
|
|
|
|
|
SecretKey: secretKey,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// Set custom region.
|
|
|
|
|
srvCfg.SetRegion(region)
|
|
|
|
|
|
|
|
|
|
// hold the mutex lock before a new config is assigned.
|
|
|
|
|
// Save the new config globally.
|
|
|
|
|
// unlock the mutex.
|
|
|
|
|
serverConfigMu.Lock()
|
|
|
|
|
serverConfig = srvCfg
|
|
|
|
|
serverConfigMu.Unlock()
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-11 20:44:26 -04:00
|
|
|
|
// 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
|
|
|
|
|
}
|
2017-04-27 14:26:00 -04:00
|
|
|
|
|
2017-04-11 20:44:26 -04:00
|
|
|
|
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)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-08 14:20:56 -04:00
|
|
|
|
// Validate gateway arguments.
|
|
|
|
|
func validateGatewayArguments(serverAddr, endpointAddr string) error {
|
|
|
|
|
if err := CheckLocalServerAddr(serverAddr); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if runtime.GOOS == "darwin" {
|
|
|
|
|
_, port := mustSplitHostPort(serverAddr)
|
|
|
|
|
// On macOS, if a process already listens on LOCALIPADDR:PORT, net.Listen() falls back
|
|
|
|
|
// to IPv6 address i.e minio will start listening on IPv6 address whereas another
|
|
|
|
|
// (non-)minio process is listening on IPv4 of given port.
|
|
|
|
|
// To avoid this error situation we check for port availability only for macOS.
|
|
|
|
|
if err := checkPortAvailability(port); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if endpointAddr != "" {
|
|
|
|
|
// Reject the endpoint if it points to the gateway handler itself.
|
|
|
|
|
sameTarget, err := sameLocalAddrs(endpointAddr, serverAddr)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
if sameTarget {
|
|
|
|
|
return errors.New("endpoint points to the local gateway")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-09 02:28:45 -04:00
|
|
|
|
// Handler for 'minio gateway azure' command line.
|
|
|
|
|
func azureGatewayMain(ctx *cli.Context) {
|
|
|
|
|
if ctx.Args().Present() && ctx.Args().First() == "help" {
|
|
|
|
|
cli.ShowCommandHelpAndExit(ctx, "azure", 1)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gatewayMain(ctx, azureBackend)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Handler for 'minio gateway s3' command line.
|
|
|
|
|
func s3GatewayMain(ctx *cli.Context) {
|
|
|
|
|
if ctx.Args().Present() && ctx.Args().First() == "help" {
|
|
|
|
|
cli.ShowCommandHelpAndExit(ctx, "s3", 1)
|
2017-03-16 15:21:58 -04:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-09 02:28:45 -04:00
|
|
|
|
gatewayMain(ctx, s3Backend)
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-08 15:44:08 -04:00
|
|
|
|
// Handler for 'minio gateway gcs' command line
|
|
|
|
|
func gcsGatewayMain(ctx *cli.Context) {
|
|
|
|
|
if ctx.Args().Present() && ctx.Args().First() == "help" {
|
|
|
|
|
cli.ShowCommandHelpAndExit(ctx, "s3", 1)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gatewayMain(ctx, gcsBackend)
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-09 02:28:45 -04:00
|
|
|
|
// Handler for 'minio gateway'.
|
|
|
|
|
func gatewayMain(ctx *cli.Context, backendType gatewayBackend) {
|
2017-03-16 15:21:58 -04:00
|
|
|
|
// Fetch access and secret key from env.
|
2017-05-08 17:40:27 -04:00
|
|
|
|
accessKey, secretKey, region := mustGetGatewayConfigFromEnv()
|
2017-03-16 15:21:58 -04:00
|
|
|
|
|
2017-06-01 12:43:20 -04:00
|
|
|
|
// Fetch browser env setting
|
|
|
|
|
mustSetBrowserSettingFromEnv()
|
|
|
|
|
|
2017-03-16 15:21:58 -04:00
|
|
|
|
// Initialize new gateway config.
|
2017-05-08 17:40:27 -04:00
|
|
|
|
newGatewayConfig(accessKey, secretKey, region)
|
2017-03-16 15:21:58 -04:00
|
|
|
|
|
|
|
|
|
// Get quiet flag from command line argument.
|
|
|
|
|
quietFlag := ctx.Bool("quiet") || ctx.GlobalBool("quiet")
|
2017-03-30 14:21:19 -04:00
|
|
|
|
if quietFlag {
|
|
|
|
|
log.EnableQuiet()
|
|
|
|
|
}
|
2017-03-16 15:21:58 -04:00
|
|
|
|
|
2017-05-17 00:13:29 -04:00
|
|
|
|
serverAddr := ctx.String("address")
|
2017-06-09 02:28:45 -04:00
|
|
|
|
endpointAddr := ctx.Args().Get(0)
|
2017-06-08 14:20:56 -04:00
|
|
|
|
err := validateGatewayArguments(serverAddr, endpointAddr)
|
|
|
|
|
fatalIf(err, "Invalid argument")
|
2017-03-16 15:21:58 -04:00
|
|
|
|
|
2017-04-11 20:44:26 -04:00
|
|
|
|
// Second argument is endpoint. If no endpoint is specified then the
|
|
|
|
|
// gateway implementation should use a default setting.
|
2017-05-17 00:13:29 -04:00
|
|
|
|
endPoint, secure, err := parseGatewayEndpoint(endpointAddr)
|
2017-04-11 20:44:26 -04:00
|
|
|
|
fatalIf(err, "Unable to parse endpoint")
|
|
|
|
|
|
2017-03-31 01:26:24 -04:00
|
|
|
|
// Create certs path for SSL configuration.
|
|
|
|
|
fatalIf(createConfigDir(), "Unable to create configuration directory")
|
|
|
|
|
|
2017-04-11 20:44:26 -04:00
|
|
|
|
newObject, err := newGatewayLayer(backendType, endPoint, accessKey, secretKey, secure)
|
2017-03-23 19:36:00 -04:00
|
|
|
|
fatalIf(err, "Unable to initialize gateway layer")
|
2017-03-16 15:21:58 -04:00
|
|
|
|
|
|
|
|
|
initNSLock(false) // Enable local namespace lock.
|
|
|
|
|
|
|
|
|
|
router := mux.NewRouter().SkipClean(true)
|
2017-06-01 12:43:20 -04:00
|
|
|
|
|
2017-06-06 17:56:41 -04:00
|
|
|
|
// credentials Envs are set globally.
|
|
|
|
|
globalIsEnvCreds = true
|
|
|
|
|
|
2017-06-01 12:43:20 -04:00
|
|
|
|
// Register web router when its enabled.
|
|
|
|
|
if globalIsBrowserEnabled {
|
|
|
|
|
aerr := registerWebRouter(router)
|
|
|
|
|
fatalIf(aerr, "Unable to configure web browser")
|
|
|
|
|
}
|
2017-03-16 15:21:58 -04:00
|
|
|
|
registerGatewayAPIRouter(router, newObject)
|
|
|
|
|
|
|
|
|
|
var handlerFns = []HandlerFunc{
|
2017-04-28 20:17:18 -04:00
|
|
|
|
// Validate all the incoming paths.
|
|
|
|
|
setPathValidityHandler,
|
2017-03-16 15:21:58 -04:00
|
|
|
|
// Limits all requests size to a maximum fixed limit
|
|
|
|
|
setRequestSizeLimitHandler,
|
|
|
|
|
// Adds 'crossdomain.xml' policy handler to serve legacy flash clients.
|
|
|
|
|
setCrossDomainPolicy,
|
|
|
|
|
// Validates all incoming requests to have a valid date header.
|
2017-06-01 12:43:20 -04:00
|
|
|
|
// Redirect some pre-defined browser request paths to a static location prefix.
|
|
|
|
|
setBrowserRedirectHandler,
|
|
|
|
|
// Validates if incoming request is for restricted buckets.
|
|
|
|
|
setPrivateBucketHandler,
|
|
|
|
|
// Adds cache control for all browser requests.
|
|
|
|
|
setBrowserCacheControlHandler,
|
|
|
|
|
// Validates all incoming requests to have a valid date header.
|
2017-03-16 15:21:58 -04:00
|
|
|
|
setTimeValidityHandler,
|
|
|
|
|
// CORS setting for all browser API requests.
|
|
|
|
|
setCorsHandler,
|
|
|
|
|
// Validates all incoming URL resources, for invalid/unsupported
|
|
|
|
|
// resources client receives a HTTP error.
|
|
|
|
|
setIgnoreResourcesHandler,
|
|
|
|
|
// Auth handler verifies incoming authorization headers and
|
|
|
|
|
// routes them accordingly. Client receives a HTTP error for
|
|
|
|
|
// invalid/unsupported signatures.
|
|
|
|
|
setAuthHandler,
|
2017-06-01 12:43:20 -04:00
|
|
|
|
// Add new handlers here.
|
|
|
|
|
|
2017-03-16 15:21:58 -04:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-17 00:13:29 -04:00
|
|
|
|
apiServer := NewServerMux(serverAddr, registerHandlers(router, handlerFns...))
|
2017-03-16 15:21:58 -04:00
|
|
|
|
|
2017-03-30 14:21:19 -04:00
|
|
|
|
_, _, globalIsSSL, err = getSSLConfig()
|
|
|
|
|
fatalIf(err, "Invalid SSL key file")
|
2017-03-16 15:21:58 -04:00
|
|
|
|
|
|
|
|
|
// Start server, automatically configures TLS if certs are available.
|
|
|
|
|
go func() {
|
|
|
|
|
cert, key := "", ""
|
|
|
|
|
if globalIsSSL {
|
|
|
|
|
cert, key = getPublicCertFile(), getPrivateKeyFile()
|
|
|
|
|
}
|
2017-03-23 19:36:00 -04:00
|
|
|
|
|
|
|
|
|
aerr := apiServer.ListenAndServe(cert, key)
|
|
|
|
|
fatalIf(aerr, "Failed to start minio server")
|
2017-03-16 15:21:58 -04:00
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
// Once endpoints are finalized, initialize the new object api.
|
|
|
|
|
globalObjLayerMutex.Lock()
|
|
|
|
|
globalObjectAPI = newObject
|
|
|
|
|
globalObjLayerMutex.Unlock()
|
|
|
|
|
|
|
|
|
|
// Prints the formatted startup message once object layer is initialized.
|
|
|
|
|
if !quietFlag {
|
|
|
|
|
mode := ""
|
|
|
|
|
if gatewayBackend(backendType) == azureBackend {
|
|
|
|
|
mode = globalMinioModeGatewayAzure
|
2017-04-27 14:26:00 -04:00
|
|
|
|
} else if gatewayBackend(backendType) == s3Backend {
|
|
|
|
|
mode = globalMinioModeGatewayS3
|
2017-03-16 15:21:58 -04:00
|
|
|
|
}
|
|
|
|
|
checkUpdate(mode)
|
2017-04-11 18:44:27 -04:00
|
|
|
|
apiEndpoints := getAPIEndpoints(apiServer.Addr)
|
|
|
|
|
printGatewayStartupMessage(apiEndpoints, accessKey, secretKey, backendType)
|
2017-03-16 15:21:58 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
<-globalServiceDoneCh
|
|
|
|
|
}
|