(metadataPath, version, binaryPath, outFile string)
| 25 | } |
| 26 | |
| 27 | func (i *installer) DownloadBinary(metadataPath, version, binaryPath, outFile string) error { |
| 28 | if isLocalReference(metadataPath) { |
| 29 | localPath := filepath.Join(filepath.Dir(metadataPath), binaryPath) |
| 30 | if isLocalReference(localPath) { |
| 31 | return copy.Copy(localPath, outFile) |
| 32 | } else if isLocalReference(binaryPath) { |
| 33 | return copy.Copy(binaryPath, outFile) |
| 34 | } |
| 35 | |
| 36 | return i.downloadTo(binaryPath, outFile) |
| 37 | } else if isRemoteHTTPYAML(metadataPath) { |
| 38 | return i.downloadTo(binaryPath, outFile) |
| 39 | } |
| 40 | |
| 41 | if strings.HasPrefix(binaryPath, "http://") || strings.HasPrefix(binaryPath, "https://") { |
| 42 | return i.downloadTo(binaryPath, outFile) |
| 43 | } |
| 44 | |
| 45 | tempDir, err := os.MkdirTemp("", "") |
| 46 | if err != nil { |
| 47 | return err |
| 48 | } |
| 49 | |
| 50 | defer os.RemoveAll(tempDir) |
| 51 | repo, err := git.NewGitCLIRepository(context.Background(), tempDir) |
| 52 | if err != nil { |
| 53 | return err |
| 54 | } |
| 55 | |
| 56 | err = repo.Clone(context.Background(), git.CloneOptions{ |
| 57 | URL: metadataPath, |
| 58 | Tag: version, |
| 59 | }) |
| 60 | if err != nil { |
| 61 | return err |
| 62 | } |
| 63 | _ = repo.Pull(context.Background()) |
| 64 | |
| 65 | return copy.Copy(filepath.Join(tempDir, binaryPath), outFile) |
| 66 | } |
| 67 | |
| 68 | func (i *installer) downloadTo(binaryPath, outFile string) error { |
| 69 | resp, err := http.Get(binaryPath) |
nothing calls this directly
no test coverage detected