Skip to content

Commit

Permalink
server: include license expiration time and time into uiconfig endp…
Browse files Browse the repository at this point in the history
…oint response

This change extends response for `uiconfig` endpoint which now contains information
about license type and time until license expires.

Release note: None
  • Loading branch information
koorosh committed Mar 14, 2024
1 parent 8da64fe commit 9ea2850
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
3 changes: 2 additions & 1 deletion pkg/server/server_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions pkg/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
1 change: 1 addition & 0 deletions pkg/ui/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ go_library(
"//pkg/build",
"//pkg/server/serverpb",
"//pkg/settings",
"//pkg/settings/cluster",
"//pkg/util/httputil",
"//pkg/util/log",
],
Expand Down
13 changes: 13 additions & 0 deletions pkg/ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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$")
Expand Down Expand Up @@ -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,
Expand All @@ -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()
Expand Down

0 comments on commit 9ea2850

Please sign in to comment.