@@ -75,6 +75,9 @@ func New(ctx context.Context, options *Options) (_ *API, err error) {
75
75
// from when an additional replica was started.
76
76
options .ReplicaErrorGracePeriod = time .Minute
77
77
}
78
+ if options .Entitlements == nil {
79
+ options .Entitlements = entitlements .New ()
80
+ }
78
81
79
82
ctx , cancelFunc := context .WithCancel (ctx )
80
83
@@ -105,25 +108,22 @@ func New(ctx context.Context, options *Options) (_ *API, err error) {
105
108
return nil , xerrors .Errorf ("init database encryption: %w" , err )
106
109
}
107
110
108
- entitlementsSet := entitlements .New ()
109
111
options .Database = cryptDB
110
112
api := & API {
111
- ctx : ctx ,
112
- cancel : cancelFunc ,
113
- Options : options ,
114
- entitlements : entitlementsSet ,
113
+ ctx : ctx ,
114
+ cancel : cancelFunc ,
115
+ Options : options ,
115
116
provisionerDaemonAuth : & provisionerDaemonAuth {
116
117
psk : options .ProvisionerDaemonPSK ,
117
118
authorizer : options .Authorizer ,
118
119
db : options .Database ,
119
120
},
120
121
licenseMetricsCollector : & license.MetricsCollector {
121
- Entitlements : entitlementsSet ,
122
+ Entitlements : options . Entitlements ,
122
123
},
123
124
}
124
125
// This must happen before coderd initialization!
125
126
options .PostAuthAdditionalHeadersFunc = api .writeEntitlementWarningsHeader
126
- options .Options .Entitlements = api .entitlements
127
127
api .AGPL = coderd .New (options .Options )
128
128
defer func () {
129
129
if err != nil {
@@ -561,8 +561,6 @@ type API struct {
561
561
// ProxyHealth checks the reachability of all workspace proxies.
562
562
ProxyHealth * proxyhealth.ProxyHealth
563
563
564
- entitlements * entitlements.Set
565
-
566
564
provisionerDaemonAuth * provisionerDaemonAuth
567
565
568
566
licenseMetricsCollector * license.MetricsCollector
@@ -595,7 +593,7 @@ func (api *API) writeEntitlementWarningsHeader(a rbac.Subject, header http.Heade
595
593
return
596
594
}
597
595
598
- api .entitlements .WriteEntitlementWarningHeaders (header )
596
+ api .Entitlements .WriteEntitlementWarningHeaders (header )
599
597
}
600
598
601
599
func (api * API ) Close () error {
@@ -658,7 +656,7 @@ func (api *API) updateEntitlements(ctx context.Context) error {
658
656
//
659
657
// We don't simply append to entitlement.Errors since we don't want any
660
658
// enterprise features enabled.
661
- api .entitlements .Update (func (entitlements * codersdk.Entitlements ) {
659
+ api .Entitlements .Update (func (entitlements * codersdk.Entitlements ) {
662
660
entitlements .Errors = []string {
663
661
"License requires telemetry but telemetry is disabled" ,
664
662
}
@@ -669,7 +667,7 @@ func (api *API) updateEntitlements(ctx context.Context) error {
669
667
}
670
668
671
669
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 ])
673
671
}
674
672
675
673
shouldUpdate := func (initial , changed , enabled bool ) bool {
@@ -835,7 +833,7 @@ func (api *API) updateEntitlements(ctx context.Context) error {
835
833
}
836
834
reloadedEntitlements .Features [codersdk .FeatureExternalTokenEncryption ] = featureExternalTokenEncryption
837
835
838
- api .entitlements .Replace (reloadedEntitlements )
836
+ api .Entitlements .Replace (reloadedEntitlements )
839
837
return nil
840
838
}
841
839
@@ -1015,7 +1013,7 @@ func derpMapper(logger slog.Logger, proxyHealth *proxyhealth.ProxyHealth) func(*
1015
1013
// @Router /entitlements [get]
1016
1014
func (api * API ) serveEntitlements (rw http.ResponseWriter , r * http.Request ) {
1017
1015
ctx := r .Context ()
1018
- httpapi .Write (ctx , rw , http .StatusOK , api .entitlements .AsJSON ())
1016
+ httpapi .Write (ctx , rw , http .StatusOK , api .Entitlements .AsJSON ())
1019
1017
}
1020
1018
1021
1019
func (api * API ) runEntitlementsLoop (ctx context.Context ) {
0 commit comments