diff --git a/pkg/server/server_http.go b/pkg/server/server_http.go index b1bd3dcb3486..280c12d2b0c8 100644 --- a/pkg/server/server_http.go +++ b/pkg/server/server_http.go @@ -178,7 +178,8 @@ func (s *httpServer) setupRoutes( } return nil }, - Flags: flags, + Flags: flags, + Settings: s.cfg.Settings, }) // The authentication mux used here is created in "allow anonymous" mode so that the UI diff --git a/pkg/server/server_test.go b/pkg/server/server_test.go index a7d7bb5e82f4..48c3b7784ad3 100644 --- a/pkg/server/server_test.go +++ b/pkg/server/server_test.go @@ -757,7 +757,7 @@ Binary built without web UI. respBytes, err = io.ReadAll(resp.Body) require.NoError(t, err) expected := fmt.Sprintf( - `{"Insecure":true,"LoggedInUser":null,"Tag":"%s","Version":"%s","NodeID":"%d","OIDCAutoLogin":false,"OIDCLoginEnabled":false,"OIDCButtonText":"","FeatureFlags":{"can_view_kv_metric_dashboards":true},"OIDCGenerateJWTAuthTokenEnabled":false}`, + `{"Insecure":true,"LoggedInUser":null,"Tag":"%s","Version":"%s","NodeID":"%d","OIDCAutoLogin":false,"OIDCLoginEnabled":false,"OIDCButtonText":"","FeatureFlags":{"can_view_kv_metric_dashboards":true},"OIDCGenerateJWTAuthTokenEnabled":false,"LicenseType":"OSS","SecondsUntilLicenseExpiry":0}`, build.GetInfo().Tag, build.BinaryVersionPrefix(), 1, @@ -785,7 +785,7 @@ Binary built without web UI. { loggedInClient, fmt.Sprintf( - `{"Insecure":false,"LoggedInUser":"authentic_user","Tag":"%s","Version":"%s","NodeID":"%d","OIDCAutoLogin":false,"OIDCLoginEnabled":false,"OIDCButtonText":"","FeatureFlags":{"can_view_kv_metric_dashboards":true},"OIDCGenerateJWTAuthTokenEnabled":false}`, + `{"Insecure":false,"LoggedInUser":"authentic_user","Tag":"%s","Version":"%s","NodeID":"%d","OIDCAutoLogin":false,"OIDCLoginEnabled":false,"OIDCButtonText":"","FeatureFlags":{"can_view_kv_metric_dashboards":true},"OIDCGenerateJWTAuthTokenEnabled":false,"LicenseType":"OSS","SecondsUntilLicenseExpiry":0}`, build.GetInfo().Tag, build.BinaryVersionPrefix(), 1, @@ -794,7 +794,7 @@ Binary built without web UI. { loggedOutClient, fmt.Sprintf( - `{"Insecure":false,"LoggedInUser":null,"Tag":"%s","Version":"%s","NodeID":"%d","OIDCAutoLogin":false,"OIDCLoginEnabled":false,"OIDCButtonText":"","FeatureFlags":{"can_view_kv_metric_dashboards":true},"OIDCGenerateJWTAuthTokenEnabled":false}`, + `{"Insecure":false,"LoggedInUser":null,"Tag":"%s","Version":"%s","NodeID":"%d","OIDCAutoLogin":false,"OIDCLoginEnabled":false,"OIDCButtonText":"","FeatureFlags":{"can_view_kv_metric_dashboards":true},"OIDCGenerateJWTAuthTokenEnabled":false,"LicenseType":"OSS","SecondsUntilLicenseExpiry":0}`, build.GetInfo().Tag, build.BinaryVersionPrefix(), 1, diff --git a/pkg/ui/BUILD.bazel b/pkg/ui/BUILD.bazel index 62a55aba3192..19ef0140fbee 100644 --- a/pkg/ui/BUILD.bazel +++ b/pkg/ui/BUILD.bazel @@ -20,6 +20,7 @@ go_library( "//pkg/build", "//pkg/server/serverpb", "//pkg/settings", + "//pkg/settings/cluster", "//pkg/util/httputil", "//pkg/util/log", ], diff --git a/pkg/ui/ui.go b/pkg/ui/ui.go index f579a4dbb310..23e0871069ef 100644 --- a/pkg/ui/ui.go +++ b/pkg/ui/ui.go @@ -29,6 +29,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/build" "github.com/cockroachdb/cockroach/pkg/server/serverpb" "github.com/cockroachdb/cockroach/pkg/settings" + "github.com/cockroachdb/cockroach/pkg/settings/cluster" "github.com/cockroachdb/cockroach/pkg/util/httputil" "github.com/cockroachdb/cockroach/pkg/util/log" ) @@ -92,6 +93,9 @@ type indexHTMLArgs struct { FeatureFlags serverpb.FeatureFlags OIDCGenerateJWTAuthTokenEnabled bool + + LicenseType string + SecondsUntilLicenseExpiry int64 } // OIDCUIConf is a variable that stores data required by the @@ -129,6 +133,7 @@ type Config struct { GetUser func(ctx context.Context) *string OIDC OIDCUI Flags serverpb.FeatureFlags + Settings *cluster.Settings } var uiConfigPath = regexp.MustCompile("^/uiconfig$") @@ -158,6 +163,11 @@ func Handler(cfg Config) http.Handler { buildInfo := build.GetInfo() return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + licenseType, err := base.LicenseType(cfg.Settings) + if err != nil { + log.Errorf(context.Background(), "unable to get license type: %+v", err) + } + licenseTTL := base.LicenseTTL.Value() oidcConf := cfg.OIDC.GetOIDCConf() args := indexHTMLArgs{ Insecure: cfg.Insecure, @@ -170,6 +180,9 @@ func Handler(cfg Config) http.Handler { FeatureFlags: cfg.Flags, OIDCGenerateJWTAuthTokenEnabled: oidcConf.GenerateJWTAuthTokenEnabled, + + LicenseType: licenseType, + SecondsUntilLicenseExpiry: licenseTTL, } if cfg.NodeID != nil { args.NodeID = cfg.NodeID.String()