import hash from 'object-hash' ; import { Setup } from '../../../lib/helpers/setup_request' ; import { AgentConfiguration , AgentConfigurationIntake , } from '../../../../common/agent_configuration/configuration_types' ; import { APMIndexDocumentParams } from '../../../lib/helpers/create_es_client/create_internal_es_client' ; export function createOrUpdateConfiguration ( { configurationId , configurationIntake , setup , } ) { const { internalClient , indices } = setup ; const params = { refresh : true , index : indices . apmAgentConfigurationIndex , body : { agent_name : configurationIntake . agent_name , service : { name : configurationIntake . service . name , environment : configurationIntake . service . environment , } , settings : configurationIntake . settings , '@timestamp' : Date . now ( ) , applied_by_agent : false , etag : hash ( configurationIntake ) , } , } ; if ( configurationId ) { params . id = configurationId ; } return internalClient . index ( 'create_or_update_agent_configuration' , params ) ; }