import { i18n } from '@kbn/i18n' ; import { cloneDeep , set , upperFirst } from 'lodash' ; import type { Logger } from 'src/core/server' ; import { getDefaultChromiumSandboxDisabled } from './default_chromium_sandbox_disabled' ; import { ConfigType } from './schema' ; export async function createConfig ( parentLogger , config ) { const logger = parentLogger . get ( 'config' ) ; if ( config . browser . chromium . disableSandbox != null ) { return config ; } const { os , disableSandbox } = await getDefaultChromiumSandboxDisabled ( ) ; const osName = [ os . os , os . dist , os . release ] . filter ( Boolean ) . map ( upperFirst ) . join ( ' ' ) ; logger . debug ( i18n . translate ( 'xpack.screenshotting.serverConfig.osDetected' , { defaultMessage : `Running on OS: '{osName}'` , values : { osName } , } ) ) ; if ( disableSandbox === true ) { logger . warn ( i18n . translate ( 'xpack.screenshotting.serverConfig.autoSet.sandboxDisabled' , { defaultMessage : `Chromium sandbox provides an additional layer of protection, but is not supported for {osName} OS. Automatically setting '{configKey}: true'.` , values : { configKey : 'xpack.screenshotting.capture.browser.chromium.disableSandbox' , osName , } , } ) ) ; } else { logger . info ( i18n . translate ( 'xpack.screenshotting.serverConfig.autoSet.sandboxEnabled' , { defaultMessage : `Chromium sandbox provides an additional layer of protection, and is supported for {osName} OS. Automatically enabling Chromium sandbox.` , values : { osName } , } ) ) ; } return set ( cloneDeep ( config ) , 'browser.chromium.disableSandbox' , disableSandbox ) ; }