Skip to content

Commit 262bb45

Browse files
committed
fix license woes
1 parent 85d0643 commit 262bb45

File tree

6 files changed

+29
-22
lines changed

6 files changed

+29
-22
lines changed

enterprise/cli/features_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func TestFeaturesList(t *testing.T) {
5757
var entitlements codersdk.Entitlements
5858
err := json.Unmarshal(buf.Bytes(), &entitlements)
5959
require.NoError(t, err, "unmarshal JSON output")
60-
assert.Len(t, entitlements.Features, 5)
60+
assert.Len(t, entitlements.Features, 6)
6161
assert.Empty(t, entitlements.Warnings)
6262
assert.Equal(t, codersdk.EntitlementNotEntitled,
6363
entitlements.Features[codersdk.FeatureUserLimit].Entitlement)

enterprise/coderd/coderd_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@ func TestEntitlements(t *testing.T) {
4141
})
4242
_ = coderdtest.CreateFirstUser(t, client)
4343
coderdenttest.AddLicense(t, client, coderdenttest.LicenseOptions{
44-
UserLimit: 100,
45-
AuditLog: true,
44+
UserLimit: 100,
45+
AuditLog: true,
46+
RBACEnabled: true,
4647
})
4748
res, err := client.Entitlements(context.Background())
4849
require.NoError(t, err)

enterprise/coderd/coderdenttest/coderdenttest.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,9 @@ func GenerateLicense(t *testing.T, options LicenseOptions) string {
135135
workspaceQuota = 1
136136
}
137137

138-
groups := int64(0)
138+
rbac := int64(0)
139139
if options.RBACEnabled {
140-
groups = 1
140+
rbac = 1
141141
}
142142

143143
c := &license.Claims{
@@ -159,7 +159,7 @@ func GenerateLicense(t *testing.T, options LicenseOptions) string {
159159
BrowserOnly: browserOnly,
160160
SCIM: scim,
161161
WorkspaceQuota: workspaceQuota,
162-
RBAC: groups,
162+
RBAC: rbac,
163163
},
164164
}
165165
tok := jwt.NewWithClaims(jwt.SigningMethodEdDSA, c)

enterprise/coderd/license/license.go

+6
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,12 @@ func Entitlements(ctx context.Context, db database.Store, logger slog.Logger, ke
9696
Enabled: enablements[codersdk.FeatureWorkspaceQuota],
9797
}
9898
}
99+
if claims.Features.RBAC > 0 {
100+
entitlements.Features[codersdk.FeatureRBAC] = codersdk.Feature{
101+
Entitlement: entitlement,
102+
Enabled: enablements[codersdk.FeatureRBAC],
103+
}
104+
}
99105
if claims.AllFeatures {
100106
allFeatures = true
101107
}

enterprise/coderd/scim.go

-16
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,6 @@ func (api *API) scimEnabledMW(next http.Handler) http.Handler {
3333
})
3434
}
3535

36-
// TODO reduce the duplication across all of these.
37-
func (api *API) rbacEnabledMW(next http.Handler) http.Handler {
38-
return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
39-
api.entitlementsMu.RLock()
40-
rbac := api.entitlements.rbac
41-
api.entitlementsMu.RUnlock()
42-
43-
if rbac == codersdk.EntitlementNotEntitled {
44-
httpapi.RouteNotFound(rw)
45-
return
46-
}
47-
48-
next.ServeHTTP(rw, r)
49-
})
50-
}
51-
5236
func (api *API) scimVerifyAuthHeader(r *http.Request) bool {
5337
hdr := []byte(r.Header.Get("Authorization"))
5438

enterprise/coderd/templates.go

+16
Original file line numberDiff line numberDiff line change
@@ -244,3 +244,19 @@ func convertSDKTemplateRole(role codersdk.TemplateRole) []rbac.Action {
244244

245245
return nil
246246
}
247+
248+
// TODO reduce the duplication across all of these.
249+
func (api *API) rbacEnabledMW(next http.Handler) http.Handler {
250+
return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
251+
api.entitlementsMu.RLock()
252+
rbac := api.entitlements.Features[codersdk.FeatureRBAC].Enabled
253+
api.entitlementsMu.RUnlock()
254+
255+
if !rbac {
256+
httpapi.RouteNotFound(rw)
257+
return
258+
}
259+
260+
next.ServeHTTP(rw, r)
261+
})
262+
}

0 commit comments

Comments
 (0)