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

[ENDPOINT] First version of the trusted apps list. #76304

Merged
merged 39 commits into from
Sep 9, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
599a463
First version of the trusted apps list.
efreeti Aug 31, 2020
87766b0
Added proper visualisation of OS and Date Created columns.
efreeti Sep 2, 2020
97a6f41
Small change in naming in middleware.
efreeti Sep 2, 2020
29bedc8
Renamed function to avoid naming confusion.
efreeti Sep 2, 2020
1ce8da6
Migrated to usage of selectors and memo in list component.
efreeti Sep 2, 2020
221ebc2
Added explicit return types.
efreeti Sep 2, 2020
96840cd
Changed to use server schema for service parameter.
efreeti Sep 2, 2020
caabfb9
Removed some over generalisation in types.
efreeti Sep 2, 2020
277b511
Renamed types and properties related to trusted apps page state.
efreeti Sep 2, 2020
223e14e
Renamed types and properties related to trusted apps page state.
efreeti Sep 2, 2020
0e6e1af
Renamed the action type to be namespaced to trusted apps.
efreeti Sep 2, 2020
d50f8fd
Merged the exports and declarations in reducer and used constants for…
efreeti Sep 2, 2020
bed5985
Memoization of pagination data structure.
efreeti Sep 2, 2020
792a1a2
Used a shared constant for REST API path.
efreeti Sep 2, 2020
567e845
Improvements and consistency on pagination across tabs.
efreeti Sep 2, 2020
b2e581d
Added a bit more typing and used Partial<>
efreeti Sep 2, 2020
f845f25
Made constants readonly and added some useMemo usages.
efreeti Sep 3, 2020
00417a7
Fixed extracting page index from URI.
efreeti Sep 3, 2020
5740a5d
Fixed the case of infinite refreshes when there is loading failure (n…
efreeti Sep 3, 2020
509e868
Resetting state to initial when we navigate away from trusted apps list.
efreeti Sep 3, 2020
102c580
Fixed mapping page index to the table pagination.
efreeti Sep 3, 2020
7072df7
Changed to using AppAction in reducer.
efreeti Sep 3, 2020
7e998f3
Made ServerApiError a default error type for data binding.
efreeti Sep 3, 2020
c624cc7
Renamed all types related to data binding to resource state.
efreeti Sep 3, 2020
32453cf
Created index file for state types.
efreeti Sep 3, 2020
01c67c4
Fixed parameter extracting code to meet expectations of endpoints lis…
efreeti Sep 3, 2020
865ff05
Updated snapshot.
efreeti Sep 3, 2020
28c1b5d
Changed middleware to only use selectors.
efreeti Sep 3, 2020
4071f54
Added tests for routing.
efreeti Sep 4, 2020
0f05756
Added documentation to the types in async resource state module.
efreeti Sep 4, 2020
ecb90f3
Added tests for async resource state module.
efreeti Sep 4, 2020
ec3e21f
Added tests for store selectors.
efreeti Sep 4, 2020
0f07f06
Added tests for reducer.
efreeti Sep 7, 2020
99ea3a7
Moved around imports.
efreeti Sep 7, 2020
cf6bd89
Added tests for the middleware.
efreeti Sep 7, 2020
fa58f55
Added list component tests.
efreeti Sep 8, 2020
2787e97
Removed a redundant function.
efreeti Sep 8, 2020
45debb2
Commiting snapshots.
efreeti Sep 8, 2020
944751d
Merge branch 'master' of https://github.com/elastic/kibana into btsym…
efreeti Sep 8, 2020
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 @@ -7,10 +7,16 @@
import { EndpointAction } from '../../management/pages/endpoint_hosts/store/action';
import { PolicyListAction } from '../../management/pages/policy/store/policy_list';
import { PolicyDetailsAction } from '../../management/pages/policy/store/policy_details';
import { TrustedAppsPageAction } from '../../management/pages/trusted_apps/store/action';

export { appActions } from './app';
export { dragAndDropActions } from './drag_and_drop';
export { inputsActions } from './inputs';
import { RoutingAction } from './routing';

export type AppAction = EndpointAction | RoutingAction | PolicyListAction | PolicyDetailsAction;
export type AppAction =
| EndpointAction
| RoutingAction
| PolicyListAction
| PolicyDetailsAction
| TrustedAppsPageAction;
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { AppLocation, Immutable } from '../../../../common/endpoint/types';

interface UserChangedUrl {
export interface UserChangedUrl {
readonly type: 'userChangedUrl';
readonly payload: Immutable<AppLocation>;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ export const MANAGEMENT_STORE_POLICY_LIST_NAMESPACE = 'policyList';
export const MANAGEMENT_STORE_POLICY_DETAILS_NAMESPACE = 'policyDetails';
/** Namespace within the Management state where endpoint-host state is maintained */
export const MANAGEMENT_STORE_ENDPOINTS_NAMESPACE = 'endpoints';
/** Namespace within the Management state where trusted apps page state is maintained */
export const MANAGEMENT_STORE_TRUSTED_APPS_NAMESPACE = 'trustedApps';

export const MANAGEMENT_DEFAULT_PAGE = 1;
export const MANAGEMENT_DEFAULT_PAGE_SIZE = 10;
efreeti marked this conversation as resolved.
Show resolved Hide resolved

// --[ DEFAULTS ]---------------------------------------------------------------------------
/** The default polling interval to start all polling pages */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { generatePath } from 'react-router-dom';
import querystring from 'querystring';

import {
MANAGEMENT_DEFAULT_PAGE,
MANAGEMENT_DEFAULT_PAGE_SIZE,
MANAGEMENT_ROUTING_ENDPOINTS_PATH,
MANAGEMENT_ROUTING_POLICIES_PATH,
MANAGEMENT_ROUTING_POLICY_DETAILS_PATH,
Expand Down Expand Up @@ -86,8 +88,26 @@ export const getPolicyDetailPath = (policyId: string, search?: string) => {
})}${appendSearch(search)}`;
};

export const getTrustedAppsListPath = (search?: string) => {
return `${generatePath(MANAGEMENT_ROUTING_TRUSTED_APPS_PATH, {
interface TrustedAppsListParams {
efreeti marked this conversation as resolved.
Show resolved Hide resolved
page_index?: number;
page_size?: number;
}

const normalizeTrustedAppsListParams = (params?: TrustedAppsListParams) => {
efreeti marked this conversation as resolved.
Show resolved Hide resolved
if (params) {
return {
...(params.page_index === MANAGEMENT_DEFAULT_PAGE ? {} : { page_index: params.page_index }),
...(params.page_size === MANAGEMENT_DEFAULT_PAGE_SIZE ? {} : { page_size: params.page_size }),
};
} else {
return {};
}
};

export const getTrustedAppsListPath = (params?: TrustedAppsListParams) => {
const path = generatePath(MANAGEMENT_ROUTING_TRUSTED_APPS_PATH, {
tabName: AdministrationSubTab.trustedApps,
})}${appendSearch(search)}`;
});

return `${path}${appendSearch(querystring.stringify(normalizeTrustedAppsListParams(params)))}`;
};
4 changes: 1 addition & 3 deletions x-pack/plugins/security_solution/public/management/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ export class Management {
* Cast the ImmutableReducer to a regular reducer for compatibility with
* the subplugin architecture (which expects plain redux reducers.)
*/
reducer: {
management: managementReducer,
} as ManagementPluginReducer,
reducer: { management: managementReducer } as ManagementPluginReducer,
middleware: managementMiddlewareFactory(core, plugins),
},
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* 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 { HttpStart } from 'kibana/public';
import { GetTrustedListAppsResponse } from '../../../../../common/endpoint/types/trusted_apps';

export interface TrustedAppsService {
efreeti marked this conversation as resolved.
Show resolved Hide resolved
getTrustedAppsList(page: number, perPage: number): Promise<GetTrustedListAppsResponse>;
}

export class TrustedAppsHttpService implements TrustedAppsService {
constructor(private http: HttpStart) {}

async getTrustedAppsList(page: number, perPage: number): Promise<GetTrustedListAppsResponse> {
return this.http.get<GetTrustedListAppsResponse>('/api/endpoint/trusted_apps', {
efreeti marked this conversation as resolved.
Show resolved Hide resolved
query: { page, per_page: perPage },
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* 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 { Immutable } from '../../../../../common/endpoint/types';

export interface UninitialisedAsyncBinding {
efreeti marked this conversation as resolved.
Show resolved Hide resolved
type: 'UninitialisedAsyncBinding';
}

export interface InProgressAsyncBinding<T, E> {
type: 'InProgressAsyncBinding';
previousBinding: StaleAsyncBinding<T, E>;
}

export interface PresentAsyncBinding<T> {
efreeti marked this conversation as resolved.
Show resolved Hide resolved
type: 'PresentAsyncBinding';
data: T;
}

export interface FailedAsyncBinding<T, E> {
type: 'FailedAsyncBinding';
error: E;
lastPresentBinding?: PresentAsyncBinding<T>;
}

export type StaleAsyncBinding<T, E> =
| UninitialisedAsyncBinding
| PresentAsyncBinding<T>
| FailedAsyncBinding<T, E>;

export type AsyncDataBinding<T, E> =
| UninitialisedAsyncBinding
| InProgressAsyncBinding<T, E>
| PresentAsyncBinding<T>
| FailedAsyncBinding<T, E>;

export const isUninitialisedAsyncBinding = <T, E>(
binding: Immutable<AsyncDataBinding<T, E>>
): binding is Immutable<UninitialisedAsyncBinding> => binding.type === 'UninitialisedAsyncBinding';

export const isInProgressBinding = <T, E>(
binding: Immutable<AsyncDataBinding<T, E>>
): binding is Immutable<InProgressAsyncBinding<T, E>> => binding.type === 'InProgressAsyncBinding';

export const isPresentAsyncBinding = <T, E>(
efreeti marked this conversation as resolved.
Show resolved Hide resolved
binding: Immutable<AsyncDataBinding<T, E>>
): binding is Immutable<PresentAsyncBinding<T>> => binding.type === 'PresentAsyncBinding';

export const isFailedAsyncBinding = <T, E>(
binding: Immutable<AsyncDataBinding<T, E>>
): binding is Immutable<FailedAsyncBinding<T, E>> => binding.type === 'FailedAsyncBinding';

export const getLastPresentDataBinding = <T, E>(
binding: Immutable<AsyncDataBinding<T, E>>
): Immutable<PresentAsyncBinding<T>> | undefined => {
if (isPresentAsyncBinding(binding)) {
return binding;
} else if (isInProgressBinding(binding)) {
return getLastPresentDataBinding(binding.previousBinding);
} else if (isFailedAsyncBinding(binding)) {
return binding.lastPresentBinding;
} else {
return undefined;
}
};

export const getLastPresentData = <T, E>(binding: Immutable<AsyncDataBinding<T, E>>) => {
return getLastPresentDataBinding(binding)?.data;
};

export const getCurrentError = <T, E>(binding: Immutable<AsyncDataBinding<T, E>>) => {
return isFailedAsyncBinding(binding) ? binding.error : undefined;
};

export const isStaleBinding = <T, E>(
binding: AsyncDataBinding<T, E>,
isFresh: (data: T) => boolean
): boolean =>
isUninitialisedAsyncBinding(binding) ||
(isPresentAsyncBinding(binding) && !isFresh(binding.data)) ||
(isFailedAsyncBinding(binding) &&
(!binding.lastPresentBinding || !isFresh(binding.lastPresentBinding.data)));
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* 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.
*/

export interface PageInfo {
index: number;
size: number;
}

export interface ItemsPage<T> {
efreeti marked this conversation as resolved.
Show resolved Hide resolved
items: T[];
pageInfo: PageInfo;
totalItemsCount: number;
}

export const pageInfosEqual = (pageInfo1: PageInfo, pageInfo2: PageInfo) =>
efreeti marked this conversation as resolved.
Show resolved Hide resolved
pageInfo1.index === pageInfo2.index && pageInfo1.size === pageInfo2.size;
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* 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 { ServerApiError } from '../../../../common/types';
import { ItemsPage, PageInfo } from './items_page';
import { AsyncDataBinding } from './async_data_binding';

export interface ListViewState<T> {
currentPage: AsyncDataBinding<ItemsPage<T>, ServerApiError>;
currentPageInfo: PageInfo;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* 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 { TrustedApp } from '../../../../../common/endpoint/types/trusted_apps';
import { ListViewState } from './list_view_state';

export interface TrustedAppsPageState {
efreeti marked this conversation as resolved.
Show resolved Hide resolved
list: ListViewState<TrustedApp>;
active: boolean;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* 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 { ServerApiError } from '../../../../common/types';
import { TrustedApp } from '../../../../../common/endpoint/types/trusted_apps';
import { RoutingAction } from '../../../../common/store/routing/action';
import { AsyncDataBinding } from '../state/async_data_binding';
import { ItemsPage } from '../state/items_page';

export interface ListDataBindingChanged {
efreeti marked this conversation as resolved.
Show resolved Hide resolved
type: 'listDataBindingChanged';
payload: {
newBinding: AsyncDataBinding<ItemsPage<TrustedApp>, ServerApiError>;
};
}

export type TrustedAppsPageAction = ListDataBindingChanged | RoutingAction;
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* 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 { ServerApiError } from '../../../../common/types';
import { Immutable, TrustedApp } from '../../../../../common/endpoint/types';
import { ImmutableMiddlewareAPI, ImmutableMiddlewareFactory } from '../../../../common/store';
import { AppAction } from '../../../../common/store/actions';
import { TrustedAppsPageState as PageState } from '../state/trusted_apps_page_state';
import { TrustedAppsHttpService, TrustedAppsService } from '../service';
import { needsRefreshOfListData } from './selectors';
import { ListDataBindingChanged } from './action';
import {
AsyncDataBinding,
StaleAsyncBinding,
getLastPresentDataBinding,
} from '../state/async_data_binding';
import { ItemsPage } from '../state/items_page';

type ListBinding = Immutable<AsyncDataBinding<ItemsPage<TrustedApp>, ServerApiError>>;
type StaleListBinding = Immutable<StaleAsyncBinding<ItemsPage<TrustedApp>, ServerApiError>>;

const listDataBindingChanged = (newBinding: ListBinding): Immutable<ListDataBindingChanged> => ({
type: 'listDataBindingChanged',
payload: { newBinding },
});

const refreshList = async (
store: ImmutableMiddlewareAPI<PageState, AppAction>,
trustedAppsService: TrustedAppsService
) => {
const list = store.getState().list;

store.dispatch(
listDataBindingChanged({
type: 'InProgressAsyncBinding',
// need to think on how to avoid the casting
previousBinding: list.currentPage as StaleListBinding,
})
);

try {
const response = await trustedAppsService.getTrustedAppsList(
list.currentPageInfo.index,
list.currentPageInfo.size
);

store.dispatch(
listDataBindingChanged({
type: 'PresentAsyncBinding',
data: {
items: response.data,
pageInfo: list.currentPageInfo,
totalItemsCount: response.total,
},
})
);
} catch (error) {
store.dispatch(
listDataBindingChanged({
type: 'FailedAsyncBinding',
error,
lastPresentBinding: getLastPresentDataBinding(list.currentPage),
})
);
}
};

const middlewareFactory: ImmutableMiddlewareFactory<PageState> = (coreStart) => {
const trustedAppsService: TrustedAppsService = new TrustedAppsHttpService(coreStart.http);

return (store) => (next) => async (action) => {
next(action);

if (needsRefreshOfListData(store.getState())) {
await refreshList(store, trustedAppsService);
}
};
};

export { middlewareFactory as trustedAppsPageMiddlewareFactory };
Loading