package nixcache import ( "fmt" "net/url" ) // ReadURL puts the pull token in as the basic auth password, with "x" as the user func ReadURL(atticURL, cache, pullToken string) (string, error) { if !validName.MatchString(cache) { return "", fmt.Errorf("%q is not a plain attic cache name", cache) } if pullToken == "" { return "", fmt.Errorf("no pull token for cache %s", cache) } u, err := url.Parse(atticURL) if err != nil || (u.Scheme != "http" && u.Scheme != "https") || u.Host == "" { return "", fmt.Errorf("invalid attic url %q", atticURL) } u.User = url.UserPassword("x", pullToken) u = u.JoinPath(cache) u.RawQuery, u.Fragment = "", "" return u.String(), nil }