@@ -10,7 +10,7 @@ import { ConnectionConfig } from '@sourcebot/schemas/v3/connection.type';
10
10
import { indexSchema } from '@sourcebot/schemas/v3/index.schema' ;
11
11
import Ajv from 'ajv' ;
12
12
import { syncSearchContexts } from '@/ee/features/searchContexts/syncSearchContexts' ;
13
- import { hasEntitlement } from '@/features/entitlements/server' ;
13
+ import { getEntitlements , hasEntitlement } from '@/features/entitlements/server' ;
14
14
import { createGuestUser , setPublicAccessStatus } from '@/ee/features/publicAccess/publicAccess' ;
15
15
import { isServiceError } from './lib/utils' ;
16
16
import { ServiceErrorException } from './lib/serviceError' ;
@@ -150,6 +150,11 @@ const syncDeclarativeConfig = async (configPath: string) => {
150
150
}
151
151
152
152
if ( hasPublicAccessEntitlement ) {
153
+ if ( enablePublicAccess && env . SOURCEBOT_EE_AUDIT_LOGGING_ENABLED === 'true' ) {
154
+ logger . error ( `Audit logging is not supported when public access is enabled. Please disable audit logging or disable public access.` ) ;
155
+ process . exit ( 1 ) ;
156
+ }
157
+
153
158
logger . info ( `Setting public access status to ${ ! ! enablePublicAccess } for org ${ SINGLE_TENANT_ORG_DOMAIN } ` ) ;
154
159
const res = await setPublicAccessStatus ( SINGLE_TENANT_ORG_DOMAIN , ! ! enablePublicAccess ) ;
155
160
if ( isServiceError ( res ) ) {
@@ -186,6 +191,17 @@ const pruneOldGuestUser = async () => {
186
191
}
187
192
}
188
193
194
+ const validateEntitlements = ( ) => {
195
+ const entitlements = getEntitlements ( ) ;
196
+
197
+ if ( env . SOURCEBOT_EE_AUDIT_LOGGING_ENABLED === 'true' ) {
198
+ if ( ! hasEntitlement ( 'audit' ) ) {
199
+ logger . error ( `Audit logging is enabled but your license does not include the audit logging entitlement. Please reach out to us to enquire about upgrading your license.` ) ;
200
+ process . exit ( 1 ) ;
201
+ }
202
+ }
203
+ }
204
+
189
205
const initSingleTenancy = async ( ) => {
190
206
await prisma . org . upsert ( {
191
207
where : {
@@ -203,6 +219,9 @@ const initSingleTenancy = async () => {
203
219
// To keep things simple, we'll just delete the old guest user if it exists in the DB
204
220
await pruneOldGuestUser ( ) ;
205
221
222
+ // Startup time entitlement/environment variable validation
223
+ validateEntitlements ( ) ;
224
+
206
225
const hasPublicAccessEntitlement = hasEntitlement ( "public-access" ) ;
207
226
if ( hasPublicAccessEntitlement ) {
208
227
const res = await createGuestUser ( SINGLE_TENANT_ORG_DOMAIN ) ;
0 commit comments