@@ -43,9 +43,10 @@ func New(ctx context.Context, options *Options) (*API, error) {
43
43
Entitlement : codersdk .EntitlementNotEntitled ,
44
44
Enabled : false ,
45
45
},
46
- auditLogs : codersdk .EntitlementNotEntitled ,
47
- browserOnly : codersdk .EntitlementNotEntitled ,
48
- scim : codersdk .EntitlementNotEntitled ,
46
+ auditLogs : codersdk .EntitlementNotEntitled ,
47
+ browserOnly : codersdk .EntitlementNotEntitled ,
48
+ scim : codersdk .EntitlementNotEntitled ,
49
+ workspaceQuota : codersdk .EntitlementNotEntitled ,
49
50
},
50
51
cancelEntitlementsLoop : cancelFunc ,
51
52
}
@@ -96,8 +97,10 @@ type Options struct {
96
97
97
98
AuditLogging bool
98
99
// Whether to block non-browser connections.
99
- BrowserOnly bool
100
- SCIMAPIKey []byte
100
+ BrowserOnly bool
101
+ SCIMAPIKey []byte
102
+ WorkspaceQuota int
103
+
101
104
EntitlementsUpdateInterval time.Duration
102
105
Keys map [string ]ed25519.PublicKey
103
106
}
@@ -112,11 +115,12 @@ type API struct {
112
115
}
113
116
114
117
type entitlements struct {
115
- hasLicense bool
116
- activeUsers codersdk.Feature
117
- auditLogs codersdk.Entitlement
118
- browserOnly codersdk.Entitlement
119
- scim codersdk.Entitlement
118
+ hasLicense bool
119
+ activeUsers codersdk.Feature
120
+ auditLogs codersdk.Entitlement
121
+ browserOnly codersdk.Entitlement
122
+ scim codersdk.Entitlement
123
+ workspaceQuota codersdk.Entitlement
120
124
}
121
125
122
126
func (api * API ) Close () error {
@@ -140,9 +144,10 @@ func (api *API) updateEntitlements(ctx context.Context) error {
140
144
Enabled : false ,
141
145
Entitlement : codersdk .EntitlementNotEntitled ,
142
146
},
143
- auditLogs : codersdk .EntitlementNotEntitled ,
144
- scim : codersdk .EntitlementNotEntitled ,
145
- browserOnly : codersdk .EntitlementNotEntitled ,
147
+ auditLogs : codersdk .EntitlementNotEntitled ,
148
+ scim : codersdk .EntitlementNotEntitled ,
149
+ browserOnly : codersdk .EntitlementNotEntitled ,
150
+ workspaceQuota : codersdk .EntitlementNotEntitled ,
146
151
}
147
152
148
153
// Here we loop through licenses to detect enabled features.
@@ -181,6 +186,9 @@ func (api *API) updateEntitlements(ctx context.Context) error {
181
186
if claims .Features .SCIM > 0 {
182
187
entitlements .scim = entitlement
183
188
}
189
+ if claims .Features .WorkspaceQuota > 0 {
190
+ entitlements .workspaceQuota = entitlement
191
+ }
184
192
}
185
193
186
194
if entitlements .auditLogs != api .entitlements .auditLogs {
@@ -205,6 +213,15 @@ func (api *API) updateEntitlements(ctx context.Context) error {
205
213
api .AGPL .WorkspaceClientCoordinateOverride .Store (& handler )
206
214
}
207
215
216
+ // TODO(f0ssel)
217
+ if entitlements .workspaceQuota != api .entitlements .workspaceQuota {
218
+ // var handler func(rw http.ResponseWriter) bool
219
+ if entitlements .workspaceQuota != codersdk .EntitlementNotEntitled && api .WorkspaceQuota > 0 {
220
+ // handler = api.shouldBlockNonBrowserConnections
221
+ }
222
+ // api.AGPL.WorkspaceClientCoordinateOverride.Store(&handler)
223
+ }
224
+
208
225
api .entitlements = entitlements
209
226
210
227
return nil
@@ -260,6 +277,15 @@ func (api *API) serveEntitlements(rw http.ResponseWriter, r *http.Request) {
260
277
"Browser only connections are enabled but your license for this feature is expired." )
261
278
}
262
279
280
+ resp .Features [codersdk .FeatureWorkspaceQuota ] = codersdk.Feature {
281
+ Entitlement : entitlements .workspaceQuota ,
282
+ Enabled : api .WorkspaceQuota > 0 ,
283
+ }
284
+ if entitlements .workspaceQuota == codersdk .EntitlementGracePeriod && api .WorkspaceQuota > 0 {
285
+ resp .Warnings = append (resp .Warnings ,
286
+ "Workspace quotas are enabled but your license for this feature is expired." )
287
+ }
288
+
263
289
httpapi .Write (ctx , rw , http .StatusOK , resp )
264
290
}
265
291
0 commit comments