forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi_version_warning.go
75 lines (60 loc) · 1.95 KB
/
api_version_warning.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package command
import (
"code.cloudfoundry.org/cli/api/cloudcontroller/ccversion"
"code.cloudfoundry.org/cli/version"
"github.com/blang/semver"
)
type APIVersionTooHighError struct{}
func (a APIVersionTooHighError) Error() string {
return ""
}
func WarnIfCLIVersionBelowAPIDefinedMinimum(config Config, apiVersion string, ui UI) error {
minVer := config.MinCLIVersion()
currentVer := config.BinaryVersion()
isOutdated, err := CheckVersionOutdated(currentVer, minVer)
if err != nil {
return err
}
if isOutdated {
ui.DisplayWarning("Cloud Foundry API version {{.APIVersion}} requires CLI version {{.MinCLIVersion}}. You are currently on version {{.BinaryVersion}}. To upgrade your CLI, please visit: https://github.com/cloudfoundry/cli#downloads",
map[string]interface{}{
"APIVersion": apiVersion,
"MinCLIVersion": minVer,
"BinaryVersion": currentVer,
})
}
return nil
}
func WarnIfAPIVersionBelowSupportedMinimum(apiVersion string, ui UI) error {
isOutdated, err := CheckVersionOutdated(apiVersion, ccversion.MinSupportedV2ClientVersion)
if err != nil {
return err
}
if isOutdated {
ui.DisplayWarning("Your CF API version ({{.APIVersion}}) is no longer supported. "+
"Upgrade to a newer version of the API (minimum version {{.MinSupportedVersion}}). Please refer to "+
"https://github.com/cloudfoundry/cli/wiki/Versioning-Policy#cf-cli-minimum-supported-version",
map[string]interface{}{
"APIVersion": apiVersion,
"MinSupportedVersion": ccversion.MinSupportedV2ClientVersion,
})
}
return nil
}
func CheckVersionOutdated(current string, minimum string) (bool, error) {
if current == version.DefaultVersion || minimum == "" {
return false, nil
}
currentSemver, err := semver.Make(current)
if err != nil {
return false, err
}
minimumSemver, err := semver.Make(minimum)
if err != nil {
return false, err
}
if currentSemver.Compare(minimumSemver) == -1 {
return true, nil
}
return false, nil
}