MCPcopy
hub / github.com/fabiolb/fabio / parseConsulURL

Function parseConsulURL

cert/consul_source.go:29–53  ·  view source on GitHub ↗
(rawurl string)

Source from the content-addressed store, hash-verified

27}
28
29func parseConsulURL(rawurl string) (config *api.Config, key string, err error) {
30 if rawurl == "" || !strings.HasPrefix(rawurl, "http://") && !strings.HasPrefix(rawurl, "https://") {
31 return nil, "", errors.New("invalid url")
32 }
33
34 u, err := url.Parse(rawurl)
35 if err != nil {
36 return nil, "", err
37 }
38
39 config = &api.Config{Address: u.Host, Scheme: u.Scheme}
40 if len(u.Query()["token"]) > 0 {
41 config.Token = u.Query()["token"][0]
42 }
43
44 // path needs to point to kv store and we need
45 // to strip the prefix off to get the key
46 const prefix = "/v1/kv/"
47 key = u.Path
48 if !strings.HasPrefix(key, prefix) {
49 return nil, "", errors.New("missing prefix: " + prefix)
50 }
51 key = key[len(prefix):]
52 return
53}
54
55func (s ConsulSource) LoadClientCAs() (*x509.CertPool, error) {
56 if s.ClientCAURL == "" {

Callers 4

TestParseConsulURLFunction · 0.85
LoadClientCAsMethod · 0.85
CertificatesMethod · 0.85
TestConsulSourceFunction · 0.85

Calls

no outgoing calls

Tested by 2

TestParseConsulURLFunction · 0.68
TestConsulSourceFunction · 0.68