Skip to content

Commit

Permalink
fixed bugs and removed console.log
Browse files Browse the repository at this point in the history
Signed-off-by: Riya Saxena <[email protected]>
  • Loading branch information
riysaxen-amzn committed Jun 18, 2024
1 parent ac4b304 commit e8a72d7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
18 changes: 18 additions & 0 deletions public/pages/Correlations/containers/CreateCorrelationRule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ import { NotificationsCallOut } from '../../../../public/components/Notification
import { BrowserServices } from '../../../../public/models/interfaces';
import { ExperimentalBanner } from '../components/ExperimentalBanner';
import { ALERT_SEVERITY_OPTIONS } from '../../CreateDetector/components/ConfigureAlerts/utils/constants';
import uuid from 'uuid';
import { randomUUID } from 'crypto';

export interface CreateCorrelationRuleProps extends DataSourceProps {
indexService: IndexService;
Expand Down Expand Up @@ -357,6 +359,8 @@ export const CreateCorrelationRule: React.FC<CreateCorrelationRuleProps> = (


const submit = async (values: CorrelationRuleModel) => {
const randomTriggerId = uuid();
const randomActionId = uuid();
let error;
if ((error = validateCorrelationRule(values))) {
errorNotificationToast(props.notifications, action, 'rule', error);
Expand All @@ -375,6 +379,20 @@ export const CreateCorrelationRule: React.FC<CreateCorrelationRuleProps> = (
});
}

// Modify or set default values for trigger if present
if (values.trigger) {
// Set default values for ids
values.trigger.id = randomTriggerId;
values.trigger.ids?.push(randomTriggerId);
// Set default values for actions if present
if (values.trigger.actions) {
values.trigger.actions.forEach((action) => {
action.id = randomActionId;
action.name = randomActionId;
});
}
}

if (action === 'Edit') {
await correlationStore.updateCorrelationRule(values as CorrelationRule);
} else {
Expand Down
14 changes: 1 addition & 13 deletions public/store/CorrelationsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { NotificationsStart } from 'opensearch-dashboards/public';
import { errorNotificationToast } from '../utils/helpers';
import { DEFAULT_EMPTY_DATA } from '../utils/constants';
import { DataStore } from './DataStore';
import uuid from 'uuid';

export interface ICorrelationsCache {
[key: string]: CorrelationRule[];
Expand Down Expand Up @@ -57,7 +56,6 @@ export class CorrelationsStore implements ICorrelationsStore {
}

public async createCorrelationRule(correlationRule: CorrelationRule): Promise<boolean> {
const randomUUID = uuid();
const response = await this.service.createCorrelationRule({
name: correlationRule.name,
time_window: correlationRule.time_window,
Expand All @@ -82,17 +80,7 @@ export class CorrelationsStore implements ICorrelationsStore {

return correlationInput;
}),
trigger: correlationRule.trigger ? {
name: correlationRule.trigger.name,
id: correlationRule.trigger.name ? randomUUID : undefined,
sev_levels: correlationRule.trigger.sev_levels,
ids: correlationRule.trigger.ids ? correlationRule.trigger.ids.map(() => randomUUID) : [], // Update ids with the same UUID
severity: correlationRule.trigger.severity,
actions: correlationRule.trigger.actions ? correlationRule.trigger.actions.map((action) => ({
...action,
id: uuid(), // Update each action's id with the same UUID
})) : undefined,
} : undefined,
trigger: correlationRule.trigger
});
if (!response.ok) {
errorNotificationToast(this.notifications, 'create', 'correlation rule', response.error);
Expand Down
2 changes: 1 addition & 1 deletion types/Correlations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export interface CorrelationRuleModel {
name: string;
time_window: number; // Time in milliseconds
queries: CorrelationRuleQuery[];
trigger?: CorrelationRuleTrigger | undefined;
trigger: CorrelationRuleTrigger | undefined;
}

export interface CorrelationRule extends CorrelationRuleModel {
Expand Down

0 comments on commit e8a72d7

Please sign in to comment.