| 56 | var ErrLicenseRequiresTelemetry = xerrors.New(codersdk.LicenseTelemetryRequiredErrorText) |
| 57 | |
| 58 | func (l *Set) Update(ctx context.Context, fetch func(context.Context) (codersdk.Entitlements, error)) error { |
| 59 | select { |
| 60 | case <-ctx.Done(): |
| 61 | return ctx.Err() |
| 62 | case <-l.right2Update: |
| 63 | defer func() { |
| 64 | l.right2Update <- struct{}{} |
| 65 | }() |
| 66 | } |
| 67 | ents, err := fetch(ctx) |
| 68 | if xerrors.Is(err, ErrLicenseRequiresTelemetry) { |
| 69 | // We can't fail because then the user couldn't remove the offending |
| 70 | // license w/o a restart. |
| 71 | // |
| 72 | // We don't simply append to entitlement.Errors since we don't want any |
| 73 | // enterprise features enabled. |
| 74 | l.Modify(func(entitlements *codersdk.Entitlements) { |
| 75 | entitlements.Errors = []string{err.Error()} |
| 76 | }) |
| 77 | return nil |
| 78 | } |
| 79 | if err != nil { |
| 80 | return err |
| 81 | } |
| 82 | l.entitlementsMu.Lock() |
| 83 | defer l.entitlementsMu.Unlock() |
| 84 | l.entitlements = ents |
| 85 | return nil |
| 86 | } |
| 87 | |
| 88 | // AllowRefresh returns whether the entitlements are allowed to be refreshed. |
| 89 | // If it returns false, that means it was recently refreshed and the caller should |