Skip to content

Commit 1094b75

Browse files
authored
Trusted Apps Signer UI (#84628) (#85413)
* Added default value for type parameter in ConditionEntry type. * Added signer field UI. Flattened a bit component structure and reused some translations. * Reverted the condition for signer option. * Fixed the import. * Removed unused translations. * Fixed the test. * Consolidated a bit the deletion and creation flows in redux.
1 parent 2bd2501 commit 1094b75

File tree

26 files changed

+406
-394
lines changed

26 files changed

+406
-394
lines changed

x-pack/plugins/security_solution/common/endpoint/schema/trusted_apps.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const createNewTrustedAppForOsScheme = <O extends OperatingSystem, F extends Con
5858

5959
for (const entry of entries) {
6060
// unfortunately combination of generics and Type<...> for "field" causes type errors
61-
const { field, value } = entry as ConditionEntry<ConditionEntryField>;
61+
const { field, value } = entry as ConditionEntry;
6262

6363
if (usedFields.has(field)) {
6464
return `[${entryFieldLabels[field]}] field can only be used once`;

x-pack/plugins/security_solution/common/endpoint/types/trusted_apps.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export enum ConditionEntryField {
3939
SIGNER = 'process.Ext.code_signature',
4040
}
4141

42-
export interface ConditionEntry<T extends ConditionEntryField> {
42+
export interface ConditionEntry<T extends ConditionEntryField = ConditionEntryField> {
4343
field: T;
4444
type: 'match';
4545
operator: 'included';

x-pack/plugins/security_solution/public/management/pages/trusted_apps/state/trusted_apps_list_page_state.ts

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import { ServerApiError } from '../../../../common/types';
87
import { NewTrustedApp, TrustedApp } from '../../../../../common/endpoint/types/trusted_apps';
98
import { AsyncResourceState } from '.';
109

@@ -23,24 +22,6 @@ export interface TrustedAppsListData {
2322
totalItemsCount: number;
2423
}
2524

26-
/** Store State when an API request has been sent to create a new trusted app entry */
27-
export interface TrustedAppCreatePending {
28-
type: 'pending';
29-
data: NewTrustedApp;
30-
}
31-
32-
/** Store State when creation of a new Trusted APP entry was successful */
33-
export interface TrustedAppCreateSuccess {
34-
type: 'success';
35-
data: TrustedApp;
36-
}
37-
38-
/** Store State when creation of a new Trusted App Entry failed */
39-
export interface TrustedAppCreateFailure {
40-
type: 'failure';
41-
data: ServerApiError;
42-
}
43-
4425
export type ViewType = 'list' | 'grid';
4526

4627
export interface TrustedAppsListPageLocation {
@@ -60,11 +41,14 @@ export interface TrustedAppsListPageState {
6041
confirmed: boolean;
6142
submissionResourceState: AsyncResourceState;
6243
};
63-
createView:
64-
| undefined
65-
| TrustedAppCreatePending
66-
| TrustedAppCreateSuccess
67-
| TrustedAppCreateFailure;
44+
creationDialog: {
45+
formState?: {
46+
entry: NewTrustedApp;
47+
isValid: boolean;
48+
};
49+
confirmed: boolean;
50+
submissionResourceState: AsyncResourceState<TrustedApp>;
51+
};
6852
location: TrustedAppsListPageLocation;
6953
active: boolean;
7054
}

x-pack/plugins/security_solution/public/management/pages/trusted_apps/state/type_guards.ts

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,50 +4,21 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import {
8-
TrustedAppCreatePending,
9-
TrustedAppsListPageState,
10-
TrustedAppCreateFailure,
11-
TrustedAppCreateSuccess,
12-
} from './trusted_apps_list_page_state';
137
import {
148
ConditionEntry,
159
ConditionEntryField,
16-
Immutable,
1710
MacosLinuxConditionEntry,
1811
WindowsConditionEntry,
1912
} from '../../../../../common/endpoint/types';
2013

21-
type CreateViewPossibleStates =
22-
| TrustedAppsListPageState['createView']
23-
| Immutable<TrustedAppsListPageState['createView']>;
24-
25-
export const isTrustedAppCreatePendingState = (
26-
data: CreateViewPossibleStates
27-
): data is TrustedAppCreatePending => {
28-
return data?.type === 'pending';
29-
};
30-
31-
export const isTrustedAppCreateSuccessState = (
32-
data: CreateViewPossibleStates
33-
): data is TrustedAppCreateSuccess => {
34-
return data?.type === 'success';
35-
};
36-
37-
export const isTrustedAppCreateFailureState = (
38-
data: CreateViewPossibleStates
39-
): data is TrustedAppCreateFailure => {
40-
return data?.type === 'failure';
41-
};
42-
4314
export const isWindowsTrustedAppCondition = (
44-
condition: ConditionEntry<ConditionEntryField>
15+
condition: ConditionEntry
4516
): condition is WindowsConditionEntry => {
4617
return condition.field === ConditionEntryField.SIGNER || true;
4718
};
4819

4920
export const isMacosLinuxTrustedAppCondition = (
50-
condition: ConditionEntry<ConditionEntryField>
21+
condition: ConditionEntry
5122
): condition is MacosLinuxConditionEntry => {
5223
return condition.field !== ConditionEntryField.SIGNER;
5324
};

x-pack/plugins/security_solution/public/management/pages/trusted_apps/store/action.ts

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,8 @@
66

77
import { Action } from 'redux';
88

9-
import { TrustedApp } from '../../../../../common/endpoint/types';
10-
import {
11-
AsyncResourceState,
12-
TrustedAppCreateFailure,
13-
TrustedAppCreatePending,
14-
TrustedAppCreateSuccess,
15-
TrustedAppsListData,
16-
} from '../state';
9+
import { NewTrustedApp, TrustedApp } from '../../../../../common/endpoint/types';
10+
import { AsyncResourceState, TrustedAppsListData } from '../state';
1711

1812
export type TrustedAppsListDataOutdated = Action<'trustedAppsListDataOutdated'>;
1913

@@ -38,20 +32,27 @@ export type TrustedAppDeletionDialogConfirmed = Action<'trustedAppDeletionDialog
3832

3933
export type TrustedAppDeletionDialogClosed = Action<'trustedAppDeletionDialogClosed'>;
4034

41-
export interface UserClickedSaveNewTrustedAppButton {
42-
type: 'userClickedSaveNewTrustedAppButton';
43-
payload: TrustedAppCreatePending;
44-
}
35+
export type TrustedAppCreationSubmissionResourceStateChanged = ResourceStateChanged<
36+
'trustedAppCreationSubmissionResourceStateChanged',
37+
TrustedApp
38+
>;
4539

46-
export interface ServerReturnedCreateTrustedAppSuccess {
47-
type: 'serverReturnedCreateTrustedAppSuccess';
48-
payload: TrustedAppCreateSuccess;
49-
}
40+
export type TrustedAppCreationDialogStarted = Action<'trustedAppCreationDialogStarted'> & {
41+
payload: {
42+
entry: NewTrustedApp;
43+
};
44+
};
5045

51-
export interface ServerReturnedCreateTrustedAppFailure {
52-
type: 'serverReturnedCreateTrustedAppFailure';
53-
payload: TrustedAppCreateFailure;
54-
}
46+
export type TrustedAppCreationDialogFormStateUpdated = Action<'trustedAppCreationDialogFormStateUpdated'> & {
47+
payload: {
48+
entry: NewTrustedApp;
49+
isValid: boolean;
50+
};
51+
};
52+
53+
export type TrustedAppCreationDialogConfirmed = Action<'trustedAppCreationDialogConfirmed'>;
54+
55+
export type TrustedAppCreationDialogClosed = Action<'trustedAppCreationDialogClosed'>;
5556

5657
export type TrustedAppsPageAction =
5758
| TrustedAppsListDataOutdated
@@ -60,6 +61,8 @@ export type TrustedAppsPageAction =
6061
| TrustedAppDeletionDialogStarted
6162
| TrustedAppDeletionDialogConfirmed
6263
| TrustedAppDeletionDialogClosed
63-
| UserClickedSaveNewTrustedAppButton
64-
| ServerReturnedCreateTrustedAppSuccess
65-
| ServerReturnedCreateTrustedAppFailure;
64+
| TrustedAppCreationSubmissionResourceStateChanged
65+
| TrustedAppCreationDialogStarted
66+
| TrustedAppCreationDialogFormStateUpdated
67+
| TrustedAppCreationDialogConfirmed
68+
| TrustedAppCreationDialogClosed;
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import {
8+
ConditionEntry,
9+
ConditionEntryField,
10+
NewTrustedApp,
11+
OperatingSystem,
12+
} from '../../../../../common/endpoint/types';
13+
14+
import { MANAGEMENT_DEFAULT_PAGE, MANAGEMENT_DEFAULT_PAGE_SIZE } from '../../../common/constants';
15+
16+
import { TrustedAppsListPageState } from '../state';
17+
18+
export const defaultConditionEntry = (): ConditionEntry<ConditionEntryField.HASH> => ({
19+
field: ConditionEntryField.HASH,
20+
operator: 'included',
21+
type: 'match',
22+
value: '',
23+
});
24+
25+
export const defaultNewTrustedApp = (): NewTrustedApp => ({
26+
name: '',
27+
os: OperatingSystem.WINDOWS,
28+
entries: [defaultConditionEntry()],
29+
description: '',
30+
});
31+
32+
export const initialDeletionDialogState = (): TrustedAppsListPageState['deletionDialog'] => ({
33+
confirmed: false,
34+
submissionResourceState: { type: 'UninitialisedResourceState' },
35+
});
36+
37+
export const initialCreationDialogState = (): TrustedAppsListPageState['creationDialog'] => ({
38+
confirmed: false,
39+
submissionResourceState: { type: 'UninitialisedResourceState' },
40+
});
41+
42+
export const initialTrustedAppsPageState = (): TrustedAppsListPageState => ({
43+
listView: {
44+
listResourceState: { type: 'UninitialisedResourceState' },
45+
freshDataTimestamp: Date.now(),
46+
},
47+
deletionDialog: initialDeletionDialogState(),
48+
creationDialog: initialCreationDialogState(),
49+
location: {
50+
page_index: MANAGEMENT_DEFAULT_PAGE,
51+
page_size: MANAGEMENT_DEFAULT_PAGE_SIZE,
52+
show: undefined,
53+
view_type: 'grid',
54+
},
55+
active: false,
56+
});

x-pack/plugins/security_solution/public/management/pages/trusted_apps/store/middleware.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ import {
2121

2222
import { TrustedAppsService } from '../service';
2323
import { Pagination, TrustedAppsListPageState } from '../state';
24-
import { initialTrustedAppsPageState, trustedAppsPageReducer } from './reducer';
24+
import { initialTrustedAppsPageState } from './builders';
25+
import { trustedAppsPageReducer } from './reducer';
2526
import { createTrustedAppsPageMiddleware } from './middleware';
2627

2728
const initialNow = 111111;

0 commit comments

Comments
 (0)