forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
max_api_version.go
52 lines (43 loc) · 1.27 KB
/
max_api_version.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
package requirements
import (
"errors"
"code.cloudfoundry.org/cli/cf/configuration/coreconfig"
"github.com/blang/semver"
. "code.cloudfoundry.org/cli/cf/i18n"
)
type MaxAPIVersionRequirement struct {
config coreconfig.Reader
feature string
maximumVersion semver.Version
}
func NewMaxAPIVersionRequirement(
config coreconfig.Reader,
feature string,
maximumVersion semver.Version,
) MaxAPIVersionRequirement {
return MaxAPIVersionRequirement{
config: config,
feature: feature,
maximumVersion: maximumVersion,
}
}
func (r MaxAPIVersionRequirement) Execute() error {
if r.config.APIVersion() == "" {
return errors.New(T("Unable to determine CC API Version. Please log in again."))
}
apiVersion, err := semver.Make(r.config.APIVersion())
if err != nil {
return errors.New(T("Unable to parse CC API Version '{{.APIVersion}}'", map[string]interface{}{
"APIVersion": r.config.APIVersion(),
}))
}
if apiVersion.GT(r.maximumVersion) {
return errors.New(T(`{{.Feature}} only works up to CF API version {{.MaximumVersion}}. Your target is {{.APIVersion}}.`,
map[string]interface{}{
"APIVersion": r.config.APIVersion(),
"Feature": r.feature,
"MaximumVersion": r.maximumVersion.String(),
}))
}
return nil
}