feat: add support for telemetry-required licenses (#6194)

This commit is contained in:
Ammar Bandukwala
2023-02-14 14:26:47 -06:00
committed by GitHub
parent 15c862fcb5
commit 6e3330a03f
10 changed files with 49 additions and 21 deletions
+3
View File
@@ -6422,6 +6422,9 @@ const docTemplate = `{
"has_license": {
"type": "boolean"
},
"require_telemetry": {
"type": "boolean"
},
"trial": {
"type": "boolean"
},
+3
View File
@@ -5742,6 +5742,9 @@
"has_license": {
"type": "boolean"
},
"require_telemetry": {
"type": "boolean"
},
"trial": {
"type": "boolean"
},
+6 -5
View File
@@ -81,11 +81,12 @@ type Feature struct {
}
type Entitlements struct {
Features map[FeatureName]Feature `json:"features"`
Warnings []string `json:"warnings"`
Errors []string `json:"errors"`
HasLicense bool `json:"has_license"`
Trial bool `json:"trial"`
Features map[FeatureName]Feature `json:"features"`
Warnings []string `json:"warnings"`
Errors []string `json:"errors"`
HasLicense bool `json:"has_license"`
Trial bool `json:"trial"`
RequireTelemetry bool `json:"require_telemetry"`
// DEPRECATED: use Experiments instead.
Experimental bool `json:"experimental"`
+1
View File
@@ -128,6 +128,7 @@ curl -X GET http://coder-server:8080/api/v2/entitlements \
}
},
"has_license": true,
"require_telemetry": true,
"trial": true,
"warnings": ["string"]
}
+11 -9
View File
@@ -2806,6 +2806,7 @@ CreateParameterRequest is a structure used to create a new parameter value for a
}
},
"has_license": true,
"require_telemetry": true,
"trial": true,
"warnings": ["string"]
}
@@ -2813,15 +2814,16 @@ CreateParameterRequest is a structure used to create a new parameter value for a
### Properties
| Name | Type | Required | Restrictions | Description |
| ------------------ | ------------------------------------ | -------- | ------------ | ------------------------------------- |
| `errors` | array of string | false | | |
| `experimental` | boolean | false | | Experimental use Experiments instead. |
| `features` | object | false | | |
| » `[any property]` | [codersdk.Feature](#codersdkfeature) | false | | |
| `has_license` | boolean | false | | |
| `trial` | boolean | false | | |
| `warnings` | array of string | false | | |
| Name | Type | Required | Restrictions | Description |
| ------------------- | ------------------------------------ | -------- | ------------ | ------------------------------------- |
| `errors` | array of string | false | | |
| `experimental` | boolean | false | | Experimental use Experiments instead. |
| `features` | object | false | | |
| » `[any property]` | [codersdk.Feature](#codersdkfeature) | false | | |
| `has_license` | boolean | false | | |
| `require_telemetry` | boolean | false | | |
| `trial` | boolean | false | | |
| `warnings` | array of string | false | | |
## codersdk.Experiment
+11
View File
@@ -254,6 +254,17 @@ func (api *API) updateEntitlements(ctx context.Context) error {
if err != nil {
return err
}
if entitlements.RequireTelemetry && !api.DeploymentConfig.Telemetry.Enable.Value {
// We can't fail because then the user couldn't remove the offending
// license w/o a restart.
api.entitlements.Errors = []string{
"License requires telemetry but telemetry is disabled",
}
api.Logger.Error(ctx, "license requires telemetry enabled")
return nil
}
entitlements.Experimental = api.DeploymentConfig.Experimental.Value || len(api.AGPL.Experiments) != 0
featureChanged := func(featureName codersdk.FeatureName) (changed bool, enabled bool) {
+9 -7
View File
@@ -98,6 +98,7 @@ func Entitlements(
if claims.AllFeatures {
allFeatures = true
}
entitlements.RequireTelemetry = entitlements.RequireTelemetry || claims.RequireTelemetry
}
if allFeatures {
@@ -224,13 +225,14 @@ type Claims struct {
// the end of the grace period (identical to LicenseExpires if there is no grace period).
// The reason we use the standard claim for the end of the grace period is that we want JWT
// processing libraries to consider the token "valid" until then.
LicenseExpires *jwt.NumericDate `json:"license_expires,omitempty"`
AccountType string `json:"account_type,omitempty"`
AccountID string `json:"account_id,omitempty"`
Trial bool `json:"trial"`
AllFeatures bool `json:"all_features"`
Version uint64 `json:"version"`
Features Features `json:"features"`
LicenseExpires *jwt.NumericDate `json:"license_expires,omitempty"`
AccountType string `json:"account_type,omitempty"`
AccountID string `json:"account_id,omitempty"`
Trial bool `json:"trial"`
AllFeatures bool `json:"all_features"`
Version uint64 `json:"version"`
Features Features `json:"features"`
RequireTelemetry bool `json:"require_telemetry,omitempty"`
}
// ParseRaw consumes a license and returns the claims.
+1
View File
@@ -654,6 +654,7 @@ export const getEntitlements = async (): Promise<TypesGen.Entitlements> => {
experimental: false,
features: withDefaultFeatures({}),
has_license: false,
require_telemetry: false,
trial: false,
warnings: [],
}
+1
View File
@@ -359,6 +359,7 @@ export interface Entitlements {
readonly errors: string[]
readonly has_license: boolean
readonly trial: boolean
readonly require_telemetry: boolean
readonly experimental: boolean
}
+3
View File
@@ -1119,6 +1119,7 @@ export const MockEntitlements: TypesGen.Entitlements = {
has_license: false,
features: withDefaultFeatures({}),
experimental: false,
require_telemetry: false,
trial: false,
}
@@ -1128,6 +1129,7 @@ export const MockEntitlementsWithWarnings: TypesGen.Entitlements = {
has_license: true,
experimental: false,
trial: false,
require_telemetry: false,
features: withDefaultFeatures({
user_limit: {
enabled: true,
@@ -1151,6 +1153,7 @@ export const MockEntitlementsWithAuditLog: TypesGen.Entitlements = {
warnings: [],
has_license: true,
experimental: false,
require_telemetry: false,
trial: false,
features: withDefaultFeatures({
audit_log: {