DownloadTo retrieves a chart. Depending on the settings, it may also download a provenance file. If Verify is set to VerifyNever, the verification will be nil. If Verify is set to VerifyIfPossible, this will return a verification (or nil on failure), and print a warning on failure. If Verify is set
(ref, version, dest string)
| 99 | // Returns a string path to the location where the file was downloaded and a verification |
| 100 | // (if provenance was verified), or an error if something bad happened. |
| 101 | func (c *ChartDownloader) DownloadTo(ref, version, dest string) (string, *provenance.Verification, error) { |
| 102 | if c.Cache == nil { |
| 103 | if c.ContentCache == "" { |
| 104 | return "", nil, errors.New("content cache must be set") |
| 105 | } |
| 106 | c.Cache = &DiskCache{Root: c.ContentCache} |
| 107 | slog.Debug("set up default downloader cache") |
| 108 | } |
| 109 | hash, u, err := c.ResolveChartVersion(ref, version) |
| 110 | if err != nil { |
| 111 | return "", nil, err |
| 112 | } |
| 113 | |
| 114 | g, err := c.Getters.ByScheme(u.Scheme) |
| 115 | if err != nil { |
| 116 | return "", nil, err |
| 117 | } |
| 118 | |
| 119 | // Check the cache for the content. Otherwise download it. |
| 120 | // Note, this process will pull from the cache but does not automatically populate |
| 121 | // the cache with the file it downloads. |
| 122 | var data *bytes.Buffer |
| 123 | var found bool |
| 124 | var digest []byte |
| 125 | var digest32 [32]byte |
| 126 | if hash != "" { |
| 127 | // if there is a hash, populate the other formats |
| 128 | // Strip the algorithm prefix (e.g., "sha256:") if present |
| 129 | digest, err = hex.DecodeString(stripDigestAlgorithm(hash)) |
| 130 | if err != nil { |
| 131 | return "", nil, err |
| 132 | } |
| 133 | if len(digest) != 32 { |
| 134 | return "", nil, fmt.Errorf("invalid digest length: %d", len(digest)) |
| 135 | } |
| 136 | |
| 137 | copy(digest32[:], digest) |
| 138 | if pth, err := c.Cache.Get(digest32, CacheChart); err == nil { |
| 139 | fdata, err := os.ReadFile(pth) |
| 140 | if err == nil { |
| 141 | found = true |
| 142 | data = bytes.NewBuffer(fdata) |
| 143 | slog.Debug("found chart in cache", "id", hash) |
| 144 | } |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | if !found { |
| 149 | c.Options = append(c.Options, getter.WithAcceptHeader("application/gzip,application/octet-stream")) |
| 150 | |
| 151 | data, err = g.Get(u.String(), c.Options...) |
| 152 | if err != nil { |
| 153 | return "", nil, err |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | name := filepath.Base(u.Path) |
| 158 | if u.Scheme == registry.OCIScheme { |