Pull takes a source URL and destination directory, fetches the Zarf package from the given sources, and returns the path to the fetched package.
(ctx context.Context, source, destination string, opts PullOptions)
| 53 | |
| 54 | // Pull takes a source URL and destination directory, fetches the Zarf package from the given sources, and returns the path to the fetched package. |
| 55 | func Pull(ctx context.Context, source, destination string, opts PullOptions) (_ string, err error) { |
| 56 | l := logger.From(ctx) |
| 57 | start := time.Now() |
| 58 | |
| 59 | // ensure architecture is set |
| 60 | arch := config.GetArch(opts.Architecture) |
| 61 | |
| 62 | opts.CachePath, err = utils.ResolveCachePath(opts.CachePath) |
| 63 | if err != nil { |
| 64 | return "", err |
| 65 | } |
| 66 | |
| 67 | u, err := url.Parse(source) |
| 68 | if err != nil { |
| 69 | return "", err |
| 70 | } |
| 71 | if destination == "" { |
| 72 | return "", fmt.Errorf("no output directory specified") |
| 73 | } |
| 74 | if u.Scheme == "" { |
| 75 | return "", errors.New("scheme must be either oci:// or http(s)://") |
| 76 | } |
| 77 | if u.Host == "" { |
| 78 | return "", errors.New("host cannot be empty") |
| 79 | } |
| 80 | |
| 81 | // Resolve deprecated PublicKeyPath into VerifyBlobOptions. |
| 82 | // Only applies when VerifyBlobOptions is not already set, |
| 83 | // ensuring the new API takes precedence over the deprecated field. |
| 84 | if opts.VerifyBlobOptions == nil && opts.PublicKeyPath != "" { |
| 85 | defaults := signing.DefaultVerifyBlobOptions() |
| 86 | defaults.Key = opts.PublicKeyPath |
| 87 | opts.VerifyBlobOptions = &defaults |
| 88 | } |
| 89 | |
| 90 | pkgLayout, err := LoadPackage(ctx, source, LoadOptions{ |
| 91 | Shasum: opts.SHASum, |
| 92 | Architecture: arch, |
| 93 | VerifyBlobOptions: opts.VerifyBlobOptions, |
| 94 | VerificationStrategy: opts.VerificationStrategy, |
| 95 | Output: destination, |
| 96 | OCIConcurrency: opts.OCIConcurrency, |
| 97 | RemoteOptions: opts.RemoteOptions, |
| 98 | CachePath: opts.CachePath, |
| 99 | }) |
| 100 | if err != nil { |
| 101 | return "", err |
| 102 | } |
| 103 | if err := pkgLayout.Cleanup(); err != nil { |
| 104 | return "", err |
| 105 | } |
| 106 | filename, err := pkgLayout.FileName() |
| 107 | if err != nil { |
| 108 | return "", err |
| 109 | } |
| 110 | filepath := filepath.Join(destination, filename) |
| 111 | l.Debug("done packager.Pull", "source", source, "destination", destination, "duration", time.Since(start)) |
| 112 | return filepath, nil |