-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
[Endpoint] Integrate the Policy list with ingest datasources api #60548
Merged
paul-tavares
merged 18 commits into
elastic:master
from
paul-tavares:task/endpoint-150-policy-list-api-integration
Mar 20, 2020
Merged
Changes from 14 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
42e686e
Use ingest API to get endpoint datasources
paul-tavares cb0d357
Add `application` service to `KibanaContextProvider`
paul-tavares fccbe1d
Adjust Policy list to show data available from API
paul-tavares 5fab1ab
Added ingest service + refactored middleware
paul-tavares d3c8aa3
handle api failures/errors
paul-tavares 4d9fab8
Removed policy list fake_data generator
paul-tavares 75c70ac
Fix typing
paul-tavares 68b0271
Rename method + added explicit return type
paul-tavares 006f33b
move dispatch outside of try block
paul-tavares b121976
Removed unnecessary action
paul-tavares 79a1b51
Merge remote-tracking branch 'upstream/master' into task/endpoint-150…
paul-tavares 484c99c
Added FIXME comments with link to issue
paul-tavares 3ee7294
Skip some functional tests
paul-tavares 9891023
added tests for ingest service
paul-tavares d6b39be
Policy list tests - turn it all off
paul-tavares 76b2cf7
Merge remote-tracking branch 'upstream/master' into task/endpoint-150…
paul-tavares 42f293c
Merge branch 'master' into task/endpoint-150-policy-list-api-integration
elasticmachine ae0c332
Merge remote-tracking branch 'upstream/master' into task/endpoint-150…
paul-tavares File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since
err
will be any, the dispatch call accepts it even though the runtime value may not satisfy the expected payload type.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't just pass the
err
through because theApiServerError
structure is in thebody
property of the error object returned byhttp.*
methods, thus why I do the check below. I test this by adding akuery
param on the fetch above to make it fail 😞