2020-11-24 13:46:51 +01:00
|
|
|
/*
|
2021-01-20 02:52:56 +01:00
|
|
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
|
|
* or more contributor license agreements. Licensed under the Elastic License
|
2021-02-04 03:12:39 +01:00
|
|
|
* 2.0 and the Server Side Public License, v 1; you may not use this file except
|
|
|
|
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
|
|
|
* Side Public License, v 1.
|
2020-11-24 13:46:51 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
import { get } from 'lodash';
|
|
|
|
import fetch from 'node-fetch';
|
2020-11-30 19:12:00 +01:00
|
|
|
import { getUrl } from '@kbn/test';
|
2020-11-24 13:46:51 +01:00
|
|
|
|
|
|
|
import { FtrProviderContext } from '../ftr_provider_context';
|
|
|
|
|
|
|
|
export function DeploymentProvider({ getService }: FtrProviderContext) {
|
|
|
|
const config = getService('config');
|
|
|
|
|
|
|
|
return {
|
|
|
|
/**
|
|
|
|
* Returns Kibana host URL
|
|
|
|
*/
|
|
|
|
getHostPort() {
|
|
|
|
return getUrl.baseUrl(config.get('servers.kibana'));
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns ES host URL
|
|
|
|
*/
|
|
|
|
getEsHostPort() {
|
|
|
|
return getUrl.baseUrl(config.get('servers.elasticsearch'));
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper to detect an OSS licensed Kibana
|
|
|
|
* Useful for functional testing in cloud environment
|
|
|
|
*/
|
|
|
|
async isOss() {
|
2021-02-08 23:23:10 +01:00
|
|
|
return config.get('kbnTestServer.serverArgs').indexOf('--oss') > -1;
|
2020-11-24 13:46:51 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
async isCloud(): Promise<boolean> {
|
|
|
|
const baseUrl = this.getHostPort();
|
|
|
|
const username = config.get('servers.kibana.username');
|
|
|
|
const password = config.get('servers.kibana.password');
|
|
|
|
const response = await fetch(baseUrl + '/api/stats?extended', {
|
|
|
|
method: 'get',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
Authorization: 'Basic ' + Buffer.from(username + ':' + password).toString('base64'),
|
|
|
|
},
|
|
|
|
});
|
|
|
|
const data = await response.json();
|
|
|
|
return get(data, 'usage.cloud.is_cloud_enabled', false);
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|