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

[Ingest][Endpoint] Add Ingest rest api response types for use in Endpoint #63373

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
MiddlewareFactory,
PolicyData,
PolicyDetailsState,
UpdateDatasourceResponse,
UpdatePolicyResponse,
} from '../../types';
import { policyIdFromParams, isOnPolicyDetailsPage, policyDetails } from './selectors';
import { generatePolicy } from '../../models/policy';
Expand Down Expand Up @@ -77,7 +77,7 @@ export const policyDetailsMiddlewareFactory: MiddlewareFactory<PolicyDetailsStat
} else if (action.type === 'userClickedPolicyDetailsSaveButton') {
const { id, revision, ...updatedPolicyItem } = policyDetails(state) as PolicyData;

let apiResponse: UpdateDatasourceResponse;
let apiResponse: UpdatePolicyResponse;
try {
apiResponse = await sendPutDatasource(http, id, updatedPolicyItem);
} catch (error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { MiddlewareFactory, PolicyListState, GetDatasourcesResponse } from '../../types';
import { GetPolicyListResponse, MiddlewareFactory, PolicyListState } from '../../types';
import { sendGetEndpointSpecificDatasources } from './services/ingest';
import { isOnPolicyListPage, urlSearchParams } from './selectors';

Expand All @@ -18,7 +18,7 @@ export const policyListMiddlewareFactory: MiddlewareFactory<PolicyListState> = c

if (action.type === 'userChangedUrl' && isOnPolicyListPage(state)) {
const { page_index: pageIndex, page_size: pageSize } = urlSearchParams(state);
let response: GetDatasourcesResponse;
let response: GetPolicyListResponse;

try {
response = await sendGetEndpointSpecificDatasources(http, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import {
} from '../../../../../../../ingest_manager/common';
import {
NewPolicyData,
GetDatasourcesResponse,
GetDatasourceResponse,
UpdateDatasourceResponse,
GetPolicyListResponse,
GetPolicyResponse,
UpdatePolicyResponse,
} from '../../../types';

const INGEST_API_ROOT = `/api/ingest_manager`;
Expand All @@ -30,8 +30,8 @@ const INGEST_API_FLEET_AGENT_STATUS = `${INGEST_API_FLEET}/agent-status`;
export const sendGetEndpointSpecificDatasources = (
http: HttpStart,
options: HttpFetchOptions & Partial<GetDatasourcesRequest> = {}
): Promise<GetDatasourcesResponse> => {
return http.get<GetDatasourcesResponse>(INGEST_API_DATASOURCES, {
): Promise<GetPolicyListResponse> => {
return http.get<GetPolicyListResponse>(INGEST_API_DATASOURCES, {
...options,
query: {
...options.query,
Expand All @@ -53,7 +53,7 @@ export const sendGetDatasource = (
datasourceId: string,
options?: HttpFetchOptions
) => {
return http.get<GetDatasourceResponse>(`${INGEST_API_DATASOURCES}/${datasourceId}`, options);
return http.get<GetPolicyResponse>(`${INGEST_API_DATASOURCES}/${datasourceId}`, options);
};

/**
Expand All @@ -69,7 +69,7 @@ export const sendPutDatasource = (
datasourceId: string,
datasource: NewPolicyData,
options: Exclude<HttpFetchOptions, 'body'> = {}
): Promise<UpdateDatasourceResponse> => {
): Promise<UpdatePolicyResponse> => {
return http.put(`${INGEST_API_DATASOURCES}/${datasourceId}`, {
...options,
body: JSON.stringify(datasource),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { HttpStart } from 'kibana/public';
import { Dispatch } from 'redux';
import { INGEST_API_DATASOURCES } from './services/ingest';
import { EndpointDocGenerator } from '../../../../../common/generate_data';
import { AppAction, GetDatasourcesResponse, GlobalState, MiddlewareFactory } from '../../types';
import { AppAction, GetPolicyListResponse, GlobalState, MiddlewareFactory } from '../../types';

const generator = new EndpointDocGenerator('policy-list');

Expand All @@ -19,13 +19,13 @@ const generator = new EndpointDocGenerator('policy-list');
*/
export const setPolicyListApiMockImplementation = (
mockedHttpService: jest.Mocked<HttpStart>,
responseItems: GetDatasourcesResponse['items'] = [generator.generatePolicyDatasource()]
responseItems: GetPolicyListResponse['items'] = [generator.generatePolicyDatasource()]
): void => {
mockedHttpService.get.mockImplementation((...args) => {
const [path] = args;
if (typeof path === 'string') {
if (path === INGEST_API_DATASOURCES) {
return Promise.resolve<GetDatasourcesResponse>({
return Promise.resolve<GetPolicyListResponse>({
items: responseItems,
total: 10,
page: 1,
Expand Down
27 changes: 10 additions & 17 deletions x-pack/plugins/endpoint/public/applications/endpoint/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@ import {
import { EndpointPluginStartDependencies } from '../../plugin';
import { AppAction } from './store/action';
import { CoreStart } from '../../../../../../src/core/public';
import { Datasource, NewDatasource } from '../../../../ingest_manager/common/types/models';
import {
Datasource,
NewDatasource,
GetAgentStatusResponse,
CreateDatasourceResponse,
} from '../../../../ingest_manager/common/types/rest_spec';
GetDatasourcesResponse,
GetOneDatasourceResponse,
UpdateDatasourceResponse,
} from '../../../../ingest_manager/common';

export { AppAction };
export type MiddlewareFactory<S = GlobalState> = (
Expand Down Expand Up @@ -335,24 +338,14 @@ export interface AlertingIndexUIQueryParams {
filters?: string;
}

export interface GetDatasourcesResponse {
export interface GetPolicyListResponse extends GetDatasourcesResponse {
items: PolicyData[];
total: number;
page: number;
perPage: number;
success: boolean;
}

export interface GetDatasourceResponse {
export interface GetPolicyResponse extends GetOneDatasourceResponse {
item: PolicyData;
success: boolean;
}

export type UpdateDatasourceResponse = CreateDatasourceResponse & {
export interface UpdatePolicyResponse extends UpdateDatasourceResponse {
item: PolicyData;
};

/**
* The PageId type is used for the payload when firing userNavigatedToPage actions
*/
export type PageId = 'alertsPage' | 'managementPage' | 'policyListPage';
}
17 changes: 12 additions & 5 deletions x-pack/plugins/ingest_manager/common/types/rest_spec/datasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,22 @@ export interface GetDatasourcesRequest {
};
}

export interface GetDatasourcesResponse {
items: Datasource[];
total: number;
page: number;
perPage: number;
success: boolean;
}

export interface GetOneDatasourceRequest {
params: {
datasourceId: string;
};
}

export interface GetDatasourcesResponse {
items: Datasource[];
total: number;
page: number;
perPage: number;
export interface GetOneDatasourceResponse {
item: Datasource;
success: boolean;
}

Expand All @@ -40,6 +45,8 @@ export type UpdateDatasourceRequest = GetOneDatasourceRequest & {
body: NewDatasource;
};

export type UpdateDatasourceResponse = CreateDatasourceResponse;

export interface DeleteDatasourcesRequest {
body: {
datasourceIds: string[];
Expand Down