-
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.
[Endpoint] Integrate the Policy list with ingest datasources api (#60548
) (#60904) * Use ingest API to get endpoint datasources * Add `application` service to `KibanaContextProvider` * Adjust Policy list to show data available from API * Added ingest service + refactored middleware * handle api failures/errors * Removed policy list fake_data generator * Fix typing * Rename method + added explicit return type * move dispatch outside of try block * Removed unnecessary action * Added FIXME comments with link to issue * Skip some functional tests * added tests for ingest service * Policy list tests - turn it all off Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> # Conflicts: # x-pack/plugins/endpoint/public/applications/endpoint/index.tsx # x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_list.tsx
- Loading branch information
1 parent
0dba353
commit ab74374
Showing
14 changed files
with
230 additions
and
175 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
53 changes: 53 additions & 0 deletions
53
x-pack/plugins/endpoint/public/applications/endpoint/services/ingest.test.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,53 @@ | ||
/* | ||
* 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 { httpServiceMock } from '../../../../../../../src/core/public/mocks'; | ||
import { sendGetDatasource, sendGetEndpointSpecificDatasources } from './ingest'; | ||
|
||
describe('ingest service', () => { | ||
let http: ReturnType<typeof httpServiceMock.createStartContract>; | ||
|
||
beforeEach(() => { | ||
http = httpServiceMock.createStartContract(); | ||
}); | ||
|
||
describe('sendGetEndpointSpecificDatasources()', () => { | ||
it('auto adds kuery to api request', async () => { | ||
await sendGetEndpointSpecificDatasources(http); | ||
expect(http.get).toHaveBeenCalledWith('/api/ingest_manager/datasources', { | ||
query: { | ||
kuery: 'datasources.package.name: endpoint', | ||
}, | ||
}); | ||
}); | ||
it('supports additional KQL to be defined on input for query params', async () => { | ||
await sendGetEndpointSpecificDatasources(http, { | ||
query: { kuery: 'someValueHere', page: 1, perPage: 10 }, | ||
}); | ||
expect(http.get).toHaveBeenCalledWith('/api/ingest_manager/datasources', { | ||
query: { | ||
kuery: 'someValueHere and datasources.package.name: endpoint', | ||
perPage: 10, | ||
page: 1, | ||
}, | ||
}); | ||
}); | ||
}); | ||
describe('sendGetDatasource()', () => { | ||
it('builds correct API path', async () => { | ||
await sendGetDatasource(http, '123'); | ||
expect(http.get).toHaveBeenCalledWith('/api/ingest_manager/datasources/123', undefined); | ||
}); | ||
it('supports http options', async () => { | ||
await sendGetDatasource(http, '123', { query: { page: 1 } }); | ||
expect(http.get).toHaveBeenCalledWith('/api/ingest_manager/datasources/123', { | ||
query: { | ||
page: 1, | ||
}, | ||
}); | ||
}); | ||
}); | ||
}); |
62 changes: 62 additions & 0 deletions
62
x-pack/plugins/endpoint/public/applications/endpoint/services/ingest.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,62 @@ | ||
/* | ||
* 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 { HttpFetchOptions, HttpStart } from 'kibana/public'; | ||
import { GetDatasourcesRequest } from '../../../../../ingest_manager/common/types/rest_spec'; | ||
import { PolicyData } from '../types'; | ||
|
||
const INGEST_API_ROOT = `/api/ingest_manager`; | ||
const INGEST_API_DATASOURCES = `${INGEST_API_ROOT}/datasources`; | ||
|
||
// FIXME: Import from ingest after - https://github.com/elastic/kibana/issues/60677 | ||
export interface GetDatasourcesResponse { | ||
items: PolicyData[]; | ||
total: number; | ||
page: number; | ||
perPage: number; | ||
success: boolean; | ||
} | ||
|
||
// FIXME: Import from Ingest after - https://github.com/elastic/kibana/issues/60677 | ||
export interface GetDatasourceResponse { | ||
item: PolicyData; | ||
success: boolean; | ||
} | ||
|
||
/** | ||
* Retrieves a list of endpoint specific datasources (those created with a `package.name` of | ||
* `endpoint`) from Ingest | ||
* @param http | ||
* @param options | ||
*/ | ||
export const sendGetEndpointSpecificDatasources = ( | ||
http: HttpStart, | ||
options: HttpFetchOptions & Partial<GetDatasourcesRequest> = {} | ||
): Promise<GetDatasourcesResponse> => { | ||
return http.get<GetDatasourcesResponse>(INGEST_API_DATASOURCES, { | ||
...options, | ||
query: { | ||
...options.query, | ||
kuery: `${ | ||
options?.query?.kuery ? options.query.kuery + ' and ' : '' | ||
}datasources.package.name: endpoint`, | ||
}, | ||
}); | ||
}; | ||
|
||
/** | ||
* Retrieves a single datasource based on ID from ingest | ||
* @param http | ||
* @param datasourceId | ||
* @param options | ||
*/ | ||
export const sendGetDatasource = ( | ||
http: HttpStart, | ||
datasourceId: string, | ||
options?: HttpFetchOptions | ||
) => { | ||
return http.get<GetDatasourceResponse>(`${INGEST_API_DATASOURCES}/${datasourceId}`, options); | ||
}; |
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
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
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
63 changes: 0 additions & 63 deletions
63
x-pack/plugins/endpoint/public/applications/endpoint/store/policy_list/fake_data.ts
This file was deleted.
Oops, something went wrong.
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
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
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
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
Oops, something went wrong.