-
Notifications
You must be signed in to change notification settings - Fork 90
/
features.go
49 lines (44 loc) · 1.58 KB
/
features.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
package argocd
import (
"fmt"
"github.com/Masterminds/semver"
"github.com/argoproj/argo-cd/pkg/apiclient"
"github.com/argoproj/argo-cd/pkg/apiclient/application"
"github.com/argoproj/argo-cd/pkg/apiclient/project"
"github.com/argoproj/argo-cd/pkg/apiclient/repocreds"
"github.com/argoproj/argo-cd/pkg/apiclient/repository"
"github.com/argoproj/argo-cd/pkg/apiclient/version"
)
const (
featureApplicationLevelSyncOptions = iota
featureRepositoryGet
featureTokenIDs
)
var (
featureVersionConstraintsMap = map[int]*semver.Version{
featureApplicationLevelSyncOptions: semver.MustParse("1.5.0"),
featureRepositoryGet: semver.MustParse("1.6.0"),
featureTokenIDs: semver.MustParse("1.5.3"),
}
)
type ServerInterface struct {
ApiClient *apiclient.Client
ApplicationClient *application.ApplicationServiceClient
ProjectClient *project.ProjectServiceClient
RepositoryClient *repository.RepositoryServiceClient
RepoCredsClient *repocreds.RepoCredsServiceClient
ServerVersion *semver.Version
ServerVersionMessage *version.VersionMessage
}
// Checks that a specific feature is available for the current ArgoCD server version.
// 'feature' argument must match one of the predefined feature* constants.
func (p ServerInterface) isFeatureSupported(feature int) (bool, error) {
versionConstraint, ok := featureVersionConstraintsMap[feature]
if !ok {
return false, fmt.Errorf("feature constraint is not handled by the provider")
}
if i := versionConstraint.Compare(p.ServerVersion); i == 1 {
return false, nil
}
return true, nil
}