Skip to content

Commit

Permalink
Merge branch 'main' into custom-fields-oas
Browse files Browse the repository at this point in the history
  • Loading branch information
lcawl committed Oct 23, 2023
2 parents a5f32dd + 3587c20 commit 7217882
Show file tree
Hide file tree
Showing 18 changed files with 30 additions and 51 deletions.
4 changes: 2 additions & 2 deletions x-pack/plugins/actions/server/sub_action_framework/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ plugins.actions.registerSubActionConnectorType({
name: 'Test: Sub action connector',
minimumLicenseRequired: 'platinum' as const,
schema: { config: TestConfigSchema, secrets: TestSecretsSchema },
Service: TestSubActionConnector,
getService: (params) => new TestSubActionConnector(params),
renderParameterTemplates: renderTestTemplate
});
```
Expand All @@ -368,6 +368,6 @@ plugins.actions.registerSubActionConnectorType({
minimumLicenseRequired: 'platinum' as const,
schema: { config: TestConfigSchema, secrets: TestSecretsSchema },
validators: [{type: ValidatorType.CONFIG, validate: urlAllowListValidator('url')}]
Service: TestSubActionConnector,
getService: (params) => new TestSubActionConnector(params),
});
```
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
TestSecrets,
TestExecutor,
} from './mocks';
import { IService } from './types';
import { IService, ServiceParams } from './types';

describe('Executor', () => {
const actionId = 'test-action-id';
Expand All @@ -40,7 +40,8 @@ describe('Executor', () => {
config: TestConfigSchema,
secrets: TestSecretsSchema,
},
Service,
getService: (serviceParams: ServiceParams<TestConfig, TestSecrets>) =>
new Service(serviceParams),
};

return buildExecutor({ configurationUtilities: mockedActionsConfig, logger, connector });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const buildExecutor = <
const subAction = params.subAction;
const subActionParams = params.subActionParams;

const service = new connector.Service({
const service = connector.getService({
connector: { id: actionId, type: connector.id },
config,
secrets,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
TestSubActionConnector,
} from './mocks';
import { register } from './register';
import { ServiceParams } from './types';

describe('Registration', () => {
const renderedVariables = { body: '' };
Expand All @@ -30,7 +31,8 @@ describe('Registration', () => {
config: TestConfigSchema,
secrets: TestSecretsSchema,
},
Service: TestSubActionConnector,
getService: (serviceParams: ServiceParams<TestConfig, TestSecrets>) =>
new TestSubActionConnector(serviceParams),
renderParameterTemplates: mockRenderParameterTemplates,
};

Expand Down
17 changes: 1 addition & 16 deletions x-pack/plugins/actions/server/sub_action_framework/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,11 @@ import { PublicMethodsOf } from '@kbn/utility-types';
import { Logger } from '@kbn/core/server';
import { ActionsConfigurationUtilities } from '../actions_config';
import { ActionTypeRegistry } from '../action_type_registry';
import { SubActionConnector } from './sub_action_connector';
import { CaseConnector } from './case';
import { ActionTypeConfig, ActionTypeSecrets } from '../types';
import { buildExecutor } from './executor';
import { ExecutorParams, SubActionConnectorType, IService } from './types';
import { ExecutorParams, SubActionConnectorType } from './types';
import { buildValidators } from './validators';

const validateService = <Config, Secrets>(Service: IService<Config, Secrets>) => {
if (
!(Service.prototype instanceof CaseConnector) &&
!(Service.prototype instanceof SubActionConnector)
) {
throw new Error(
'Service must be extend one of the abstract classes: SubActionConnector or CaseConnector'
);
}
};

export const register = <Config extends ActionTypeConfig, Secrets extends ActionTypeSecrets>({
actionTypeRegistry,
connector,
Expand All @@ -38,8 +25,6 @@ export const register = <Config extends ActionTypeConfig, Secrets extends Action
connector: SubActionConnectorType<Config, Secrets>;
logger: Logger;
}) => {
validateService(connector.Service);

const validators = buildValidators<Config, Secrets>({ connector, configurationUtilities });
const executor = buildExecutor({
connector,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export interface SubActionConnectorType<Config, Secrets> {
secrets: Type<Secrets>;
};
validators?: Array<ConfigValidator<Config> | SecretsValidator<Secrets>>;
Service: IService<Config, Secrets>;
getService: (params: ServiceParams<Config, Secrets>) => SubActionConnector<Config, Secrets>;
renderParameterTemplates?: RenderParameterTemplates<ExecutorParams>;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
TestSecrets,
TestSubActionConnector,
} from './mocks';
import { IService, SubActionConnectorType, ValidatorType } from './types';
import { IService, ServiceParams, SubActionConnectorType, ValidatorType } from './types';
import { buildValidators } from './validators';

describe('Validators', () => {
Expand All @@ -30,7 +30,8 @@ describe('Validators', () => {
config: TestConfigSchema,
secrets: TestSecretsSchema,
},
Service,
getService: (serviceParams: ServiceParams<TestConfig, TestSecrets>) =>
new Service(serviceParams),
};

return buildValidators({ configurationUtilities: mockedActionsConfig, connector });
Expand Down Expand Up @@ -59,7 +60,8 @@ describe('Validators', () => {
validator: secretsValidator,
},
],
Service,
getService: (serviceParams: ServiceParams<TestConfig, TestSecrets>) =>
new Service(serviceParams),
};

return {
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/security_solution/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ export const DEFAULT_INTERVAL_TYPE = 'manual' as const;
export const DEFAULT_INTERVAL_VALUE = 300000 as const; // ms
export const DEFAULT_TIMEPICKER_QUICK_RANGES = 'timepicker:quickRanges' as const;
export const SCROLLING_DISABLED_CLASS_NAME = 'scrolling-disabled' as const;
export const FULL_SCREEN_TOGGLED_CLASS_NAME = 'fullScreenToggled' as const;
export const NO_ALERT_INDEX = 'no-alert-index-049FC71A-4C2C-446F-9901-37XMC5024C51' as const;
export const ENDPOINT_METADATA_INDEX = 'metrics-endpoint.metadata-*' as const;
export const ENDPOINT_METRICS_INDEX = '.ds-metrics-endpoint.metrics-*' as const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import { DEFAULT_ACTION_BUTTON_WIDTH } from '.';
import { EventsTh, EventsThContent } from '../../../timelines/components/timeline/styles';
import { StatefulRowRenderersBrowser } from '../../../timelines/components/row_renderers_browser';
import { EXIT_FULL_SCREEN } from '../exit_full_screen/translations';
import { FULL_SCREEN_TOGGLED_CLASS_NAME } from '../../../../common/constants';
import { EventsSelect } from '../../../timelines/components/timeline/body/column_headers/events_select';
import * as i18n from './translations';

Expand Down Expand Up @@ -243,8 +242,8 @@ const HeaderActionsComponent: React.FC<HeaderActionProps> = ({
? EXIT_FULL_SCREEN
: i18n.FULL_SCREEN
}
className={fullScreen ? FULL_SCREEN_TOGGLED_CLASS_NAME : ''}
color={fullScreen ? 'ghost' : 'primary'}
display={fullScreen ? 'fill' : 'empty'}
color="primary"
data-test-subj={
// a full screen button gets created for timeline and for the host page
// this sets the data-test-subj for each case so that tests can differentiate between them
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import { EuiBadge, EuiDescriptionList, EuiFlexGroup, EuiIcon } from '@elastic/eui';
import styled, { createGlobalStyle, css } from 'styled-components';

import { FULL_SCREEN_TOGGLED_CLASS_NAME } from '../../../../common/constants';

export const SecuritySolutionAppWrapper = styled.div`
display: flex;
flex-direction: column;
Expand Down Expand Up @@ -89,11 +87,6 @@ export const AppGlobalStyle = createGlobalStyle<{
}
}
/* applies a "toggled" button style to the Full Screen button */
.${FULL_SCREEN_TOGGLED_CLASS_NAME} {
${({ theme }) => `background-color: ${theme.eui.euiColorPrimary} !important`};
}
/*
EuiScreenReaderOnly has a default 1px height and width. These extra pixels
were adding additional height to every table row in the alerts table on the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ import { TimelineTabs } from '../../../../../common/types/timeline';
import { useDetailPanel } from '../../side_panel/hooks/use_detail_panel';
import { SourcererScopeName } from '../../../../common/store/sourcerer/model';
import { isFullScreen } from '../body/column_headers';
import {
SCROLLING_DISABLED_CLASS_NAME,
FULL_SCREEN_TOGGLED_CLASS_NAME,
} from '../../../../../common/constants';
import { SCROLLING_DISABLED_CLASS_NAME } from '../../../../../common/constants';
import { FULL_SCREEN } from '../body/column_headers/translations';
import { EXIT_FULL_SCREEN } from '../../../../common/components/exit_full_screen/translations';
import {
Expand Down Expand Up @@ -97,8 +94,8 @@ const NavigationComponent: React.FC<NavigationProps> = ({
? EXIT_FULL_SCREEN
: FULL_SCREEN
}
className={fullScreen ? FULL_SCREEN_TOGGLED_CLASS_NAME : ''}
color={fullScreen ? 'ghost' : 'primary'}
display={fullScreen ? 'fill' : 'empty'}
color="primary"
data-test-subj="full-screen"
iconType="fullScreen"
onClick={toggleFullScreen}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { renderParameterTemplates } from './render';
export const getConnectorType = (): SubActionConnectorType<Config, Secrets> => ({
id: BEDROCK_CONNECTOR_ID,
name: BEDROCK_TITLE,
Service: BedrockConnector,
getService: (params) => new BedrockConnector(params),
schema: {
config: ConfigSchema,
secrets: SecretsSchema,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function getConnectorType(): D3SecurityConnectorType {
id: D3_SECURITY_CONNECTOR_ID,
minimumLicenseRequired: 'gold',
name: D3_SECURITY_TITLE,
Service: D3SecurityConnector,
getService: (params) => new D3SecurityConnector(params),
supportedFeatureIds: [AlertingConnectorFeatureId, SecurityConnectorFeatureId],
schema: {
config: D3SecurityConfigSchema,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { renderParameterTemplates } from './render';
export const getConnectorType = (): SubActionConnectorType<Config, Secrets> => ({
id: OPENAI_CONNECTOR_ID,
name: OPENAI_TITLE,
Service: OpenAIConnector,
getService: (params) => new OpenAIConnector(params),
schema: {
config: ConfigSchema,
secrets: SecretsSchema,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { renderParameterTemplates } from './render_template_variables';

export const getOpsgenieConnectorType = (): SubActionConnectorType<Config, Secrets> => {
return {
Service: OpsgenieConnector,
getService: (params) => new OpsgenieConnector(params),
minimumLicenseRequired: 'platinum',
name: i18n.OPSGENIE_NAME,
id: OpsgenieConnectorTypeId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const getSentinelOneConnectorType = (): SubActionConnectorType<
> => ({
id: SENTINELONE_CONNECTOR_ID,
name: SENTINELONE_TITLE,
Service: SentinelOneConnector,
getService: (params) => new SentinelOneConnector(params),
schema: {
config: SentinelOneConfigSchema,
secrets: SentinelOneSecretsSchema,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { renderParameterTemplates } from './render';
export const getTinesConnectorType = (): SubActionConnectorType<TinesConfig, TinesSecrets> => ({
id: TINES_CONNECTOR_ID,
name: TINES_TITLE,
Service: TinesConnector,
getService: (params) => new TinesConnector(params),
schema: {
config: TinesConfigSchema,
secrets: TinesSecretsSchema,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,14 @@ export const getTestSubActionConnector = (

public async noData() {}
}

return {
id: 'test.sub-action-connector',
name: 'Test: Sub action connector',
minimumLicenseRequired: 'platinum' as const,
supportedFeatureIds: ['alerting'],
schema: { config: TestConfigSchema, secrets: TestSecretsSchema },
Service: TestSubActionConnector,
getService: (params) => new TestSubActionConnector(params),
};
};

Expand All @@ -106,6 +107,6 @@ export const getTestSubActionConnectorWithoutSubActions = (
minimumLicenseRequired: 'platinum' as const,
supportedFeatureIds: ['alerting'],
schema: { config: TestConfigSchema, secrets: TestSecretsSchema },
Service: TestNoSubActions,
getService: (params) => new TestNoSubActions(params),
};
};

0 comments on commit 7217882

Please sign in to comment.