@@ -10,7 +10,7 @@ import { ConnectionConfig } from '@sourcebot/schemas/v3/connection.type';
1010import { indexSchema } from '@sourcebot/schemas/v3/index.schema' ;
1111import Ajv from 'ajv' ;
1212import { syncSearchContexts } from '@/ee/features/searchContexts/syncSearchContexts' ;
13- import { hasEntitlement } from '@/features/entitlements/server' ;
13+ import { getEntitlements , hasEntitlement } from '@/features/entitlements/server' ;
1414import { createGuestUser , setPublicAccessStatus } from '@/ee/features/publicAccess/publicAccess' ;
1515import { isServiceError } from './lib/utils' ;
1616import { ServiceErrorException } from './lib/serviceError' ;
@@ -150,6 +150,11 @@ const syncDeclarativeConfig = async (configPath: string) => {
150150 }
151151
152152 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+
153158 logger . info ( `Setting public access status to ${ ! ! enablePublicAccess } for org ${ SINGLE_TENANT_ORG_DOMAIN } ` ) ;
154159 const res = await setPublicAccessStatus ( SINGLE_TENANT_ORG_DOMAIN , ! ! enablePublicAccess ) ;
155160 if ( isServiceError ( res ) ) {
@@ -186,6 +191,17 @@ const pruneOldGuestUser = async () => {
186191 }
187192}
188193
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+
189205const initSingleTenancy = async ( ) => {
190206 await prisma . org . upsert ( {
191207 where : {
@@ -203,6 +219,9 @@ const initSingleTenancy = async () => {
203219 // To keep things simple, we'll just delete the old guest user if it exists in the DB
204220 await pruneOldGuestUser ( ) ;
205221
222+ // Startup time entitlement/environment variable validation
223+ validateEntitlements ( ) ;
224+
206225 const hasPublicAccessEntitlement = hasEntitlement ( "public-access" ) ;
207226 if ( hasPublicAccessEntitlement ) {
208227 const res = await createGuestUser ( SINGLE_TENANT_ORG_DOMAIN ) ;
0 commit comments