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

Skip to content

feat: add support for telemetry-required licenses #6194

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions coderd/apidoc/docs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions coderd/apidoc/swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions codersdk/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
1 change: 1 addition & 0 deletions docs/api/enterprise.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ curl -X GET http://coder-server:8080/api/v2/entitlements \
}
},
"has_license": true,
"require_telemetry": true,
"trial": true,
"warnings": ["string"]
}
Expand Down
20 changes: 11 additions & 9 deletions docs/api/schemas.md
Original file line number Diff line number Diff line change
Expand Up @@ -2806,22 +2806,24 @@ CreateParameterRequest is a structure used to create a new parameter value for a
}
},
"has_license": true,
"require_telemetry": true,
"trial": true,
"warnings": ["string"]
}
```

### 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

Expand Down
11 changes: 11 additions & 0 deletions enterprise/coderd/coderd.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,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
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kylecarbs — is it safe to return early here to your knowledge?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you return early it doesn't seem like any of the enterprise features would work, if that's your goal. I think it'd probably be better to just append to the entitlements created above instead of overwriting and let the rest of the function run.

entitlements.Experimental = api.DeploymentConfig.Experimental.Value || len(api.AGPL.Experiments) != 0

featureChanged := func(featureName codersdk.FeatureName) (changed bool, enabled bool) {
Expand Down
16 changes: 9 additions & 7 deletions enterprise/coderd/license/license.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ func Entitlements(
if claims.AllFeatures {
allFeatures = true
}
entitlements.RequireTelemetry = entitlements.RequireTelemetry || claims.RequireTelemetry
}

if allFeatures {
Expand Down Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions site/src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,7 @@ export const getEntitlements = async (): Promise<TypesGen.Entitlements> => {
experimental: false,
features: withDefaultFeatures({}),
has_license: false,
require_telemetry: false,
trial: false,
warnings: [],
}
Expand Down
1 change: 1 addition & 0 deletions site/src/api/typesGenerated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ export interface Entitlements {
readonly errors: string[]
readonly has_license: boolean
readonly trial: boolean
readonly require_telemetry: boolean
readonly experimental: boolean
}

Expand Down
3 changes: 3 additions & 0 deletions site/src/testHelpers/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1119,6 +1119,7 @@ export const MockEntitlements: TypesGen.Entitlements = {
has_license: false,
features: withDefaultFeatures({}),
experimental: false,
require_telemetry: false,
trial: false,
}

Expand All @@ -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,
Expand All @@ -1151,6 +1153,7 @@ export const MockEntitlementsWithAuditLog: TypesGen.Entitlements = {
warnings: [],
has_license: true,
experimental: false,
require_telemetry: false,
trial: false,
features: withDefaultFeatures({
audit_log: {
Expand Down