forked from jenkins-x/jx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
binaries.go
54 lines (43 loc) · 1.04 KB
/
binaries.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package binaries
import (
"os/exec"
"runtime"
)
const EksctlVersion = "0.1.3"
const HeptioAuthenticatorAwsVersion = "1.10.3"
func BinaryWithExtension(binary string) string {
if runtime.GOOS == "windows" {
return binary + ".exe"
}
return binary
}
func LookupForBinary(binary string) (string, error) {
path, err := exec.LookPath(BinaryWithExtension(binary))
if err != nil {
return "", err
}
return path, nil
}
type VersionExtractor interface {
arguments() []string
extractVersion(command string, arguments []string) (string, error)
}
func ShouldInstallBinary(binary string, expectedVersion string, versionExtractor VersionExtractor) (bool, error) {
if versionExtractor == nil {
return true, nil
}
binaryPath, err := LookupForBinary(binary)
if err != nil {
return true, err
}
if binaryPath != "" {
currentVersion, err := versionExtractor.extractVersion(binaryPath, versionExtractor.arguments())
if err != nil {
return true, err
}
if currentVersion == expectedVersion {
return false, nil
}
}
return true, nil
}