@@ -75,6 +75,9 @@ func New(ctx context.Context, options *Options) (_ *API, err error) {
7575 // from when an additional replica was started.
7676 options .ReplicaErrorGracePeriod = time .Minute
7777 }
78+ if options .Entitlements == nil {
79+ options .Entitlements = entitlements .New ()
80+ }
7881
7982 ctx , cancelFunc := context .WithCancel (ctx )
8083
@@ -105,25 +108,22 @@ func New(ctx context.Context, options *Options) (_ *API, err error) {
105108 return nil , xerrors .Errorf ("init database encryption: %w" , err )
106109 }
107110
108- entitlementsSet := entitlements .New ()
109111 options .Database = cryptDB
110112 api := & API {
111- ctx : ctx ,
112- cancel : cancelFunc ,
113- Options : options ,
114- entitlements : entitlementsSet ,
113+ ctx : ctx ,
114+ cancel : cancelFunc ,
115+ Options : options ,
115116 provisionerDaemonAuth : & provisionerDaemonAuth {
116117 psk : options .ProvisionerDaemonPSK ,
117118 authorizer : options .Authorizer ,
118119 db : options .Database ,
119120 },
120121 licenseMetricsCollector : & license.MetricsCollector {
121- Entitlements : entitlementsSet ,
122+ Entitlements : options . Entitlements ,
122123 },
123124 }
124125 // This must happen before coderd initialization!
125126 options .PostAuthAdditionalHeadersFunc = api .writeEntitlementWarningsHeader
126- options .Options .Entitlements = api .entitlements
127127 api .AGPL = coderd .New (options .Options )
128128 defer func () {
129129 if err != nil {
@@ -561,8 +561,6 @@ type API struct {
561561 // ProxyHealth checks the reachability of all workspace proxies.
562562 ProxyHealth * proxyhealth.ProxyHealth
563563
564- entitlements * entitlements.Set
565-
566564 provisionerDaemonAuth * provisionerDaemonAuth
567565
568566 licenseMetricsCollector * license.MetricsCollector
@@ -595,7 +593,7 @@ func (api *API) writeEntitlementWarningsHeader(a rbac.Subject, header http.Heade
595593 return
596594 }
597595
598- api .entitlements .WriteEntitlementWarningHeaders (header )
596+ api .Entitlements .WriteEntitlementWarningHeaders (header )
599597}
600598
601599func (api * API ) Close () error {
@@ -658,7 +656,7 @@ func (api *API) updateEntitlements(ctx context.Context) error {
658656 //
659657 // We don't simply append to entitlement.Errors since we don't want any
660658 // enterprise features enabled.
661- api .entitlements .Update (func (entitlements * codersdk.Entitlements ) {
659+ api .Entitlements .Update (func (entitlements * codersdk.Entitlements ) {
662660 entitlements .Errors = []string {
663661 "License requires telemetry but telemetry is disabled" ,
664662 }
@@ -669,7 +667,7 @@ func (api *API) updateEntitlements(ctx context.Context) error {
669667 }
670668
671669 featureChanged := func (featureName codersdk.FeatureName ) (initial , changed , enabled bool ) {
672- return api .entitlements .FeatureChanged (featureName , reloadedEntitlements .Features [featureName ])
670+ return api .Entitlements .FeatureChanged (featureName , reloadedEntitlements .Features [featureName ])
673671 }
674672
675673 shouldUpdate := func (initial , changed , enabled bool ) bool {
@@ -835,7 +833,7 @@ func (api *API) updateEntitlements(ctx context.Context) error {
835833 }
836834 reloadedEntitlements .Features [codersdk .FeatureExternalTokenEncryption ] = featureExternalTokenEncryption
837835
838- api .entitlements .Replace (reloadedEntitlements )
836+ api .Entitlements .Replace (reloadedEntitlements )
839837 return nil
840838}
841839
@@ -1015,7 +1013,7 @@ func derpMapper(logger slog.Logger, proxyHealth *proxyhealth.ProxyHealth) func(*
10151013// @Router /entitlements [get]
10161014func (api * API ) serveEntitlements (rw http.ResponseWriter , r * http.Request ) {
10171015 ctx := r .Context ()
1018- httpapi .Write (ctx , rw , http .StatusOK , api .entitlements .AsJSON ())
1016+ httpapi .Write (ctx , rw , http .StatusOK , api .Entitlements .AsJSON ())
10191017}
10201018
10211019func (api * API ) runEntitlementsLoop (ctx context.Context ) {
0 commit comments