import { FtrProviderContext as CommonFtrProviderContext } from '../../../common/ftr_provider_context' ; import { Role , User , UserInfo } from './types' ; import { users } from './users' ; import { roles } from './roles' ; import { spaces } from './spaces' ; export const getUserInfo = ( user ) : UserInfo => ( { username : user . username , full_name : user . username . replace ( '_' , ' ' ) , email : `${ user . username }@elastic.co` , } ) ; export const createSpaces = async ( getService ) => { const spacesService = getService ( 'spaces' ) ; for ( const space of spaces ) { await spacesService . create ( space ) ; } } ; /**
 * Creates the users and roles for use in the tests. Defaults to specific users and roles used by the security_and_spaces
 * scenarios but can be passed specific ones as well.
 */ export const createUsersAndRoles = async ( getService , usersToCreate = users , rolesToCreate = roles ) => { const security = getService ( 'security' ) ; const createRole = async ( { name , privileges } ) => { return await security . role . create ( name , privileges ) ; } ; const createUser = async ( user ) => { const userInfo = getUserInfo ( user ) ; return await security . user . create ( user . username , { password : user . password , roles : user . roles , full_name : userInfo . full_name , email : userInfo . email , } ) ; } ; for ( const role of rolesToCreate ) { await createRole ( role ) ; } for ( const user of usersToCreate ) { await createUser ( user ) ; } } ; export const deleteSpaces = async ( getService ) => { const spacesService = getService ( 'spaces' ) ; for ( const space of spaces ) { try { await spacesService . delete ( space . id ) ; } catch ( error ) { } } } ; export const deleteUsersAndRoles = async ( getService , usersToDelete = users , rolesToDelete = roles ) => { const security = getService ( 'security' ) ; for ( const user of usersToDelete ) { try { await security . user . delete ( user . username ) ; } catch ( error ) { } } for ( const role of rolesToDelete ) { try { await security . role . delete ( role . name ) ; } catch ( error ) { } } } ; export const createSpacesAndUsers = async ( getService ) => { await createSpaces ( getService ) ; await createUsersAndRoles ( getService ) ; } ; export const deleteSpacesAndUsers = async ( getService ) => { await deleteSpaces ( getService ) ; await deleteUsersAndRoles ( getService ) ; } ;