import { Role } from '../../../../plugins/security/common/model' ; import { FtrProviderContext } from '../../ftr_provider_context' ; type CreateRolePayload = Pick < Role , 'metadata' | 'elasticsearch' | 'kibana' > ; const OBSERVABILITY_TEST_ROLE_NAME = 'observability-functional-test-role' ; export function ObservabilityUsersProvider ( { getPageObject , getService } ) { const security = getService ( 'security' ) ; const commonPageObject = getPageObject ( 'common' ) ; arg roleDefinition const setTestUserRole = async ( roleDefinition ) => { await commonPageObject . navigateToActualUrl ( 'kibana' ) ; await security . role . create ( OBSERVABILITY_TEST_ROLE_NAME , roleDefinition ) ; await security . testUser . setRoles ( [ OBSERVABILITY_TEST_ROLE_NAME ] ) ; } ; /**
     * Deletes the test role and restores thedefault test user role. Performs a
     * page reload to apply the role change, but doesn't require a re-login.
     */ const restoreDefaultTestUserRole = async ( ) => { await Promise . all ( [ security . role . delete ( OBSERVABILITY_TEST_ROLE_NAME ) , security . testUser . restoreDefaults ( ) , ] ) ; } ; return { defineBasicObservabilityRole , restoreDefaultTestUserRole , setTestUserRole , } ; } /**
 * Generates a combination of Elasticsearch and Kibana privileges for given
 * observability features.
 */ const defineBasicObservabilityRole = ( features ) : CreateRolePayload => { return { elasticsearch : { cluster : [ 'all' ] , indices : [ ... ( ( features . logs ?. length ?? 0 ) > 0 ? [ { names : [ 'filebeat-*' , 'logs-*' ] , privileges : [ 'all' ] } ] : [ ] ) , ... ( ( features . infrastructure ?. length ?? 0 ) > 0 ? [ { names : [ 'metricbeat-*' , 'metrics-*' ] , privileges : [ 'all' ] } ] : [ ] ) , ... ( ( features . apm ?. length ?? 0 ) > 0 ? [ { names : [ 'apm-*' , 'logs-apm*' , 'metrics-apm*' , 'traces-apm*' , 'observability-annotations' , ] , privileges : [ 'read' , 'view_index_metadata' ] , } , ] : [ ] ) , ... ( ( features . uptime ?. length ?? 0 ) > 0 ? [ { names : [ 'heartbeat-*,synthetics-*' ] , privileges : [ 'all' ] } ] : [ ] ) , ] , run_as : [ ] , } , kibana : [ { spaces : [ '*' ] , base : [ ] , feature : features , } , ] , } ; } ;