Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[@kbn/securitysolution-es-utils] remove transport API in favour of typed public API #113717

Merged
merged 5 commits into from
Oct 4, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

import { ElasticsearchClient } from '../elasticsearch_client';
import type { KibanaClient as ElasticsearchClient } from '@elastic/elasticsearch/api/kibana';

// See the reference(s) below on explanations about why -000001 was chosen and
// why the is_write_index is true as well as the bootstrapping step which is needed.
Expand All @@ -16,9 +16,8 @@ export const createBootstrapIndex = async (
index: string
): Promise<unknown> => {
return (
await esClient.transport.request({
path: `/${index}-000001`,
method: 'PUT',
await esClient.indices.create({
index: `/${index}-000001`,
body: {
aliases: {
[index]: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

import { ElasticsearchClient } from '../elasticsearch_client';
import type { KibanaClient as ElasticsearchClient } from '@elastic/elasticsearch/api/kibana';

export const deleteAllIndex = async (
esClient: ElasticsearchClient,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,14 @@
* Side Public License, v 1.
*/

import { ElasticsearchClient } from '../elasticsearch_client';
import type { KibanaClient as ElasticsearchClient } from '@elastic/elasticsearch/api/kibana';

export const deletePolicy = async (
esClient: ElasticsearchClient,
policy: string
): Promise<unknown> => {
return (
await esClient.transport.request({
path: `/_ilm/policy/${policy}`,
method: 'DELETE',
})
).body;
// @ts-expect-error policy_id is required by mistake. fixed in the v8.0
(await esClient.ilm.deleteLifecycle({ policy })).body
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

);
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

import { ElasticsearchClient } from '../elasticsearch_client';
import type { KibanaClient as ElasticsearchClient } from '@elastic/elasticsearch/api/kibana';

export const deleteTemplate = async (
esClient: ElasticsearchClient,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

import { ElasticsearchClient } from '../elasticsearch_client';
import type { KibanaClient as ElasticsearchClient } from '@elastic/elasticsearch/api/kibana';

interface AliasesResponse {
[indexName: string]: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

import { ElasticsearchClient } from '../elasticsearch_client';
import type { KibanaClient as ElasticsearchClient } from '@elastic/elasticsearch/api/kibana';

/**
* Retrieves the count of documents in a given index
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

import { ElasticsearchClient } from '../elasticsearch_client';
import type { KibanaClient as ElasticsearchClient } from '@elastic/elasticsearch/api/kibana';

export const getIndexExists = async (
esClient: ElasticsearchClient,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,15 @@
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { ElasticsearchClient } from '../elasticsearch_client';
import type { KibanaClient as ElasticsearchClient } from '@elastic/elasticsearch/api/kibana';

export const getPolicyExists = async (
esClient: ElasticsearchClient,
policy: string
): Promise<boolean> => {
try {
await esClient.transport.request({
path: `/_ilm/policy/${policy}`,
method: 'GET',
await esClient.ilm.getLifecycle({
policy,
});
// Return true that there exists a policy which is not 404 or some error
// Since there is not a policy exists API, this is how we create one by calling
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

import { ElasticsearchClient } from '../elasticsearch_client';
import type { KibanaClient as ElasticsearchClient } from '@elastic/elasticsearch/api/kibana';

export const getTemplateExists = async (
esClient: ElasticsearchClient,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

import { ElasticsearchClient } from '../elasticsearch_client';
import type { KibanaClient as ElasticsearchClient } from '@elastic/elasticsearch/api/kibana';

export const readIndex = async (esClient: ElasticsearchClient, index: string): Promise<unknown> => {
return esClient.indices.get({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,14 @@
* Side Public License, v 1.
*/

import { ElasticsearchClient } from '../elasticsearch_client';
import type { KibanaClient as ElasticsearchClient } from '@elastic/elasticsearch/api/kibana';

export const readPrivileges = async (
esClient: ElasticsearchClient,
index: string
): Promise<unknown> => {
return (
await esClient.transport.request({
path: '/_security/user/_has_privileges',
method: 'POST',
await esClient.security.hasPrivileges({
body: {
cluster: [
'all',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,16 @@
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { ElasticsearchClient } from '../elasticsearch_client';
import type { KibanaClient as ElasticsearchClient } from '@elastic/elasticsearch/api/kibana';

export const setPolicy = async (
esClient: ElasticsearchClient,
policy: string,
body: Record<string, unknown>
): Promise<unknown> => {
return (
await esClient.transport.request({
path: `/_ilm/policy/${policy}`,
method: 'PUT',
body,
await esClient.ilm.putLifecycle({
policy,
})
).body;
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

import { ElasticsearchClient } from '../elasticsearch_client';
import type { KibanaClient as ElasticsearchClient } from '@elastic/elasticsearch/api/kibana';

export const setTemplate = async (
esClient: ElasticsearchClient,
Expand Down