From a62572fb86b90e751aaa914d4dda6d41d7a2027d Mon Sep 17 00:00:00 2001 From: kannappanr <30541348+kannappanr@users.noreply.github.com> Date: Sun, 17 May 2020 08:46:23 -0700 Subject: [PATCH] Check for address flags in all positions (#9615) Fixes #9599 --- cmd/common-main.go | 2 +- cmd/gateway/azure/gateway-azure.go | 7 ++++++- cmd/gateway/s3/gateway-s3.go | 8 ++++++-- cmd/globals.go | 4 ++-- cmd/server-main.go | 2 +- 5 files changed, 16 insertions(+), 7 deletions(-) diff --git a/cmd/common-main.go b/cmd/common-main.go index d744905fb..4fc455b3a 100644 --- a/cmd/common-main.go +++ b/cmd/common-main.go @@ -145,7 +145,7 @@ func handleCommonCmdArgs(ctx *cli.Context) { // Fetch address option globalCLIContext.Addr = ctx.GlobalString("address") - if globalCLIContext.Addr == "" || globalCLIContext.Addr == ":"+globalMinioDefaultPort { + if globalCLIContext.Addr == "" || globalCLIContext.Addr == ":"+GlobalMinioDefaultPort { globalCLIContext.Addr = ctx.String("address") } diff --git a/cmd/gateway/azure/gateway-azure.go b/cmd/gateway/azure/gateway-azure.go index 46a7361e0..cfb2eeb10 100644 --- a/cmd/gateway/azure/gateway-azure.go +++ b/cmd/gateway/azure/gateway-azure.go @@ -130,8 +130,13 @@ func isAzureMarker(marker string) bool { func azureGatewayMain(ctx *cli.Context) { // Validate gateway arguments. host := ctx.Args().First() + + serverAddr := ctx.GlobalString("address") + if serverAddr == "" || serverAddr == ":"+minio.GlobalMinioDefaultPort { + serverAddr = ctx.String("address") + } // Validate gateway arguments. - logger.FatalIf(minio.ValidateGatewayArguments(ctx.GlobalString("address"), host), "Invalid argument") + logger.FatalIf(minio.ValidateGatewayArguments(serverAddr, host), "Invalid argument") minio.StartGateway(ctx, &Azure{host}) } diff --git a/cmd/gateway/s3/gateway-s3.go b/cmd/gateway/s3/gateway-s3.go index 8e2051fb5..3d388413a 100644 --- a/cmd/gateway/s3/gateway-s3.go +++ b/cmd/gateway/s3/gateway-s3.go @@ -1,5 +1,5 @@ /* - * MinIO Cloud Storage, (C) 2017, 2018, 2019 MinIO, Inc. + * MinIO Cloud Storage, (C) 2017-2020 MinIO, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -89,8 +89,12 @@ func s3GatewayMain(ctx *cli.Context) { args = cli.Args{"https://s3.amazonaws.com"} } + serverAddr := ctx.GlobalString("address") + if serverAddr == "" || serverAddr == ":"+minio.GlobalMinioDefaultPort { + serverAddr = ctx.String("address") + } // Validate gateway arguments. - logger.FatalIf(minio.ValidateGatewayArguments(ctx.GlobalString("address"), args.First()), "Invalid argument") + logger.FatalIf(minio.ValidateGatewayArguments(serverAddr, args.First()), "Invalid argument") // Start the gateway.. minio.StartGateway(ctx, &S3{args.First()}) diff --git a/cmd/globals.go b/cmd/globals.go index 0726ece5a..891ac58ed 100644 --- a/cmd/globals.go +++ b/cmd/globals.go @@ -43,7 +43,7 @@ import ( // minio configuration related constants. const ( - globalMinioDefaultPort = "9000" + GlobalMinioDefaultPort = "9000" globalMinioDefaultRegion = "" // This is a sha256 output of ``arn:aws:iam::minio:user/admin``, @@ -133,7 +133,7 @@ var ( // MinIO local server address (in `host:port` format) globalMinioAddr = "" // MinIO default port, can be changed through command line. - globalMinioPort = globalMinioDefaultPort + globalMinioPort = GlobalMinioDefaultPort // Holds the host that was passed using --address globalMinioHost = "" // Holds the possible host endpoint. diff --git a/cmd/server-main.go b/cmd/server-main.go index ffed2f3e6..8f8932b66 100644 --- a/cmd/server-main.go +++ b/cmd/server-main.go @@ -42,7 +42,7 @@ import ( var ServerFlags = []cli.Flag{ cli.StringFlag{ Name: "address", - Value: ":" + globalMinioDefaultPort, + Value: ":" + GlobalMinioDefaultPort, Usage: "bind to a specific ADDRESS:PORT, ADDRESS can be an IP or hostname", }, }