Skip to content

chore: add comment that explains require_telemetry behavior #6211

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 7 commits into from
Feb 15, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
feat: support licenses that require telemetry
  • Loading branch information
ammario committed Feb 13, 2023
commit b6e4c51c4fb5d9d25feac4ed65c4dc167fb14148
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
6 changes: 6 additions & 0 deletions enterprise/coderd/coderd.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"crypto/ed25519"
"crypto/tls"
"crypto/x509"
"fmt"
"net/http"
"sync"
"time"
Expand Down Expand Up @@ -252,6 +253,11 @@ func (api *API) updateEntitlements(ctx context.Context) error {
if err != nil {
return err
}

if entitlements.RequireTelemetry && !api.DeploymentConfig.Telemetry.Enable.Value {
return xerrors.New("telemetry disabled, but a license requires telemetry")
}

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