Skip to content

Commit b6e4c51

Browse files
committed
feat: support licenses that require telemetry
1 parent a54de60 commit b6e4c51

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

codersdk/deployment.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,12 @@ type Feature struct {
8181
}
8282

8383
type Entitlements struct {
84-
Features map[FeatureName]Feature `json:"features"`
85-
Warnings []string `json:"warnings"`
86-
Errors []string `json:"errors"`
87-
HasLicense bool `json:"has_license"`
88-
Trial bool `json:"trial"`
84+
Features map[FeatureName]Feature `json:"features"`
85+
Warnings []string `json:"warnings"`
86+
Errors []string `json:"errors"`
87+
HasLicense bool `json:"has_license"`
88+
Trial bool `json:"trial"`
89+
RequireTelemetry bool `json:"require_telemetry"`
8990

9091
// DEPRECATED: use Experiments instead.
9192
Experimental bool `json:"experimental"`

enterprise/coderd/coderd.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"crypto/ed25519"
66
"crypto/tls"
77
"crypto/x509"
8+
"fmt"
89
"net/http"
910
"sync"
1011
"time"
@@ -252,6 +253,11 @@ func (api *API) updateEntitlements(ctx context.Context) error {
252253
if err != nil {
253254
return err
254255
}
256+
257+
if entitlements.RequireTelemetry && !api.DeploymentConfig.Telemetry.Enable.Value {
258+
return xerrors.New("telemetry disabled, but a license requires telemetry")
259+
}
260+
255261
entitlements.Experimental = api.DeploymentConfig.Experimental.Value || len(api.AGPL.Experiments) != 0
256262

257263
featureChanged := func(featureName codersdk.FeatureName) (changed bool, enabled bool) {

enterprise/coderd/license/license.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ func Entitlements(
9898
if claims.AllFeatures {
9999
allFeatures = true
100100
}
101+
entitlements.RequireTelemetry = entitlements.RequireTelemetry || claims.RequireTelemetry
101102
}
102103

103104
if allFeatures {
@@ -224,13 +225,14 @@ type Claims struct {
224225
// the end of the grace period (identical to LicenseExpires if there is no grace period).
225226
// The reason we use the standard claim for the end of the grace period is that we want JWT
226227
// processing libraries to consider the token "valid" until then.
227-
LicenseExpires *jwt.NumericDate `json:"license_expires,omitempty"`
228-
AccountType string `json:"account_type,omitempty"`
229-
AccountID string `json:"account_id,omitempty"`
230-
Trial bool `json:"trial"`
231-
AllFeatures bool `json:"all_features"`
232-
Version uint64 `json:"version"`
233-
Features Features `json:"features"`
228+
LicenseExpires *jwt.NumericDate `json:"license_expires,omitempty"`
229+
AccountType string `json:"account_type,omitempty"`
230+
AccountID string `json:"account_id,omitempty"`
231+
Trial bool `json:"trial"`
232+
AllFeatures bool `json:"all_features"`
233+
Version uint64 `json:"version"`
234+
Features Features `json:"features"`
235+
RequireTelemetry bool `json:"require_telemetry,omitempty"`
234236
}
235237

236238
// ParseRaw consumes a license and returns the claims.

0 commit comments

Comments
 (0)