1
0
mirror of https://github.com/minio/mc.git synced 2025-07-30 07:23:03 +03:00

config: Provide meaningful errors for invalid URL and Alias. (#2233)

Fixes #2232
This commit is contained in:
Harshavardhana
2017-08-06 11:35:01 -07:00
committed by GitHub
parent e53ad24e8c
commit 60681d7fb6
4 changed files with 24 additions and 21 deletions

View File

@ -72,12 +72,11 @@ func checkConfigHostAddSyntax(ctx *cli.Context) {
api := args.Get(4) api := args.Get(4)
if !isValidAlias(alias) { if !isValidAlias(alias) {
fatalIf(errDummy().Trace(alias), "Invalid alias `"+alias+"`.") fatalIf(errInvalidAlias(alias), "Invalid alias")
} }
if !isValidHostURL(url) { if !isValidHostURL(url) {
fatalIf(errDummy().Trace(url), fatalIf(errInvalidURL(url), "Invalid URL.")
"Invalid URL `"+url+"`.")
} }
if !isValidAccessKey(accessKey) { if !isValidAccessKey(accessKey) {

View File

@ -17,7 +17,6 @@
package cmd package cmd
import ( import (
"bytes"
"fmt" "fmt"
"strings" "strings"
) )
@ -54,25 +53,13 @@ func validateConfigFile(config *configV8) (bool, []string) {
func validateConfigHost(host hostConfigV8) (bool, []string) { func validateConfigHost(host hostConfigV8) (bool, []string) {
var validationSuccessful = true var validationSuccessful = true
var hostErrors []string var hostErrors []string
api := host.API if !isValidAPI(strings.ToLower(host.API)) {
validAPI := isValidAPI(strings.ToLower(api))
if !validAPI {
var errorMsg bytes.Buffer
errorMsg.WriteString(fmt.Sprintf(
"%s API for host %s is not Valid. It is not part of any of the following APIs:\n",
api, host.URL))
for index, validAPI := range validAPIs {
errorMsg.WriteString(fmt.Sprintf("%d. %s\n", index+1, validAPI))
}
validationSuccessful = false validationSuccessful = false
hostErrors = append(hostErrors, errorMsg.String()) hostErrors = append(hostErrors, errInvalidAPISignature(host.API, host.URL).ToGoError().Error())
} }
url := host.URL if !isValidHostURL(host.URL) {
validURL := isValidHostURL(url)
if !validURL {
validationSuccessful = false validationSuccessful = false
msg := fmt.Sprintf("URL %s for host %s is not valid. Could not parse it.\n", url, host.URL) hostErrors = append(hostErrors, errInvalidURL(host.URL).ToGoError().Error())
hostErrors = append(hostErrors, msg)
} }
return validationSuccessful, hostErrors return validationSuccessful, hostErrors
} }

View File

@ -134,7 +134,7 @@ func checkConfig() {
} }
errorMsg.WriteString(errMsg + "\n") errorMsg.WriteString(errMsg + "\n")
} }
console.Fatalln(errorMsg.String()) console.Fatal(errorMsg.String())
} }
} }

View File

@ -18,6 +18,8 @@ package cmd
import ( import (
"errors" "errors"
"fmt"
"strings"
"github.com/minio/minio/pkg/probe" "github.com/minio/minio/pkg/probe"
) )
@ -39,6 +41,21 @@ var (
return probe.NewError(errors.New("Use `mc config host add mycloud " + URL + " ...` to add an alias. Use the alias for S3 operations.")).Untrace() return probe.NewError(errors.New("Use `mc config host add mycloud " + URL + " ...` to add an alias. Use the alias for S3 operations.")).Untrace()
} }
errInvalidAlias = func(alias string) *probe.Error {
return probe.NewError(errors.New("Alias `" + alias + "` should have alphanumeric characters such as [helloWorld0, hello_World0, ...]"))
}
errInvalidURL = func(URL string) *probe.Error {
return probe.NewError(errors.New("URL `" + URL + "` for minio client should be of the form scheme://host[:port]/ without resource component."))
}
errInvalidAPISignature = func(api, url string) *probe.Error {
msg := fmt.Sprintf(
"Unrecognized API signature %s for host %s. Valid options are `[%s]`",
api, url, strings.Join(validAPIs, ", "))
return probe.NewError(errors.New(msg))
}
errNoMatchingHost = func(URL string) *probe.Error { errNoMatchingHost = func(URL string) *probe.Error {
return probe.NewError(errors.New("No matching host found for the given URL `" + URL + "`.")).Untrace() return probe.NewError(errors.New("No matching host found for the given URL `" + URL + "`.")).Untrace()
} }