Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6e3330a

Browse files
authored
feat: add support for telemetry-required licenses (coder#6194)
1 parent 15c862f commit 6e3330a

File tree

10 files changed

+49
-21
lines changed

10 files changed

+49
-21
lines changed

coderd/apidoc/docs.go

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/apidoc/swagger.json

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

codersdk/deployment.go

+6-5
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"`

docs/api/enterprise.md

+1
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ curl -X GET http://coder-server:8080/api/v2/entitlements \
128128
}
129129
},
130130
"has_license": true,
131+
"require_telemetry": true,
131132
"trial": true,
132133
"warnings": ["string"]
133134
}

docs/api/schemas.md

+11-9
Original file line numberDiff line numberDiff line change
@@ -2806,22 +2806,24 @@ CreateParameterRequest is a structure used to create a new parameter value for a
28062806
}
28072807
},
28082808
"has_license": true,
2809+
"require_telemetry": true,
28092810
"trial": true,
28102811
"warnings": ["string"]
28112812
}
28122813
```
28132814

28142815
### Properties
28152816

2816-
| Name | Type | Required | Restrictions | Description |
2817-
| ------------------ | ------------------------------------ | -------- | ------------ | ------------------------------------- |
2818-
| `errors` | array of string | false | | |
2819-
| `experimental` | boolean | false | | Experimental use Experiments instead. |
2820-
| `features` | object | false | | |
2821-
| » `[any property]` | [codersdk.Feature](#codersdkfeature) | false | | |
2822-
| `has_license` | boolean | false | | |
2823-
| `trial` | boolean | false | | |
2824-
| `warnings` | array of string | false | | |
2817+
| Name | Type | Required | Restrictions | Description |
2818+
| ------------------- | ------------------------------------ | -------- | ------------ | ------------------------------------- |
2819+
| `errors` | array of string | false | | |
2820+
| `experimental` | boolean | false | | Experimental use Experiments instead. |
2821+
| `features` | object | false | | |
2822+
| » `[any property]` | [codersdk.Feature](#codersdkfeature) | false | | |
2823+
| `has_license` | boolean | false | | |
2824+
| `require_telemetry` | boolean | false | | |
2825+
| `trial` | boolean | false | | |
2826+
| `warnings` | array of string | false | | |
28252827

28262828
## codersdk.Experiment
28272829

enterprise/coderd/coderd.go

+11
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,17 @@ func (api *API) updateEntitlements(ctx context.Context) error {
254254
if err != nil {
255255
return err
256256
}
257+
258+
if entitlements.RequireTelemetry && !api.DeploymentConfig.Telemetry.Enable.Value {
259+
// We can't fail because then the user couldn't remove the offending
260+
// license w/o a restart.
261+
api.entitlements.Errors = []string{
262+
"License requires telemetry but telemetry is disabled",
263+
}
264+
api.Logger.Error(ctx, "license requires telemetry enabled")
265+
return nil
266+
}
267+
257268
entitlements.Experimental = api.DeploymentConfig.Experimental.Value || len(api.AGPL.Experiments) != 0
258269

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

enterprise/coderd/license/license.go

+9-7
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.

site/src/api/api.ts

+1
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,7 @@ export const getEntitlements = async (): Promise<TypesGen.Entitlements> => {
654654
experimental: false,
655655
features: withDefaultFeatures({}),
656656
has_license: false,
657+
require_telemetry: false,
657658
trial: false,
658659
warnings: [],
659660
}

site/src/api/typesGenerated.ts

+1
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ export interface Entitlements {
359359
readonly errors: string[]
360360
readonly has_license: boolean
361361
readonly trial: boolean
362+
readonly require_telemetry: boolean
362363
readonly experimental: boolean
363364
}
364365

site/src/testHelpers/entities.ts

+3
Original file line numberDiff line numberDiff line change
@@ -1119,6 +1119,7 @@ export const MockEntitlements: TypesGen.Entitlements = {
11191119
has_license: false,
11201120
features: withDefaultFeatures({}),
11211121
experimental: false,
1122+
require_telemetry: false,
11221123
trial: false,
11231124
}
11241125

@@ -1128,6 +1129,7 @@ export const MockEntitlementsWithWarnings: TypesGen.Entitlements = {
11281129
has_license: true,
11291130
experimental: false,
11301131
trial: false,
1132+
require_telemetry: false,
11311133
features: withDefaultFeatures({
11321134
user_limit: {
11331135
enabled: true,
@@ -1151,6 +1153,7 @@ export const MockEntitlementsWithAuditLog: TypesGen.Entitlements = {
11511153
warnings: [],
11521154
has_license: true,
11531155
experimental: false,
1156+
require_telemetry: false,
11541157
trial: false,
11551158
features: withDefaultFeatures({
11561159
audit_log: {

0 commit comments

Comments
 (0)