rename explain-sigma-rules to sigma-rule-details
This commit is contained in:
parent
519c87fb04
commit
657a33a189
7 changed files with 96 additions and 95 deletions
|
@ -1,27 +1,34 @@
|
|||
/**
|
||||
* sigma_details_handler.js
|
||||
*
|
||||
* Handles Sigma rule details requests from Slack commands
|
||||
* Handles Sigma rule details requests from both Slack commands and CLI
|
||||
* Processes requests for rule explanations
|
||||
*/
|
||||
const logger = require('../../utils/logger');
|
||||
const { handleError } = require('../../utils/error_handler');
|
||||
const { explainSigmaRule } = require('../../services/sigma/sigma_details_service');
|
||||
const { processRuleDetails } = require('./actions/sigma_action_core');
|
||||
const FILE_NAME = 'sigma_details_handler.js';
|
||||
const { getSigmaRuleDetails, getSigmaRuleYaml } = require('../../services/sigma/sigma_details_service');
|
||||
const { getSigmaRuleDetailsBlocks } = require('../../blocks/sigma/sigma_details_block');
|
||||
const { formatSigmaDetails } = require('../../utils/cli_formatters');
|
||||
|
||||
const { getFileName } = require('../../utils/file_utils');
|
||||
const FILE_NAME = getFileName(__filename);
|
||||
|
||||
/**
|
||||
* Handle the sigma-details command for Sigma rules
|
||||
*
|
||||
* @param {Object} command - The Slack command object
|
||||
* @param {Function} respond - Function to send response back to Slack
|
||||
* @param {Object} command - The Slack command or CLI command object
|
||||
* @param {Function} respond - Function to send response back to Slack or CLI
|
||||
*/
|
||||
const handleCommand = async (command, respond) => {
|
||||
try {
|
||||
logger.debug(`${FILE_NAME}: Processing sigma-details command: ${JSON.stringify(command.text)}`);
|
||||
logger.debug(`${FILE_NAME}: Processing sigma-details command: ${command.text}`);
|
||||
|
||||
if (!command || !command.text) {
|
||||
logger.warn(`${FILE_NAME}: Empty command received for sigma-details`);
|
||||
await respond('Invalid command. Usage: /sigma-details [id]');
|
||||
await respond({
|
||||
text: 'Invalid command. Usage: /sigma-details [id] or "details sigma [id]"',
|
||||
response_type: 'ephemeral'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -30,7 +37,10 @@ const handleCommand = async (command, respond) => {
|
|||
|
||||
if (!ruleId) {
|
||||
logger.warn(`${FILE_NAME}: Missing rule ID in sigma-details command`);
|
||||
await respond('Invalid command: missing rule ID. Usage: /sigma-details [id]');
|
||||
await respond({
|
||||
text: 'Invalid command: missing rule ID. Usage: /sigma-details [id] or "details sigma [id]"',
|
||||
response_type: 'ephemeral'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -40,14 +50,44 @@ const handleCommand = async (command, respond) => {
|
|||
response_type: 'ephemeral'
|
||||
});
|
||||
|
||||
// Use the shared processRuleDetails function from action handlers
|
||||
await processRuleDetails(ruleId, respond, false, 'in_channel');
|
||||
// Get the rule explanation
|
||||
const sigmaRuleDetailsResult = await getSigmaRuleDetails(ruleId);
|
||||
|
||||
if (!sigmaRuleDetailsResult.success) {
|
||||
logger.warn(`${FILE_NAME}: Failed to explain rule ${ruleId}: ${sigmaRuleDetailsResult.message}`);
|
||||
await respond({
|
||||
text: `Error: ${sigmaRuleDetailsResult.message}`,
|
||||
response_type: 'ephemeral'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// For Slack responses, generate Block Kit blocks
|
||||
let blocks;
|
||||
try {
|
||||
// This is for Slack - get the Block Kit UI components
|
||||
blocks = getSigmaRuleDetailsBlocks(sigmaRuleDetailsResult.explanation);
|
||||
} catch (blockError) {
|
||||
await handleError(blockError, `${FILE_NAME}: Block generation`, respond, {
|
||||
responseType: 'ephemeral',
|
||||
customMessage: 'Error generating rule details view'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// Return the response with both blocks for Slack and responseData for CLI
|
||||
await respond({
|
||||
blocks: blocks, // For Slack
|
||||
responseData: sigmaRuleDetailsResult.explanation, // For CLI
|
||||
response_type: 'in_channel'
|
||||
});
|
||||
} catch (error) {
|
||||
await handleError(error, `${FILE_NAME}: Details command handler`, respond, {
|
||||
responseType: 'ephemeral'
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
handleCommand
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue