github.com/argoproj/argo-cd/v3@v3.2.1/server/version/version.go (about) 1 package version 2 3 import ( 4 "context" 5 6 "github.com/golang/protobuf/ptypes/empty" 7 "github.com/google/go-jsonnet" 8 9 "github.com/argoproj/argo-cd/v3/common" 10 "github.com/argoproj/argo-cd/v3/pkg/apiclient/version" 11 "github.com/argoproj/argo-cd/v3/server/settings" 12 "github.com/argoproj/argo-cd/v3/util/helm" 13 "github.com/argoproj/argo-cd/v3/util/kustomize" 14 sessionmgr "github.com/argoproj/argo-cd/v3/util/session" 15 ) 16 17 type Server struct { 18 kustomizeVersion string 19 helmVersion string 20 jsonnetVersion string 21 authenticator settings.Authenticator 22 disableAuth func() (bool, error) 23 } 24 25 func NewServer(authenticator settings.Authenticator, disableAuth func() (bool, error)) *Server { 26 return &Server{authenticator: authenticator, disableAuth: disableAuth} 27 } 28 29 // Version returns the version of the API server 30 func (s *Server) Version(ctx context.Context, _ *empty.Empty) (*version.VersionMessage, error) { 31 vers := common.GetVersion() 32 disableAuth, err := s.disableAuth() 33 if err != nil { 34 return nil, err 35 } 36 37 if !sessionmgr.LoggedIn(ctx) && !disableAuth { 38 return &version.VersionMessage{Version: vers.Version}, nil 39 } 40 41 if s.kustomizeVersion == "" { 42 kustomizeVersion, err := kustomize.Version() 43 if err == nil { 44 s.kustomizeVersion = kustomizeVersion 45 } else { 46 s.kustomizeVersion = err.Error() 47 } 48 } 49 if s.helmVersion == "" { 50 helmVersion, err := helm.Version() 51 if err == nil { 52 s.helmVersion = helmVersion 53 } else { 54 s.helmVersion = err.Error() 55 } 56 } 57 s.jsonnetVersion = jsonnet.Version() 58 return &version.VersionMessage{ 59 Version: vers.Version, 60 BuildDate: vers.BuildDate, 61 GitCommit: vers.GitCommit, 62 GitTag: vers.GitTag, 63 GitTreeState: vers.GitTreeState, 64 GoVersion: vers.GoVersion, 65 Compiler: vers.Compiler, 66 Platform: vers.Platform, 67 KustomizeVersion: s.kustomizeVersion, 68 HelmVersion: s.helmVersion, 69 JsonnetVersion: s.jsonnetVersion, 70 KubectlVersion: vers.KubectlVersion, 71 ExtraBuildInfo: vers.ExtraBuildInfo, 72 }, nil 73 } 74 75 // AuthFuncOverride allows the version to be returned without auth 76 func (s *Server) AuthFuncOverride(ctx context.Context, _ string) (context.Context, error) { 77 if s.authenticator != nil { 78 // this authenticates the user, but ignores any error, so that we have claims populated 79 ctx, _ = s.authenticator.Authenticate(ctx) 80 } 81 return ctx, nil 82 }