Skip to content

Commit 76db339

Browse files
committed
options
1 parent 347c834 commit 76db339

File tree

3 files changed

+19
-19
lines changed

3 files changed

+19
-19
lines changed

enterprise/cli/server.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@ func server() *cobra.Command {
2121
userWorkspaceQuota int
2222
)
2323
cmd := agpl.Server(func(ctx context.Context, options *agplcoderd.Options) (*agplcoderd.API, error) {
24+
coderd.NewEnforcer(userWorkspaceQuota)
25+
2426
api, err := coderd.New(ctx, &coderd.Options{
25-
AuditLogging: auditLogging,
26-
BrowserOnly: browserOnly,
27-
SCIMAPIKey: []byte(scimAuthHeader),
28-
WorkspaceQuota: userWorkspaceQuota,
29-
Options: options,
27+
AuditLogging: auditLogging,
28+
BrowserOnly: browserOnly,
29+
SCIMAPIKey: []byte(scimAuthHeader),
30+
UserWorkspaceQuota: userWorkspaceQuota,
31+
Options: options,
3032
})
3133
if err != nil {
3234
return nil, err

enterprise/coderd/coderd.go

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@ import (
1515

1616
"cdr.dev/slog"
1717
"github.com/coder/coder/coderd"
18-
agplaudit "github.com/coder/coder/coderd/audit"
1918
"github.com/coder/coder/coderd/httpapi"
2019
"github.com/coder/coder/coderd/httpmw"
21-
"github.com/coder/coder/coderd/workspacequota"
2220
"github.com/coder/coder/codersdk"
2321
"github.com/coder/coder/enterprise/audit"
2422
"github.com/coder/coder/enterprise/audit/backends"
@@ -98,9 +96,9 @@ type Options struct {
9896

9997
AuditLogging bool
10098
// Whether to block non-browser connections.
101-
BrowserOnly bool
102-
SCIMAPIKey []byte
103-
WorkspaceQuota int
99+
BrowserOnly bool
100+
SCIMAPIKey []byte
101+
UserWorkspaceQuota int
104102

105103
EntitlementsUpdateInterval time.Duration
106104
Keys map[string]ed25519.PublicKey
@@ -193,17 +191,16 @@ func (api *API) updateEntitlements(ctx context.Context) error {
193191
}
194192

195193
if entitlements.auditLogs != api.entitlements.auditLogs {
196-
auditor := agplaudit.NewNop()
197194
// A flag could be added to the options that would allow disabling
198195
// enhanced audit logging here!
199196
if entitlements.auditLogs != codersdk.EntitlementNotEntitled && api.AuditLogging {
200-
auditor = audit.NewAuditor(
197+
auditor := audit.NewAuditor(
201198
audit.DefaultFilter,
202199
backends.NewPostgres(api.Database, true),
203200
backends.NewSlog(api.Logger),
204201
)
202+
api.AGPL.Auditor.Store(&auditor)
205203
}
206-
api.AGPL.Auditor.Store(&auditor)
207204
}
208205

209206
if entitlements.browserOnly != api.entitlements.browserOnly {
@@ -215,11 +212,10 @@ func (api *API) updateEntitlements(ctx context.Context) error {
215212
}
216213

217214
if entitlements.workspaceQuota != api.entitlements.workspaceQuota {
218-
var enforcer workspacequota.Enforcer
219-
if entitlements.workspaceQuota != codersdk.EntitlementNotEntitled && api.WorkspaceQuota > 0 {
220-
enforcer = NewEnforcer(api.WorkspaceQuota)
215+
if entitlements.workspaceQuota != codersdk.EntitlementNotEntitled && api.Options.UserWorkspaceQuota > 0 {
216+
enforcer := NewEnforcer(api.Options.UserWorkspaceQuota)
217+
api.AGPL.WorkspaceQuotaEnforcer.Store(&enforcer)
221218
}
222-
api.AGPL.WorkspaceQuotaEnforcer.Store(&enforcer)
223219
}
224220

225221
api.entitlements = entitlements
@@ -279,9 +275,9 @@ func (api *API) serveEntitlements(rw http.ResponseWriter, r *http.Request) {
279275

280276
resp.Features[codersdk.FeatureWorkspaceQuota] = codersdk.Feature{
281277
Entitlement: entitlements.workspaceQuota,
282-
Enabled: api.WorkspaceQuota > 0,
278+
Enabled: api.UserWorkspaceQuota > 0,
283279
}
284-
if entitlements.workspaceQuota == codersdk.EntitlementGracePeriod && api.WorkspaceQuota > 0 {
280+
if entitlements.workspaceQuota == codersdk.EntitlementGracePeriod && api.UserWorkspaceQuota > 0 {
285281
resp.Warnings = append(resp.Warnings,
286282
"Workspace quotas are enabled but your license for this feature is expired.")
287283
}

enterprise/coderd/coderdenttest/coderdenttest.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ type Options struct {
3939
BrowserOnly bool
4040
EntitlementsUpdateInterval time.Duration
4141
SCIMAPIKey []byte
42+
UserWorkspaceQuota int
4243
}
4344

4445
// New constructs a codersdk client connected to an in-memory Enterprise API instance.
@@ -59,6 +60,7 @@ func NewWithAPI(t *testing.T, options *Options) (*codersdk.Client, io.Closer, *c
5960
AuditLogging: true,
6061
BrowserOnly: options.BrowserOnly,
6162
SCIMAPIKey: options.SCIMAPIKey,
63+
UserWorkspaceQuota: options.UserWorkspaceQuota,
6264
Options: oop,
6365
EntitlementsUpdateInterval: options.EntitlementsUpdateInterval,
6466
Keys: map[string]ed25519.PublicKey{

0 commit comments

Comments
 (0)