mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix: ensure the web UI doesn't break when license telemetry required check fails (#16667)
Addresses https://github.com/coder/coder/issues/16455. ## Changes - Initialize default entitlements in a Set to include all features - Initialize entitlements' `Warnings` and `Errors` fields to arrays rather than `nil`s. - Minor changes in formatting on the frontend ## Reasoning I had to change how entitlements are initialized to match the `codersdk` [generated types](https://github.com/coder/coder/blob/33d62619225702257fa2542f40ecc26bfd0d1fa6/site/src/api/typesGenerated.ts#L727), which the frontend assumes are correct, and doesn't run additional checks on. - `features: Record<FeatureName, Feature>`: this type signifies that every `FeatureName` is present in the record, but on `main`, that's not true if there's a telemetry required error - `warnings: readonly string[];` and `errors: readonly string[];`: these types mean that the fields are not `null`, but that's not always true With a valid license, the [`LicensesEntitlements` function](https://github.com/coder/coder/blob/33d62619225702257fa2542f40ecc26bfd0d1fa6/enterprise/coderd/license/license.go#L92) ensures that all features are present in the entitlements. It's called by the [`Entitlements` function](https://github.com/coder/coder/blob/33d62619225702257fa2542f40ecc26bfd0d1fa6/enterprise/coderd/license/license.go#L42), which is called by [`api.updateEnittlements`](https://github.com/coder/coder/blob/33d62619225702257fa2542f40ecc26bfd0d1fa6/enterprise/coderd/coderd.go#L687). However, when a license requires telemetry and telemetry is disabled, the entitlements with all features [are discarded](https://github.com/coder/coder/blob/33d62619225702257fa2542f40ecc26bfd0d1fa6/enterprise/coderd/coderd.go#L704) in an early exit from the same function. By initializing entitlements with all the features from the get go, we avoid this problem. ## License issue banner after the changes <img width="1512" alt="Screenshot 2025-02-23 at 20 25 42" src="https://github.com/user-attachments/assets/ee0134b3-f745-45d9-8333-bfa1661e33d2" />
This commit is contained in:
@@ -30,8 +30,8 @@ func New() *Set {
|
||||
// These will be updated when coderd is initialized.
|
||||
entitlements: codersdk.Entitlements{
|
||||
Features: map[codersdk.FeatureName]codersdk.Feature{},
|
||||
Warnings: nil,
|
||||
Errors: nil,
|
||||
Warnings: []string{},
|
||||
Errors: []string{},
|
||||
HasLicense: false,
|
||||
Trial: false,
|
||||
RequireTelemetry: false,
|
||||
@@ -39,13 +39,21 @@ func New() *Set {
|
||||
},
|
||||
right2Update: make(chan struct{}, 1),
|
||||
}
|
||||
// Ensure all features are present in the entitlements. Our frontend
|
||||
// expects this.
|
||||
for _, featureName := range codersdk.FeatureNames {
|
||||
s.entitlements.AddFeature(featureName, codersdk.Feature{
|
||||
Entitlement: codersdk.EntitlementNotEntitled,
|
||||
Enabled: false,
|
||||
})
|
||||
}
|
||||
s.right2Update <- struct{}{} // one token, serialized updates
|
||||
return s
|
||||
}
|
||||
|
||||
// ErrLicenseRequiresTelemetry is an error returned by a fetch passed to Update to indicate that the
|
||||
// fetched license cannot be used because it requires telemetry.
|
||||
var ErrLicenseRequiresTelemetry = xerrors.New("License requires telemetry but telemetry is disabled")
|
||||
var ErrLicenseRequiresTelemetry = xerrors.New(codersdk.LicenseTelemetryRequiredErrorText)
|
||||
|
||||
func (l *Set) Update(ctx context.Context, fetch func(context.Context) (codersdk.Entitlements, error)) error {
|
||||
select {
|
||||
|
||||
Reference in New Issue
Block a user