-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Transform] Refactor new IndexService
- Loading branch information
Showing
3 changed files
with
38 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
x-pack/plugins/transform/public/app/services/es_index_service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { HttpSetup, SavedObjectsClientContract } from 'kibana/public'; | ||
import { API_BASE_PATH } from '../../../common/constants'; | ||
import { IIndexPattern } from '../../../../../../src/plugins/data/common/index_patterns'; | ||
|
||
export class IndexService { | ||
async canDeleteIndex(http: HttpSetup) { | ||
const privilege = await http.get(`${API_BASE_PATH}privileges`); | ||
if (!privilege) { | ||
return false; | ||
} | ||
return privilege.hasAllPrivileges; | ||
} | ||
|
||
async indexPatternExists(savedObjectsClient: SavedObjectsClientContract, indexName: string) { | ||
const response = await savedObjectsClient.find<IIndexPattern>({ | ||
type: 'index-pattern', | ||
perPage: 1, | ||
search: `"${indexName}"`, | ||
searchFields: ['title'], | ||
fields: ['title'], | ||
}); | ||
const ip = response.savedObjects.find((obj) => obj.attributes.title === indexName); | ||
return ip !== undefined; | ||
} | ||
} | ||
|
||
export const indexService = new IndexService(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters