~james/core

core/spindle/nixcache/upstream.go -rw-r--r-- 688 bytes
452f17b7 — james chore(import): snapshot james.dad.town/core at f70c71c7696a 16 hours ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
}