From 3ac36d1f959af14fb43b7dcfad6761db46f1e5f1 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Tue, 21 Apr 2015 15:00:33 -0700 Subject: [PATCH] Add skip localhost and 127.0.0.1 - treat them as special case in getHostConfig - fixes #467 --- cmd-config.go | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/cmd-config.go b/cmd-config.go index 36de24df..6212a569 100644 --- a/cmd-config.go +++ b/cmd-config.go @@ -62,6 +62,10 @@ const ( globalSecretAccessKey = "YOUR-SECRET-ACCESS-KEY-HERE" ) +const ( + exampleHostURL = "YOUR-EXAMPLE.COM" +) + func getMcConfigDir() (string, error) { u, err := user.Current() if err != nil { @@ -185,13 +189,13 @@ func newConfig() (config quick.Config) { s3HostConf := new(hostConfig) s3HostConf.AccessKeyID = globalAccessKeyID s3HostConf.SecretAccessKey = globalSecretAccessKey - // local minio server can have this empty until webcli is ready - // which would make it easier to generate accesskeys and manage - localhostConf := new(hostConfig) - localhostConf.AccessKeyID = "" - localhostConf.SecretAccessKey = "" - conf.Hosts["http://localhost:9000"] = localhostConf + // Your example host config + exampleHostConf := new(hostConfig) + exampleHostConf.AccessKeyID = globalAccessKeyID + exampleHostConf.SecretAccessKey = globalSecretAccessKey + + conf.Hosts[exampleHostURL] = exampleHostConf conf.Hosts["http*://s3*.amazonaws.com"] = s3HostConf aliases := make(map[string]string) @@ -261,7 +265,7 @@ func getHostConfig(requestURL string) (*hostConfig, error) { if err != nil { return nil, iodine.New(errInvalidURL{url: requestURL}, nil) } - // skip filesystem + // No host matching or keys needed for filesystem requests if client.GetType(requestURL) == client.Filesystem { hostCfg := &hostConfig{ AccessKeyID: "", @@ -269,6 +273,15 @@ func getHostConfig(requestURL string) (*hostConfig, error) { } return hostCfg, nil } + + // No host matching or keys needed for localhost and 127.0.0.1 URL's skip them + if strings.Contains(getHostURL(u), "localhost") || strings.Contains(getHostURL(u), "127.0.0.1") { + hostCfg := &hostConfig{ + AccessKeyID: "", + SecretAccessKey: "", + } + return hostCfg, nil + } for globURL, hostCfg := range config.Hosts { match, err := filepath.Match(globURL, getHostURL(u)) if err != nil { @@ -278,14 +291,9 @@ func getHostConfig(requestURL string) (*hostConfig, error) { if hostCfg == nil { return nil, iodine.New(errInvalidAuth{}, nil) } - // verify Auth key validity for all hosts other than localhost - if !strings.Contains(getHostURL(u), "localhost") { - if !client.IsValidAccessKey(hostCfg.AccessKeyID) { - return nil, iodine.New(errInvalidAuthKeys{}, nil) - } - if !client.IsValidSecretKey(hostCfg.SecretAccessKey) { - return nil, iodine.New(errInvalidAuthKeys{}, nil) - } + // verify Auth key validity for all hosts + if !client.IsValidAccessKey(hostCfg.AccessKeyID) || !client.IsValidSecretKey(hostCfg.SecretAccessKey) { + return nil, iodine.New(errInvalidAuthKeys{}, nil) } return hostCfg, nil }