Skip to content

Commit

Permalink
Add upload command to list of console commands
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-tavares committed May 9, 2023
1 parent d8adbf1 commit ee91d9d
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 2 deletions.
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
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import React, { memo } from 'react';
import type { ActionRequestComponentProps } from '../types';

export const UploadActionResult = memo<
ActionRequestComponentProps<{
file: File;
overwrite?: boolean;
}>
>((props) => {
return <div>{'UploadActionResult placeholder'}</div>;
});
UploadActionResult.displayName = 'UploadActionResult';
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
*/

import { i18n } from '@kbn/i18n';
import { UploadActionResult } from '../command_render_components/upload_action';
import { ArgumentFileSelector } from '../../console_argument_selectors';
import type { ParsedArgData } from '../../console/service/types';
import { ExperimentalFeaturesService } from '../../../../common/experimental_features_service';
import type {
Expand Down Expand Up @@ -139,8 +141,11 @@ export const getEndpointConsoleCommands = ({
endpointCapabilities: ImmutableArray<string>;
endpointPrivileges: EndpointPrivileges;
}): CommandDefinition[] => {
const isGetFileEnabled = ExperimentalFeaturesService.get().responseActionGetFileEnabled;
const isExecuteEnabled = ExperimentalFeaturesService.get().responseActionExecuteEnabled;
const featureFlags = ExperimentalFeaturesService.get();

const isGetFileEnabled = featureFlags.responseActionGetFileEnabled;
const isExecuteEnabled = featureFlags.responseActionExecuteEnabled;
const isUploadEnabled = featureFlags.responseActionUploadEnabled;

const doesEndpointSupportCommand = (commandName: ConsoleResponseActionCommands) => {
const responderCapability =
Expand Down Expand Up @@ -484,5 +489,69 @@ export const getEndpointConsoleCommands = ({
}),
});
}

// `upload` command
// planned for 8.9
if (isUploadEnabled) {
consoleCommands.push({
name: 'upload',
about: getCommandAboutInfo({
aboutInfo: i18n.translate('xpack.securitySolution.endpointConsoleCommands.upload.about', {
defaultMessage: 'Upload a file to the host',
}),
isSupported: doesEndpointSupportCommand('upload'),
}),
RenderComponent: UploadActionResult,
meta: {
endpointId: endpointAgentId,
capabilities: endpointCapabilities,
privileges: endpointPrivileges,
},
exampleUsage: 'upload --file --overwrite --comment "script to fix registry"',
exampleInstruction: ENTER_OR_ADD_COMMENT_ARG_INSTRUCTION,
validate: capabilitiesAndPrivilegesValidator,
mustHaveArgs: true,
args: {
file: {
required: true,
allowMultiples: false,
about: i18n.translate(
'xpack.securitySolution.endpointConsoleCommands.upload.args.file.about',
{
defaultMessage: 'The file that will be sent to the host',
}
),
mustHaveValue: true,
SelectorComponent: ArgumentFileSelector,
},
overwrite: {
required: false,
allowMultiples: false,
about: i18n.translate(
'xpack.securitySolution.endpointConsoleCommands.upload.args.overwrite.about',
{
defaultMessage: 'Overwrite the file on the host if it already exists',
}
),
mustHaveValue: false,
},
comment: {
required: false,
allowMultiples: false,
mustHaveValue: 'non-empty-string',
about: COMMENT_ARG_ABOUT,
},
},
helpGroupLabel: HELP_GROUPS.responseActions.label,
helpGroupPosition: HELP_GROUPS.responseActions.position,
helpCommandPosition: 7,
helpDisabled: !doesEndpointSupportCommand('upload'),
helpHidden: !getRbacControl({
commandName: 'upload',
privileges: endpointPrivileges,
}),
});
}

return consoleCommands;
};

0 comments on commit ee91d9d

Please sign in to comment.