mirror of
https://github.com/coder/coder.git
synced 2026-06-02 20:48:20 +00:00
feat: add support for telemetry-required licenses (#6194)
This commit is contained in:
Generated
+3
@@ -6422,6 +6422,9 @@ const docTemplate = `{
|
||||
"has_license": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"require_telemetry": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"trial": {
|
||||
"type": "boolean"
|
||||
},
|
||||
|
||||
Generated
+3
@@ -5742,6 +5742,9 @@
|
||||
"has_license": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"require_telemetry": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"trial": {
|
||||
"type": "boolean"
|
||||
},
|
||||
|
||||
@@ -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"`
|
||||
|
||||
@@ -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
@@ -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
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -654,6 +654,7 @@ export const getEntitlements = async (): Promise<TypesGen.Entitlements> => {
|
||||
experimental: false,
|
||||
features: withDefaultFeatures({}),
|
||||
has_license: false,
|
||||
require_telemetry: false,
|
||||
trial: false,
|
||||
warnings: [],
|
||||
}
|
||||
|
||||
@@ -359,6 +359,7 @@ export interface Entitlements {
|
||||
readonly errors: string[]
|
||||
readonly has_license: boolean
|
||||
readonly trial: boolean
|
||||
readonly require_telemetry: boolean
|
||||
readonly experimental: boolean
|
||||
}
|
||||
|
||||
|
||||
@@ -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: {
|
||||
|
||||
Reference in New Issue
Block a user