Skip to content

Commit

Permalink
Merge branch 'main' into user-internal-repository-for-so-access
Browse files Browse the repository at this point in the history
  • Loading branch information
hop-dev committed Feb 1, 2022
2 parents 8539406 + fd82fea commit 2949c49
Show file tree
Hide file tree
Showing 144 changed files with 4,311 additions and 4,479 deletions.
12 changes: 12 additions & 0 deletions x-pack/plugins/cases/public/components/case_view/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ export const CHANGED_FIELD = i18n.translate('xpack.cases.caseView.actionLabel.ch
defaultMessage: 'changed',
});

export const ENABLED_SETTING = i18n.translate('xpack.cases.caseView.actionLabel.enabledSetting', {
defaultMessage: 'enabled',
});

export const DISABLED_SETTING = i18n.translate('xpack.cases.caseView.actionLabel.disableSetting', {
defaultMessage: 'disabled',
});

export const SELECTED_THIRD_PARTY = (thirdParty: string) =>
i18n.translate('xpack.cases.caseView.actionLabel.selectedThirdParty', {
values: {
Expand Down Expand Up @@ -119,6 +127,10 @@ export const SYNC_ALERTS = i18n.translate('xpack.cases.caseView.syncAlertsLabel'
defaultMessage: `Sync alerts`,
});

export const SYNC_ALERTS_LC = i18n.translate('xpack.cases.caseView.syncAlertsLowercaseLabel', {
defaultMessage: `sync alerts`,
});

export const DOES_NOT_EXIST_TITLE = i18n.translate('xpack.cases.caseView.doesNotExist.title', {
defaultMessage: 'This case does not exist',
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { createCommentUserActionBuilder } from './comment/comment';
import { createConnectorUserActionBuilder } from './connector';
import { createDescriptionUserActionBuilder } from './description';
import { createPushedUserActionBuilder } from './pushed';
import { createSettingsUserActionBuilder } from './settings';
import { createStatusUserActionBuilder } from './status';
import { createTagsUserActionBuilder } from './tags';
import { createTitleUserActionBuilder } from './title';
Expand All @@ -22,4 +23,5 @@ export const builderMap: UserActionBuilderMap = {
pushed: createPushedUserActionBuilder,
comment: createCommentUserActionBuilder,
description: createDescriptionUserActionBuilder,
settings: createSettingsUserActionBuilder,
};
65 changes: 33 additions & 32 deletions x-pack/plugins/cases/public/components/user_actions/common.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,37 +51,38 @@ export const createCommonUpdateUserActionBuilder = ({
label,
icon,
handleOutlineComment,
}: BuilderArgs): ReturnType<UserActionBuilder> => ({
// TODO: Fix this manually. Issue #123375
// eslint-disable-next-line react/display-name
build: () => [
{
username: (
<UserActionUsernameWithAvatar
username={userAction.createdBy.username}
fullName={userAction.createdBy.fullName}
/>
),
type: 'update' as const,
event: label,
'data-test-subj': `${userAction.type}-${userAction.action}-action-${userAction.actionId}`,
timestamp: <UserActionTimestamp createdAt={userAction.createdAt} />,
timelineIcon: icon,
actions: (
<EuiFlexGroup responsive={false}>
<EuiFlexItem grow={false}>
<UserActionCopyLink id={userAction.actionId} />
</EuiFlexItem>
{showMoveToReference(userAction.action, userAction.commentId) && (
}: BuilderArgs): ReturnType<UserActionBuilder> => {
return {
// eslint-disable-next-line react/display-name
build: () => [
{
username: (
<UserActionUsernameWithAvatar
username={userAction.createdBy.username}
fullName={userAction.createdBy.fullName}
/>
),
type: 'update' as const,
event: label,
'data-test-subj': `${userAction.type}-${userAction.action}-action-${userAction.actionId}`,
timestamp: <UserActionTimestamp createdAt={userAction.createdAt} />,
timelineIcon: icon,
actions: (
<EuiFlexGroup responsive={false}>
<EuiFlexItem grow={false}>
<UserActionMoveToReference
id={userAction.commentId}
outlineComment={handleOutlineComment}
/>
<UserActionCopyLink id={userAction.actionId} />
</EuiFlexItem>
)}
</EuiFlexGroup>
),
},
],
});
{showMoveToReference(userAction.action, userAction.commentId) && (
<EuiFlexItem grow={false}>
<UserActionMoveToReference
id={userAction.commentId}
outlineComment={handleOutlineComment}
/>
</EuiFlexItem>
)}
</EuiFlexGroup>
),
},
],
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { SupportedUserActionTypes } from './types';

export const DRAFT_COMMENT_STORAGE_ID = 'xpack.cases.commentDraft';

export const UNSUPPORTED_ACTION_TYPES = ['create_case', 'delete_case', 'settings'] as const;
export const UNSUPPORTED_ACTION_TYPES = ['create_case', 'delete_case'] as const;
export const SUPPORTED_ACTION_TYPES: SupportedUserActionTypes[] = Object.keys(
omit(ActionTypes, UNSUPPORTED_ACTION_TYPES)
) as SupportedUserActionTypes[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe('helpers', () => {
['tags', true],
['title', true],
['status', true],
['settings', false],
['settings', true],
['create_case', false],
['delete_case', false],
];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { EuiCommentList } from '@elastic/eui';
import React from 'react';
import { Actions } from '../../../common/api';
import { AppMockRenderer, createAppMockRenderer } from '../../common/mock';
import { getUserAction } from '../../containers/mock';
import { getMockBuilderArgs } from './mock';
import { createSettingsUserActionBuilder } from './settings';

jest.mock('../../common/lib/kibana');
jest.mock('../../common/navigation/hooks');

describe('createStatusUserActionBuilder ', () => {
const builderArgs = getMockBuilderArgs();
let appMock: AppMockRenderer;

beforeEach(() => {
appMock = createAppMockRenderer();
jest.clearAllMocks();
});

const tests = [
[false, 'disabled'],
[true, 'enabled'],
];

it.each(tests)(
'renders correctly when changed setting sync-alerts to %s',
async (syncAlerts, label) => {
const userAction = getUserAction('settings', Actions.update, {
payload: { settings: { syncAlerts } },
});
const builder = createSettingsUserActionBuilder({
...builderArgs,
userAction,
});

const createdUserAction = builder.build();
const result = appMock.render(<EuiCommentList comments={createdUserAction} />);

expect(result.getByTestId('settings-update-action-settings-update')).toBeTruthy();
expect(result.getByText(`${label} sync alerts`)).toBeTruthy();
}
);
});
43 changes: 43 additions & 0 deletions x-pack/plugins/cases/public/components/user_actions/settings.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { ReactNode } from 'react';
import { SettingsUserAction } from '../../../common/api';
import { UserActionBuilder, UserActionResponse } from './types';

import { createCommonUpdateUserActionBuilder } from './common';
import { DISABLED_SETTING, ENABLED_SETTING, SYNC_ALERTS_LC } from './translations';

function getSettingsLabel(userAction: UserActionResponse<SettingsUserAction>): ReactNode {
if (userAction.payload.settings.syncAlerts) {
return `${ENABLED_SETTING} ${SYNC_ALERTS_LC}`;
} else {
return `${DISABLED_SETTING} ${SYNC_ALERTS_LC}`;
}
}

export const createSettingsUserActionBuilder: UserActionBuilder = ({
userAction,
handleOutlineComment,
}) => ({
build: () => {
const action = userAction as UserActionResponse<SettingsUserAction>;
if (action?.payload?.settings?.syncAlerts !== undefined) {
const commonBuilder = createCommonUpdateUserActionBuilder({
userAction,
handleOutlineComment,
label: getSettingsLabel(action),
icon: 'gear',
});

return commonBuilder.build();
}

// if new settings are introduced. they won't be rendered
return [];
},
});
12 changes: 12 additions & 0 deletions x-pack/plugins/fleet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,15 @@ $ yarn storybook fleet
```

Write stories by creating `.stories.tsx` files colocated with the components you're working on. Consult the [Storybook docs](https://storybook.js.org/docs/react/get-started/introduction) for more information.

## Dependent applications using Fleet

The projects below are dependent on Fleet, most using Fleet API as well. In case of breaking changes in Fleet functionality/API, the project owners have to be notified to make sure they can plan for the necessary changes on their end to avoid unexpected break in functionality.

* [Elastic Agent](https://github.com/elastic/beats/blob/master/x-pack/elastic-agent): uses Fleet API to enroll agents. [See here](https://github.com/elastic/beats/blob/master/x-pack/elastic-agent/pkg/agent/cmd/container.go)
* [Fleet Server](https://github.com/elastic/fleet-server): uses Fleet API to enroll fleet server [See here](https://github.com/elastic/fleet-server/blob/master/cmd/fleet/router.go)
* [elastic-package](https://github.com/elastic/elastic-package): command line tool, uses Fleet with docker compose and Fleet API [See here](https://github.com/elastic/elastic-package/tree/master/internal/kibana)
* [Azure VM extension](https://github.com/elastic/azure-vm-extension): automation tool for Azure VMs, uses Fleet API to enroll agents [See here](https://github.com/elastic/azure-vm-extension/blob/main/src/handler/windows/scripts/enable.ps1)
* [e2e-testing](https://github.com/elastic/e2e-testing): internal project that runs Fleet and tests Fleet API [See here](https://github.com/elastic/e2e-testing/tree/main/internal/kibana)
* [observability-test-environments](https://github.com/elastic/observability-test-environments): internal project, uses Fleet API [See here](https://github.com/elastic/observability-test-environments/blob/master/ansible/tasks-fleet-config.yml)
* [ECK](https://github.com/elastic/cloud-on-k8s): Elastic Cloud on Kubernetes, orchestrates Elastic Stack applications, including Kibana with Fleet (no direct dependency, has examples that include Fleet config) [See here](https://github.com/elastic/cloud-on-k8s/blob/main/docs/orchestrating-elastic-stack-applications/agent-fleet.asciidoc)
22 changes: 3 additions & 19 deletions x-pack/plugins/fleet/common/constants/epm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,9 @@ export const STANDALONE_RUN_INSTRUCTIONS_WINDOWS = '.\\elastic-agent.exe install

/*
Package rules:
| | unremovablePackages | defaultPackages | autoUpdatePackages |
|---------------|:---------------------:|:---------------:|:------------------:|
| Removable | ❌ | ✔️ | ✔️ |
| Auto-installs | ❌ | ✔️ | ❌ |
| Auto-updates | ❌ | ✔️ | ✔️ |
`endpoint` is a special package. It needs to autoupdate, it needs to _not_ be
removable, but it doesn't install by default. Following the table, it needs to
be in `unremovablePackages` and in `autoUpdatePackages`, but not in
`defaultPackages`.
| | autoUpdatePackages |
|---------------|:------------------:|
| Auto-updates | ✔️ |
We also define "auto upgrade policies" packages below. These are packages that are considered "stack-aligned"
Expand All @@ -42,15 +35,6 @@ in their custom policy editor implementations.
*/

export const unremovablePackages = [
FLEET_SYSTEM_PACKAGE,
FLEET_ELASTIC_AGENT_PACKAGE,
FLEET_SERVER_PACKAGE,
FLEET_ENDPOINT_PACKAGE,
];

export const defaultPackages = unremovablePackages.filter((p) => p !== FLEET_ENDPOINT_PACKAGE);

export const autoUpdatePackages = [
FLEET_ENDPOINT_PACKAGE,
FLEET_APM_PACKAGE,
Expand Down
71 changes: 2 additions & 69 deletions x-pack/plugins/fleet/common/constants/preconfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,8 @@
*/

import { uniqBy } from 'lodash';
import uuidv5 from 'uuid/v5';

import type { PreconfiguredAgentPolicy } from '../types';

import {
defaultPackages,
FLEET_SYSTEM_PACKAGE,
FLEET_SERVER_PACKAGE,
autoUpdatePackages,
monitoringTypes,
autoUpgradePoliciesPackages,
} from './epm';
import { autoUpdatePackages, autoUpgradePoliciesPackages } from './epm';

// UUID v5 values require a namespace. We use UUID v5 for some of our preconfigured ID values.
export const UUID_V5_NAMESPACE = 'dde7c2de-1370-4c19-9975-b473d0e03508';
Expand All @@ -27,63 +17,6 @@ export const PRECONFIGURATION_DELETION_RECORD_SAVED_OBJECT_TYPE =

export const PRECONFIGURATION_LATEST_KEYWORD = 'latest';

type PreconfiguredAgentPolicyWithDefaultInputs = Omit<
PreconfiguredAgentPolicy,
'package_policies'
> & {
package_policies: Array<Omit<PreconfiguredAgentPolicy['package_policies'][0], 'inputs'>>;
};

export const DEFAULT_AGENT_POLICY_ID_SEED = 'default-agent-policy';
export const DEFAULT_SYSTEM_PACKAGE_POLICY_ID = 'default-system-policy';

export const DEFAULT_AGENT_POLICY: PreconfiguredAgentPolicyWithDefaultInputs = {
id: uuidv5(DEFAULT_AGENT_POLICY_ID_SEED, UUID_V5_NAMESPACE),
name: 'Default policy',
namespace: 'default',
description: 'Default agent policy created by Kibana',
package_policies: [
{
id: DEFAULT_SYSTEM_PACKAGE_POLICY_ID,
name: `${FLEET_SYSTEM_PACKAGE}-1`,
package: {
name: FLEET_SYSTEM_PACKAGE,
},
},
],
is_default: true,
is_managed: false,
monitoring_enabled: monitoringTypes,
};

export const DEFAULT_FLEET_SERVER_POLICY_ID = 'default-fleet-server-agent-policy';
export const DEFAULT_FLEET_SERVER_AGENT_POLICY_ID_SEED = 'default-fleet-server';

export const DEFAULT_FLEET_SERVER_AGENT_POLICY: PreconfiguredAgentPolicyWithDefaultInputs = {
id: uuidv5(DEFAULT_FLEET_SERVER_AGENT_POLICY_ID_SEED, UUID_V5_NAMESPACE),
name: 'Default Fleet Server policy',
namespace: 'default',
description: 'Default Fleet Server agent policy created by Kibana',
package_policies: [
{
id: DEFAULT_FLEET_SERVER_POLICY_ID,
name: `${FLEET_SERVER_PACKAGE}-1`,
package: {
name: FLEET_SERVER_PACKAGE,
},
},
],
is_default: false,
is_default_fleet_server: true,
is_managed: false,
monitoring_enabled: monitoringTypes,
};

export const DEFAULT_PACKAGES = defaultPackages.map((name) => ({
name,
version: PRECONFIGURATION_LATEST_KEYWORD,
}));

export const AUTO_UPDATE_PACKAGES = autoUpdatePackages.map((name) => ({
name,
version: PRECONFIGURATION_LATEST_KEYWORD,
Expand All @@ -97,7 +30,7 @@ export const AUTO_UPGRADE_POLICIES_PACKAGES = autoUpgradePoliciesPackages.map((n

// Controls whether the `Keep Policies up to date` setting is exposed to the user
export const KEEP_POLICIES_UP_TO_DATE_PACKAGES = uniqBy(
[...AUTO_UPGRADE_POLICIES_PACKAGES, ...DEFAULT_PACKAGES, ...AUTO_UPDATE_PACKAGES],
[...AUTO_UPGRADE_POLICIES_PACKAGES, ...AUTO_UPDATE_PACKAGES],
({ name }) => name
);

Expand Down
7 changes: 6 additions & 1 deletion x-pack/plugins/fleet/common/openapi/bundled.json
Original file line number Diff line number Diff line change
Expand Up @@ -3002,9 +3002,14 @@
]
},
"is_default": {
"type": "boolean"
"type": "boolean",
"deprecated": true
},
"is_default_fleet_server": {
"type": "boolean",
"deprecated": true
},
"has_fleet_server": {
"type": "boolean"
},
"data_output_id": {
Expand Down
4 changes: 4 additions & 0 deletions x-pack/plugins/fleet/common/openapi/bundled.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1850,8 +1850,12 @@ components:
- type: number
is_default:
type: boolean
deprecated: true
is_default_fleet_server:
type: boolean
deprecated: true
has_fleet_server:
type: boolean
data_output_id:
type: string
monitoring_output_id:
Expand Down
Loading

0 comments on commit 2949c49

Please sign in to comment.