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 { MiddlewareFactory, PolicyListState, GetPolicyListResponse } from '../../types';
import { sendGetEndpointSpecificDatasources } from './services/ingest';

export const policyListMiddlewareFactory: MiddlewareFactory<PolicyListState> = coreStart => {
Expand All @@ -29,7 +29,7 @@ export const policyListMiddlewareFactory: MiddlewareFactory<PolicyListState> = c
pageIndex = state.pageIndex;
}

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
22 changes: 10 additions & 12 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 @@ -321,22 +324,17 @@ 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
Expand Down
15 changes: 15 additions & 0 deletions x-pack/plugins/ingest_manager/common/types/rest_spec/datasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,25 @@ export interface GetDatasourcesRequest {
query: ListWithKuery;
}

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

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

export interface GetOneDatasourceResponse {
item: Datasource;
success: boolean;
}

export interface CreateDatasourceRequest {
body: NewDatasource;
}
Expand All @@ -29,6 +42,8 @@ export type UpdateDatasourceRequest = GetOneDatasourceRequest & {
body: NewDatasource;
};

export type UpdateDatasourceResponse = CreateDatasourceResponse;

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