Skip to content

Commit

Permalink
apply comments, fix types and licenseSErvice
Browse files Browse the repository at this point in the history
  • Loading branch information
tomsonpl committed May 5, 2023
1 parent aa32c6d commit 6685338
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 15 deletions.
5 changes: 3 additions & 2 deletions x-pack/plugins/osquery/public/action_results/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ const parametersNotFound =
export const getSkippedQueryError = (error: string) => {
if (error === platinumLicenseRequired) {
return i18n.translate('xpack.osquery.liveQueryActionResults.table.wrongLicenseErrorText', {
defaultMessage: `${platinumLicenseRequired}`,
defaultMessage: 'At least Platinum license is required to use Response Actions.',
});
}

if (error === parametersNotFound) {
return i18n.translate('xpack.osquery.liveQueryActionResults.table.skippedErrorText', {
defaultMessage: `${parametersNotFound}`,
defaultMessage:
"This query hasn't been called due to parameter used and its value not found in the alert.",
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import type { EndpointAuthz } from '../../common/endpoint/types/authz';
import { calculateEndpointAuthz } from '../../common/endpoint/service/authz';
import type { FeatureUsageService } from './services/feature_usage/service';
import type { ExperimentalFeatures } from '../../common/experimental_features';
import type { ActionCreateService } from './services';
import { doesArtifactHaveData } from './services';
import type { actionCreateService } from './services/actions';

Expand Down Expand Up @@ -237,7 +238,7 @@ export class EndpointAppContextService {
return this.startDependencies.messageSigningService;
}

public getActionCreateService(): ReturnType<typeof actionCreateService> {
public getActionCreateService(): ActionCreateService {
if (!this.startDependencies?.actionCreateService) {
throw new EndpointAppContentServicesNotStartedError();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,7 @@ describe('Response actions', () => {
endpointAppContextService.setup(createMockEndpointAppContextServiceSetupContract());
endpointAppContextService.start({
...startContract,
actionCreateService: actionCreateService(
mockScopedClient.asInternalUser,
endpointContext,
licenseService
),
actionCreateService: actionCreateService(mockScopedClient.asInternalUser, endpointContext),
licenseService,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,19 @@ interface CreateActionMetadata {
enableActionsWithErrors?: boolean;
}

export interface ActionCreateService {
createActionFromAlert: (payload: CreateActionPayload) => Promise<ActionDetails>;
createAction: (
payload: CreateActionPayload,
metadata: CreateActionMetadata
) => Promise<ActionDetails>;
}

export const actionCreateService = (
esClient: ElasticsearchClient,
endpointContext: EndpointAppContext,
licenseService: LicenseService
) => {
const createActionFromAlert = async (payload: CreateActionPayload) => {
endpointContext: EndpointAppContext
): ActionCreateService => {
const createActionFromAlert = async (payload: CreateActionPayload): Promise<ActionDetails> => {
return createAction({ ...payload }, { minimumLicenseRequired: 'enterprise' });
};

Expand All @@ -86,6 +93,8 @@ export const actionCreateService = (
endpointContext.service.getFeatureUsageService().notifyUsage(featureKey);
}

const licenseService = endpointContext.service.getLicenseService();

const logger = endpointContext.logFactory.get('hostIsolation');

// fetch the Agent IDs to send the commands to
Expand Down Expand Up @@ -341,11 +350,12 @@ interface CheckForAlertsArgs {
licenseService: LicenseService;
minimumLicenseRequired: LicenseType;
}

const checkForAlertErrors = ({
agents,
licenseService,
minimumLicenseRequired = 'basic',
}: CheckForAlertsArgs) => {
}: CheckForAlertsArgs): string | undefined => {
const licenseError = validateEndpointLicense(licenseService, minimumLicenseRequired);
const agentsError = validateAgents(agents);

Expand Down
3 changes: 1 addition & 2 deletions x-pack/plugins/security_solution/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -506,8 +506,7 @@ export class Plugin implements ISecuritySolutionPlugin {
messageSigningService: plugins.fleet?.messageSigningService,
actionCreateService: actionCreateService(
core.elasticsearch.client.asInternalUser,
this.endpointContext,
licenseService
this.endpointContext
),
});

Expand Down

0 comments on commit 6685338

Please sign in to comment.