Skip to content

Commit

Permalink
Revise index calls to use kibana https fetch. Remove http service
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Caldwell committed Apr 27, 2021
1 parent 2dd166d commit bc75830
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 75 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,22 @@
* 2.0.
*/

import { http as httpService } from './http_service';
import { getSavedObjectsClient } from '../../../../kibana_services';
import { getSavedObjectsClient, getHttp } from '../../../../kibana_services';
import { INDEX_FEATURE_PATH, INDEX_SOURCE_API_PATH } from '../../../../../common';

export const getExistingIndexNames = async () => {
const indexes = await httpService({
url: `/api/index_management/indices`,
const indexes = await getHttp().fetch({
path: `/api/index_management/indices`,
method: 'GET',
});
return indexes ? indexes.map(({ name }: { name: string }) => name) : [];
};

export const createNewIndexAndPattern = async (indexName: string) => {
return await httpService({
url: `/${INDEX_SOURCE_API_PATH}`,
return await getHttp().fetch({
path: `/${INDEX_SOURCE_API_PATH}`,
method: 'POST',
data: {
body: convertObjectToBlob({
index: indexName,
// Initially set to static mappings
mappings: {
Expand All @@ -31,23 +30,27 @@ export const createNewIndexAndPattern = async (indexName: string) => {
},
},
},
},
}),
});
};

export const addFeatureToIndex = async (indexName: string, geometry: unknown) => {
return await httpService({
url: `/${INDEX_FEATURE_PATH}`,
return await getHttp().fetch({
path: `/${INDEX_FEATURE_PATH}`,
method: 'POST',
data: {
body: convertObjectToBlob({
index: indexName,
data: {
coordinates: geometry,
},
},
}),
});
};

const convertObjectToBlob = (obj: unknown) => {
return new Blob([JSON.stringify(obj)], { type: 'application/json' });
};

export const getExistingIndexPatternNames = async () => {
const indexPatterns = await getSavedObjectsClient()
.find({
Expand Down

0 comments on commit bc75830

Please sign in to comment.