ResolveChartVersion resolves a chart reference to a URL. It returns: - A hash of the content if available - The URL and sets the ChartDownloader's Options that can fetch the URL using the appropriate Getter. - An error if there is one A reference may be an HTTP URL, an oci reference URL, a 'repona
(ref, version string)
| 365 | // |
| 366 | // TODO: support OCI hash |
| 367 | func (c *ChartDownloader) ResolveChartVersion(ref, version string) (string, *url.URL, error) { |
| 368 | u, err := url.Parse(ref) |
| 369 | if err != nil { |
| 370 | return "", nil, fmt.Errorf("invalid chart URL format: %s", ref) |
| 371 | } |
| 372 | |
| 373 | if registry.IsOCI(u.String()) { |
| 374 | if c.RegistryClient == nil { |
| 375 | return "", nil, fmt.Errorf("unable to lookup ref %s at version '%s', missing registry client", ref, version) |
| 376 | } |
| 377 | |
| 378 | digest, OCIref, err := c.RegistryClient.ValidateReference(ref, version, u) |
| 379 | return digest, OCIref, err |
| 380 | } |
| 381 | |
| 382 | rf, err := loadRepoConfig(c.RepositoryConfig) |
| 383 | if err != nil { |
| 384 | return "", u, err |
| 385 | } |
| 386 | |
| 387 | if u.IsAbs() && len(u.Host) > 0 && len(u.Path) > 0 { |
| 388 | // In this case, we have to find the parent repo that contains this chart |
| 389 | // URL. And this is an unfortunate problem, as it requires actually going |
| 390 | // through each repo cache file and finding a matching URL. But basically |
| 391 | // we want to find the repo in case we have special SSL cert config |
| 392 | // for that repo. |
| 393 | |
| 394 | rc, err := c.scanReposForURL(ref, rf) |
| 395 | if err != nil { |
| 396 | // If there is no special config, return the default HTTP client and |
| 397 | // swallow the error. |
| 398 | if errors.Is(err, ErrNoOwnerRepo) { |
| 399 | // Make sure to add the ref URL as the URL for the getter |
| 400 | c.Options = append(c.Options, getter.WithURL(ref)) |
| 401 | return "", u, nil |
| 402 | } |
| 403 | return "", u, err |
| 404 | } |
| 405 | |
| 406 | // If we get here, we don't need to go through the next phase of looking |
| 407 | // up the URL. We have it already. So we just set the parameters and return. |
| 408 | c.Options = append( |
| 409 | c.Options, |
| 410 | getter.WithURL(rc.URL), |
| 411 | ) |
| 412 | if rc.CertFile != "" || rc.KeyFile != "" || rc.CAFile != "" { |
| 413 | c.Options = append(c.Options, getter.WithTLSClientConfig(rc.CertFile, rc.KeyFile, rc.CAFile)) |
| 414 | } |
| 415 | if rc.Username != "" && rc.Password != "" { |
| 416 | c.Options = append( |
| 417 | c.Options, |
| 418 | getter.WithBasicAuth(rc.Username, rc.Password), |
| 419 | getter.WithPassCredentialsAll(rc.PassCredentialsAll), |
| 420 | ) |
| 421 | } |
| 422 | return "", u, nil |
| 423 | } |
| 424 |