-
Notifications
You must be signed in to change notification settings - Fork 5.1k
/
version.go
80 lines (72 loc) · 2.33 KB
/
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package version
import (
"github.com/golang/protobuf/ptypes/empty"
"github.com/google/go-jsonnet"
"golang.org/x/net/context"
"github.com/argoproj/argo-cd/v2/common"
"github.com/argoproj/argo-cd/v2/pkg/apiclient/version"
"github.com/argoproj/argo-cd/v2/server/settings"
"github.com/argoproj/argo-cd/v2/util/helm"
"github.com/argoproj/argo-cd/v2/util/kustomize"
sessionmgr "github.com/argoproj/argo-cd/v2/util/session"
)
type server struct {
kustomizeVersion string
helmVersion string
jsonnetVersion string
authenticator settings.Authenticator
disableAuth func() (bool, error)
}
func NewServer(authenticator settings.Authenticator, disableAuth func() (bool, error)) *server {
return &server{authenticator: authenticator, disableAuth: disableAuth}
}
// Version returns the version of the API server
func (s *server) Version(ctx context.Context, _ *empty.Empty) (*version.VersionMessage, error) {
vers := common.GetVersion()
disableAuth, err := s.disableAuth()
if err != nil {
return nil, err
}
if !sessionmgr.LoggedIn(ctx) && !disableAuth {
return &version.VersionMessage{Version: vers.Version}, nil
}
if s.kustomizeVersion == "" {
kustomizeVersion, err := kustomize.Version(true)
if err == nil {
s.kustomizeVersion = kustomizeVersion
} else {
s.kustomizeVersion = err.Error()
}
}
if s.helmVersion == "" {
helmVersion, err := helm.Version(true)
if err == nil {
s.helmVersion = helmVersion
} else {
s.helmVersion = err.Error()
}
}
s.jsonnetVersion = jsonnet.Version()
return &version.VersionMessage{
Version: vers.Version,
BuildDate: vers.BuildDate,
GitCommit: vers.GitCommit,
GitTag: vers.GitTag,
GitTreeState: vers.GitTreeState,
GoVersion: vers.GoVersion,
Compiler: vers.Compiler,
Platform: vers.Platform,
KustomizeVersion: s.kustomizeVersion,
HelmVersion: s.helmVersion,
JsonnetVersion: s.jsonnetVersion,
KubectlVersion: vers.KubectlVersion,
}, nil
}
// AuthFuncOverride allows the version to be returned without auth
func (s *server) AuthFuncOverride(ctx context.Context, fullMethodName string) (context.Context, error) {
if s.authenticator != nil {
// this authenticates the user, but ignores any error, so that we have claims populated
ctx, _ = s.authenticator.Authenticate(ctx)
}
return ctx, nil
}