diff --git a/cmd-config.go b/cmd-config.go index 53ea48e3..dfc9cb07 100644 --- a/cmd-config.go +++ b/cmd-config.go @@ -36,10 +36,9 @@ type hostConfig struct { } type mcConfig struct { - Version uint - MCVersion string - Hosts map[string]hostConfig - Aliases map[string]string + Version uint + Hosts map[string]hostConfig + Aliases map[string]string } const ( @@ -237,14 +236,18 @@ func parseConfigInput(c *cli.Context) (config *mcConfig, err error) { switch true { case len(alias) == 0: config = &mcConfig{ - Version: currentConfigVersion, - MCVersion: "0.9", + Version: currentConfigVersion, Hosts: map[string]hostConfig{ "http*://s3*.amazonaws.com": { Auth: auth{ AccessKeyID: accessKeyID, SecretAccessKey: secretAccesskey, }}, + "http*://localhost:*": { + Auth: auth{ + AccessKeyID: accessKeyID, + SecretAccessKey: secretAccesskey, + }}, }, Aliases: map[string]string{ "s3": "https://s3.amazonaws.com", @@ -262,8 +265,7 @@ func parseConfigInput(c *cli.Context) (config *mcConfig, err error) { return nil, iodine.New(errors.New("invalid url type only supports http{s}"), nil) } config = &mcConfig{ - Version: currentConfigVersion, - MCVersion: "0.9", + Version: currentConfigVersion, Hosts: map[string]hostConfig{ "http*://s3*.amazonaws.com": { Auth: auth{ @@ -283,23 +285,31 @@ func parseConfigInput(c *cli.Context) (config *mcConfig, err error) { } } +// getHostURL - +func getHostURL(u *url.URL) string { + return u.Scheme + "://" + u.Host +} + // getHostConfig retrieves host specific configuration such as access keys, certs. -func getHostConfig(hostURL string) (*hostConfig, error) { - _, err := url.Parse(hostURL) +func getHostConfig(requestURL string) (*hostConfig, error) { + u, err := url.Parse(requestURL) if err != nil { return nil, iodine.New(err, nil) } - config, err := getMcConfig() if err != nil { return nil, iodine.New(err, nil) } for globURL, cfg := range config.Hosts { - match, err := filepath.Match(globURL, hostURL) + match, err := filepath.Match(globURL, getHostURL(u)) if err != nil { - return nil, fmt.Errorf("Error parsing glob'ed URL while comparing [%s] [%s]", globURL, hostURL) + msg := fmt.Errorf("Error parsing glob'ed URL while comparing [%s] [%s]", globURL, requestURL) + return nil, iodine.New(msg, map[string]string{ + "globURL": globURL, + "hostURL": requestURL, + }) } if match { var hostCfg hostConfig diff --git a/cmd-update.go b/cmd-update.go index 0554e1b9..a5771273 100644 --- a/cmd-update.go +++ b/cmd-update.go @@ -20,6 +20,7 @@ import ( "errors" "fmt" "io" + "time" "encoding/json" "io/ioutil" @@ -35,9 +36,9 @@ const ( ) type updateResults struct { - Version uint // this is config version - LatestVersion string - Signature string + Version uint // this is config version + LatestBuild string + Signature string } func getReq(url string) (*http.Request, error) { @@ -72,11 +73,13 @@ func doUpdateCmd(ctx *cli.Context) { log.Debug.Println(iodine.New(err, nil)) fatal(err) } - /* FIXME: Config file should not hold versin info (MCVersion). Use commit-id or build-date for the check */ - config, err := getMcConfig() + latest, err := time.Parse(time.RFC3339Nano, ures.LatestBuild) if err != nil { log.Debug.Println(iodine.New(err, nil)) fatal(err) } - printUpdateNotify(ures.LatestVersion, config.MCVersion) + if latest.After(ctx.App.Compiled) { + // FIXME : find some proper versioning scheme here + printUpdateNotify("new", "old") + } }