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)
if !isValidAlias(alias) {
fatalIf(errDummy().Trace(alias), "Invalid alias `"+alias+"`.")
fatalIf(errInvalidAlias(alias), "Invalid alias")
}
if !isValidHostURL(url) {
fatalIf(errDummy().Trace(url),
"Invalid URL `"+url+"`.")
fatalIf(errInvalidURL(url), "Invalid URL.")
}
if !isValidAccessKey(accessKey) {

View File

@ -17,7 +17,6 @@
package cmd
import (
"bytes"
"fmt"
"strings"
)
@ -54,25 +53,13 @@ func validateConfigFile(config *configV8) (bool, []string) {
func validateConfigHost(host hostConfigV8) (bool, []string) {
var validationSuccessful = true
var hostErrors []string
api := 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))
}
if !isValidAPI(strings.ToLower(host.API)) {
validationSuccessful = false
hostErrors = append(hostErrors, errorMsg.String())
hostErrors = append(hostErrors, errInvalidAPISignature(host.API, host.URL).ToGoError().Error())
}
url := host.URL
validURL := isValidHostURL(url)
if !validURL {
if !isValidHostURL(host.URL) {
validationSuccessful = false
msg := fmt.Sprintf("URL %s for host %s is not valid. Could not parse it.\n", url, host.URL)
hostErrors = append(hostErrors, msg)
hostErrors = append(hostErrors, errInvalidURL(host.URL).ToGoError().Error())
}
return validationSuccessful, hostErrors
}

View File

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

View File

@ -18,6 +18,8 @@ package cmd
import (
"errors"
"fmt"
"strings"
"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()
}
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 {
return probe.NewError(errors.New("No matching host found for the given URL `" + URL + "`.")).Untrace()
}