MCPcopy Index your code
hub / github.com/helm/helm / Key

Function Key

internal/plugin/cache/cache.go:32–67  ·  view source on GitHub ↗

Key generates a cache key based on a url or scp string. The key is file system safe.

(repo string)

Source from the content-addressed store, hash-verified

30// Key generates a cache key based on a url or scp string. The key is file
31// system safe.
32func Key(repo string) (string, error) {
33 var (
34 u *url.URL
35 err error
36 )
37 if m := scpSyntaxRe.FindStringSubmatch(repo); m != nil {
38 // Match SCP-like syntax and convert it to a URL.
39 // Eg, "git@github.com:user/repo" becomes
40 // "ssh://git@github.com/user/repo".
41 u = &url.URL{
42 User: url.User(m[1]),
43 Host: m[2],
44 Path: "/" + m[3],
45 }
46 } else {
47 u, err = url.Parse(repo)
48 if err != nil {
49 return "", err
50 }
51 }
52
53 var key strings.Builder
54 if u.Scheme != "" {
55 key.WriteString(u.Scheme)
56 key.WriteString("-")
57 }
58 if u.User != nil && u.User.Username() != "" {
59 key.WriteString(u.User.Username())
60 key.WriteString("-")
61 }
62 key.WriteString(u.Host)
63 if u.Path != "" {
64 key.WriteString(strings.ReplaceAll(u.Path, "/", "-"))
65 }
66 return strings.ReplaceAll(key.String(), ":", "-"), nil
67}

Callers 3

NewVCSInstallerFunction · 0.92
NewOCIInstallerFunction · 0.92
NewHTTPInstallerFunction · 0.92

Calls 1

StringMethod · 0.45

Tested by

no test coverage detected