MCPcopy
hub / github.com/zarf-dev/zarf / Pull

Function Pull

src/pkg/packager/pull.go:55–113  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
55func 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

Callers 7

runMethod · 0.92
runMethod · 0.92
runMethod · 0.92
downloadInitPackageMethod · 0.92
TestPullFunction · 0.70
TestPullUncompressedFunction · 0.70
TestPullUnsupportedFunction · 0.70

Calls 7

FromFunction · 0.92
GetArchFunction · 0.92
ResolveCachePathFunction · 0.92
DefaultVerifyBlobOptionsFunction · 0.92
LoadPackageFunction · 0.85
CleanupMethod · 0.80
FileNameMethod · 0.80

Tested by 3

TestPullFunction · 0.56
TestPullUncompressedFunction · 0.56
TestPullUnsupportedFunction · 0.56