@@ -67,67 +67,31 @@ func Entitlements(
67
67
// LicenseExpires we must be in grace period.
68
68
entitlement = codersdk .EntitlementGracePeriod
69
69
}
70
- if claims .Features .UserLimit > 0 {
71
- limit := claims .Features .UserLimit
72
- priorLimit := entitlements .Features [codersdk .FeatureUserLimit ]
73
- if priorLimit .Limit != nil && * priorLimit .Limit > limit {
74
- limit = * priorLimit .Limit
75
- }
76
- entitlements .Features [codersdk .FeatureUserLimit ] = codersdk.Feature {
77
- Enabled : true ,
78
- Entitlement : entitlement ,
79
- Limit : & limit ,
80
- Actual : & activeUserCount ,
81
- }
82
- }
83
- if claims .Features .AuditLog > 0 {
84
- entitlements .Features [codersdk .FeatureAuditLog ] = codersdk.Feature {
85
- Entitlement : entitlement ,
86
- Enabled : enablements [codersdk .FeatureAuditLog ],
87
- }
88
- }
89
- if claims .Features .BrowserOnly > 0 {
90
- entitlements .Features [codersdk .FeatureBrowserOnly ] = codersdk.Feature {
91
- Entitlement : entitlement ,
92
- Enabled : enablements [codersdk .FeatureBrowserOnly ],
93
- }
94
- }
95
- if claims .Features .SCIM > 0 {
96
- entitlements .Features [codersdk .FeatureSCIM ] = codersdk.Feature {
97
- Entitlement : entitlement ,
98
- Enabled : enablements [codersdk .FeatureSCIM ],
99
- }
100
- }
101
- if claims .Features .HighAvailability > 0 {
102
- entitlements .Features [codersdk .FeatureHighAvailability ] = codersdk.Feature {
103
- Entitlement : entitlement ,
104
- Enabled : enablements [codersdk .FeatureHighAvailability ],
105
- }
106
- }
107
- if claims .Features .TemplateRBAC > 0 {
108
- entitlements .Features [codersdk .FeatureTemplateRBAC ] = codersdk.Feature {
109
- Entitlement : entitlement ,
110
- Enabled : enablements [codersdk .FeatureTemplateRBAC ],
111
- }
112
- }
113
- if claims .Features .MultipleGitAuth > 0 {
114
- entitlements .Features [codersdk .FeatureMultipleGitAuth ] = codersdk.Feature {
115
- Entitlement : entitlement ,
116
- Enabled : true ,
117
- }
118
- }
119
- if claims .Features .ExternalProvisionerDaemons > 0 {
120
- entitlements .Features [codersdk .FeatureExternalProvisionerDaemons ] = codersdk.Feature {
121
- Entitlement : entitlement ,
122
- Enabled : true ,
123
- }
124
- }
125
- if claims .Features .Appearance > 0 {
126
- entitlements .Features [codersdk .FeatureAppearance ] = codersdk.Feature {
127
- Entitlement : entitlement ,
128
- Enabled : true ,
70
+ for featureName , featureValue := range claims .Features {
71
+ switch featureName {
72
+ // User limit has special treatment as our only non-boolean feature.
73
+ case codersdk .FeatureUserLimit :
74
+ limit := featureValue
75
+ priorLimit := entitlements .Features [codersdk .FeatureUserLimit ]
76
+ if priorLimit .Limit != nil && * priorLimit .Limit > limit {
77
+ limit = * priorLimit .Limit
78
+ }
79
+ entitlements .Features [codersdk .FeatureUserLimit ] = codersdk.Feature {
80
+ Enabled : true ,
81
+ Entitlement : entitlement ,
82
+ Limit : & limit ,
83
+ Actual : & activeUserCount ,
84
+ }
85
+ default :
86
+ if featureValue > 0 {
87
+ entitlements .Features [featureName ] = codersdk.Feature {
88
+ Entitlement : entitlement ,
89
+ Enabled : enablements [featureName ] || featureName .AlwaysEnable (),
90
+ }
91
+ }
129
92
}
130
93
}
94
+
131
95
if claims .AllFeatures {
132
96
allFeatures = true
133
97
}
@@ -248,17 +212,7 @@ var (
248
212
ErrMissingLicenseExpires = xerrors .New ("license missing license_expires" )
249
213
)
250
214
251
- type Features struct {
252
- UserLimit int64 `json:"user_limit"`
253
- AuditLog int64 `json:"audit_log"`
254
- BrowserOnly int64 `json:"browser_only"`
255
- SCIM int64 `json:"scim"`
256
- TemplateRBAC int64 `json:"template_rbac"`
257
- HighAvailability int64 `json:"high_availability"`
258
- MultipleGitAuth int64 `json:"multiple_git_auth"`
259
- ExternalProvisionerDaemons int64 `json:"external_provisioner_daemons"`
260
- Appearance int64 `json:"appearance"`
261
- }
215
+ type Features map [codersdk.FeatureName ]int64
262
216
263
217
type Claims struct {
264
218
jwt.RegisteredClaims
0 commit comments