@@ -78,6 +78,7 @@ func New(ctx context.Context, options *Options) (*API, error) {
78
78
type Options struct {
79
79
* coderd.Options
80
80
81
+ AuditLogging bool
81
82
EntitlementsUpdateInterval time.Duration
82
83
Keys map [string ]ed25519.PublicKey
83
84
}
@@ -125,7 +126,14 @@ func (api *API) updateEntitlements(ctx context.Context) error {
125
126
api .mutex .Lock ()
126
127
defer api .mutex .Unlock ()
127
128
now := time .Now ()
128
- auditLogs := api .auditLogs
129
+
130
+ // Default all entitlements to be disabled.
131
+ activeUsers := codersdk.Feature {
132
+ Enabled : false ,
133
+ Entitlement : codersdk .EntitlementNotEntitled ,
134
+ }
135
+ auditLogs := codersdk .EntitlementNotEntitled
136
+
129
137
for _ , l := range licenses {
130
138
claims , err := validateDBLicense (l , api .Keys )
131
139
if err != nil {
@@ -141,24 +149,25 @@ func (api *API) updateEntitlements(ctx context.Context) error {
141
149
entitlement = codersdk .EntitlementGracePeriod
142
150
}
143
151
if claims .Features .UserLimit > 0 {
144
- api . activeUsers .Enabled = true
145
- api . activeUsers .Entitlement = entitlement
152
+ activeUsers .Enabled = true
153
+ activeUsers .Entitlement = entitlement
146
154
currentLimit := int64 (0 )
147
- if api . activeUsers .Limit != nil {
148
- currentLimit = * api . activeUsers .Limit
155
+ if activeUsers .Limit != nil {
156
+ currentLimit = * activeUsers .Limit
149
157
}
150
158
limit := max (currentLimit , claims .Features .UserLimit )
151
- api . activeUsers .Limit = & limit
159
+ activeUsers .Limit = & limit
152
160
}
153
161
if claims .Features .AuditLog > 0 {
154
- api . auditLogs = entitlement
162
+ auditLogs = entitlement
155
163
}
156
164
}
165
+
157
166
if auditLogs != api .auditLogs {
158
167
auditor := agplaudit .NewNop ()
159
168
// A flag could be added to the options that would allow disabling
160
169
// enhanced audit logging here!
161
- if api .auditLogs == codersdk .EntitlementEntitled {
170
+ if api .auditLogs == codersdk .EntitlementEntitled && api . AuditLogging {
162
171
auditor = audit .NewAuditor (
163
172
audit .DefaultFilter ,
164
173
backends .NewPostgres (api .Database , true ),
@@ -167,6 +176,10 @@ func (api *API) updateEntitlements(ctx context.Context) error {
167
176
}
168
177
api .AGPL .Auditor .Store (auditor )
169
178
}
179
+
180
+ api .activeUsers = activeUsers
181
+ api .auditLogs = auditLogs
182
+
170
183
return nil
171
184
}
172
185
@@ -205,9 +218,9 @@ func (api *API) entitlements(rw http.ResponseWriter, r *http.Request) {
205
218
// Audit logs
206
219
resp .Features [codersdk .FeatureAuditLog ] = codersdk.Feature {
207
220
Entitlement : auditLogs ,
208
- Enabled : true ,
221
+ Enabled : api . AuditLogging ,
209
222
}
210
- if auditLogs == codersdk .EntitlementGracePeriod {
223
+ if auditLogs == codersdk .EntitlementGracePeriod && api . AuditLogging {
211
224
resp .Warnings = append (resp .Warnings ,
212
225
"Audit logging is enabled but your license for this feature is expired." )
213
226
}
0 commit comments