mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[Maps] remove getIndexPatternsService from server.kibana_server_services (#120156)
* [Maps] remove getIndexPatternsService from server.kibana_server_services * eslint
This commit is contained in:
parent
44f3f92682
commit
553928c4e1
4 changed files with 52 additions and 46 deletions
|
@ -5,32 +5,20 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { ElasticsearchClient, ISavedObjectsRepository } from 'kibana/server';
|
||||
import { SavedObjectsClient } from '../../../../src/core/server';
|
||||
import {
|
||||
IndexPatternsCommonService,
|
||||
IndexPatternsServiceStart,
|
||||
} from '../../../../src/plugins/data/server';
|
||||
import { CoreStart } from '../../../../src/core/server';
|
||||
import { StartDeps } from './plugin';
|
||||
|
||||
let internalRepository: ISavedObjectsRepository;
|
||||
export const setInternalRepository = (
|
||||
createInternalRepository: (extraTypes?: string[]) => ISavedObjectsRepository
|
||||
) => {
|
||||
internalRepository = createInternalRepository();
|
||||
};
|
||||
export const getInternalRepository = () => internalRepository;
|
||||
let coreStart: CoreStart;
|
||||
let pluginsStart: StartDeps;
|
||||
export function setStartServices(core: CoreStart, plugins: StartDeps) {
|
||||
coreStart = core;
|
||||
pluginsStart = plugins;
|
||||
}
|
||||
|
||||
let esClient: ElasticsearchClient;
|
||||
let indexPatternsService: IndexPatternsCommonService;
|
||||
export const setIndexPatternsService = async (
|
||||
indexPatternsServiceFactory: IndexPatternsServiceStart['indexPatternsServiceFactory'],
|
||||
elasticsearchClient: ElasticsearchClient
|
||||
) => {
|
||||
esClient = elasticsearchClient;
|
||||
indexPatternsService = await indexPatternsServiceFactory(
|
||||
new SavedObjectsClient(getInternalRepository()),
|
||||
elasticsearchClient
|
||||
);
|
||||
export const getSavedObjectClient = (extraTypes?: string[]) => {
|
||||
return coreStart.savedObjects.createInternalRepository(extraTypes);
|
||||
};
|
||||
export const getIndexPatternsService = () => indexPatternsService;
|
||||
export const getESClient = () => esClient;
|
||||
|
||||
export const getIndexPatternsServiceFactory = () =>
|
||||
pluginsStart.data.indexPatterns.indexPatternsServiceFactory;
|
||||
export const getElasticsearch = () => coreStart.elasticsearch;
|
||||
|
|
|
@ -54,19 +54,31 @@ jest.mock('../kibana_server_services', () => {
|
|||
},
|
||||
};
|
||||
return {
|
||||
getIndexPatternsService() {
|
||||
getSavedObjectClient: () => {
|
||||
return {};
|
||||
},
|
||||
getElasticsearch: () => {
|
||||
return {
|
||||
async get(x) {
|
||||
return x === testAggIndexPatternId ? testAggIndexPattern : testIndexPatterns[x];
|
||||
},
|
||||
async getIds() {
|
||||
return Object.values(testIndexPatterns).map((x) => x.id);
|
||||
},
|
||||
async getFieldsForIndexPattern(x) {
|
||||
return x.fields;
|
||||
client: {
|
||||
asInternalUser: {},
|
||||
},
|
||||
};
|
||||
},
|
||||
getIndexPatternsServiceFactory() {
|
||||
return function () {
|
||||
return {
|
||||
async get(x) {
|
||||
return x === testAggIndexPatternId ? testAggIndexPattern : testIndexPatterns[x];
|
||||
},
|
||||
async getIds() {
|
||||
return Object.values(testIndexPatterns).map((x) => x.id);
|
||||
},
|
||||
async getFieldsForIndexPattern(x) {
|
||||
return x.fields;
|
||||
},
|
||||
};
|
||||
};
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
|
|
|
@ -22,7 +22,11 @@ import {
|
|||
LayerDescriptor,
|
||||
} from '../../common/descriptor_types';
|
||||
import { MapSavedObject, MapSavedObjectAttributes } from '../../common/map_saved_object_type';
|
||||
import { getIndexPatternsService, getInternalRepository } from '../kibana_server_services';
|
||||
import {
|
||||
getElasticsearch,
|
||||
getIndexPatternsServiceFactory,
|
||||
getSavedObjectClient,
|
||||
} from '../kibana_server_services';
|
||||
import { injectReferences } from '././../../common/migrations/references';
|
||||
import {
|
||||
getBaseMapsPerCluster,
|
||||
|
@ -36,6 +40,15 @@ import {
|
|||
TELEMETRY_SCALING_OPTION_COUNTS_PER_CLUSTER,
|
||||
TELEMETRY_TERM_JOIN_COUNTS_PER_CLUSTER,
|
||||
} from './util';
|
||||
import { SavedObjectsClient } from '../../../../../src/core/server';
|
||||
|
||||
async function getIndexPatternsService() {
|
||||
const factory = getIndexPatternsServiceFactory();
|
||||
return factory(
|
||||
new SavedObjectsClient(getSavedObjectClient()),
|
||||
getElasticsearch().client.asInternalUser
|
||||
);
|
||||
}
|
||||
|
||||
interface IStats {
|
||||
[key: string]: {
|
||||
|
@ -302,7 +315,7 @@ export async function execTransformOverMultipleSavedObjectPages<T>(
|
|||
savedObjectType: string,
|
||||
transform: (savedObjects: Array<SavedObject<T>>) => void
|
||||
) {
|
||||
const savedObjectsClient = getInternalRepository();
|
||||
const savedObjectsClient = getSavedObjectClient();
|
||||
|
||||
let currentPage = 1;
|
||||
// Seed values
|
||||
|
|
|
@ -25,8 +25,7 @@ import { registerMapsUsageCollector } from './maps_telemetry/collectors/register
|
|||
import { APP_ID, APP_ICON, MAP_SAVED_OBJECT_TYPE, getFullPath } from '../common/constants';
|
||||
import { mapSavedObjects, mapsTelemetrySavedObjects } from './saved_objects';
|
||||
import { MapsXPackConfig } from '../config';
|
||||
// @ts-ignore
|
||||
import { setIndexPatternsService, setInternalRepository } from './kibana_server_services';
|
||||
import { setStartServices } from './kibana_server_services';
|
||||
import { UsageCollectionSetup } from '../../../../src/plugins/usage_collection/server';
|
||||
import { emsBoundariesSpecProvider } from './tutorials/ems';
|
||||
// @ts-ignore
|
||||
|
@ -160,7 +159,6 @@ export class MapsPlugin implements Plugin {
|
|||
);
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
setup(core: CoreSetup, plugins: SetupDeps) {
|
||||
const { usageCollection, home, licensing, features, mapsEms, customIntegrations } = plugins;
|
||||
const mapsEmsConfig = mapsEms.config;
|
||||
|
@ -230,12 +228,7 @@ export class MapsPlugin implements Plugin {
|
|||
};
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
start(core: CoreStart, plugins: StartDeps) {
|
||||
setInternalRepository(core.savedObjects.createInternalRepository);
|
||||
setIndexPatternsService(
|
||||
plugins.data.indexPatterns.indexPatternsServiceFactory,
|
||||
core.elasticsearch.client.asInternalUser
|
||||
);
|
||||
setStartServices(core, plugins);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue