Skip to content

Commit

Permalink
Integration to send scan summary (#2236)
Browse files Browse the repository at this point in the history
* add send scan summary option

* rename variable name

* remove from filters and replace by checkbox

* corrected typo
  • Loading branch information
milan-deepfence authored Jul 5, 2024
1 parent 517619d commit c887ed4
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 4 deletions.
6 changes: 4 additions & 2 deletions deepfence_frontend/apps/dashboard/api-spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -14587,7 +14587,8 @@
"config": { "type": "object", "additionalProperties": {}, "nullable": true },
"filters": { "$ref": "#/components/schemas/ModelIntegrationFilters" },
"integration_type": { "type": "string" },
"notification_type": { "type": "string" }
"notification_type": { "type": "string" },
"send_summary": { "type": "boolean" }
}
},
"ModelIntegrationFilters": {
Expand Down Expand Up @@ -14625,7 +14626,8 @@
"filters": { "$ref": "#/components/schemas/ModelIntegrationFilters" },
"id": { "type": "integer" },
"integration_type": { "type": "string" },
"notification_type": { "type": "string" }
"notification_type": { "type": "string" },
"send_summary": { "type": "boolean" }
}
},
"ModelInviteUserRequest": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ export interface ModelIntegrationAddReq {
* @memberof ModelIntegrationAddReq
*/
notification_type: string;
/**
*
* @type {boolean}
* @memberof ModelIntegrationAddReq
*/
send_summary?: boolean;
}

/**
Expand Down Expand Up @@ -77,6 +83,7 @@ export function ModelIntegrationAddReqFromJSONTyped(json: any, ignoreDiscriminat
'filters': !exists(json, 'filters') ? undefined : ModelIntegrationFiltersFromJSON(json['filters']),
'integration_type': json['integration_type'],
'notification_type': json['notification_type'],
'send_summary': !exists(json, 'send_summary') ? undefined : json['send_summary'],
};
}

Expand All @@ -93,6 +100,7 @@ export function ModelIntegrationAddReqToJSON(value?: ModelIntegrationAddReq | nu
'filters': ModelIntegrationFiltersToJSON(value.filters),
'integration_type': value.integration_type,
'notification_type': value.notification_type,
'send_summary': value.send_summary,
};
}

Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ export interface ModelIntegrationUpdateReq {
* @memberof ModelIntegrationUpdateReq
*/
notification_type?: string;
/**
*
* @type {boolean}
* @memberof ModelIntegrationUpdateReq
*/
send_summary?: boolean;
}

/**
Expand All @@ -82,6 +88,7 @@ export function ModelIntegrationUpdateReqFromJSONTyped(json: any, ignoreDiscrimi
'id': !exists(json, 'id') ? undefined : json['id'],
'integration_type': !exists(json, 'integration_type') ? undefined : json['integration_type'],
'notification_type': !exists(json, 'notification_type') ? undefined : json['notification_type'],
'send_summary': !exists(json, 'send_summary') ? undefined : json['send_summary'],
};
}

Expand All @@ -99,6 +106,7 @@ export function ModelIntegrationUpdateReqToJSON(value?: ModelIntegrationUpdateRe
'id': value.id,
'integration_type': value.integration_type,
'notification_type': value.notification_type,
'send_summary': value.send_summary,
};
}

Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { useState } from 'react';
import { useParams } from 'react-router-dom';
import { Listbox, ListboxOption } from 'ui-components';
import { Checkbox, Listbox, ListboxOption, Tooltip } from 'ui-components';

import { ModelIntegrationListResp } from '@/api/generated';
import { InfoStandardIcon } from '@/components/icons/common/InfoStandard';
import { ScanTypeEnum } from '@/types/common';

import { AdvancedFilters } from './AdvancedFilter';
import { FieldSelection } from './FieldSelection';
import { TextInputType } from './TextInputType';
import {
canSendScanSummary,
getDisplayNotification,
IntegrationType,
isCloudComplianceNotification,
Expand All @@ -18,6 +20,24 @@ import {
isVulnerabilityNotification,
} from './utils';

const SendScanSummaryCheckbox = ({ sendSummaryOnly }: { sendSummaryOnly: boolean }) => {
const [checked, setChecked] = useState(sendSummaryOnly);
return (
<div className="flex gap-x-1.5 items-center col-span-2">
<Checkbox
name="sendSummary"
label="Send scan summary only?"
checked={checked}
onCheckedChange={(check: boolean) => setChecked(check)}
/>
<Tooltip content="By default complete scan results are sent. If you wish to send only scan summary, check this checkbox.">
<div className="w-4 h-4">
<InfoStandardIcon />
</div>
</Tooltip>
</div>
);
};
export const NotificationTypeField = ({
fieldErrors,
defaultNotificationType,
Expand Down Expand Up @@ -80,6 +100,10 @@ export const NotificationTypeField = ({
) : null} */}
</Listbox>

{canSendScanSummary(notificationType, integrationType) ? (
<SendScanSummaryCheckbox sendSummaryOnly={data?.config?.send_summary ?? false} />
) : null}

{isCloudComplianceNotification(notificationType) &&
integrationType !== IntegrationType.s3 && (
<Listbox
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,13 @@ export const getDisplayNotification = (notificationType: string) => {
}
return notificationType;
};

export const canSendScanSummary = (notificationType: string, integrationType: string) => {
return (
((integrationType === IntegrationType.slack ||
integrationType === IntegrationType.microsoftTeams) &&
scanTypes.includes(notificationType)) ||
isComplianceNotification(notificationType) ||
isCloudComplianceNotification(notificationType)
);
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { upperCase } from 'lodash-es';
import { useMemo, useState } from 'react';
import { Listbox, ListboxOption } from 'ui-components';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ const action = async ({ request, params }: ActionFunctionArgs): Promise<ActionDa
notification_type: _notificationType,
config: getConfigBodyNotificationType(formData, _integrationType as string),
filters: _filters,
send_summary: formData.get('sendSummary') === 'on',
},
});
} else {
Expand All @@ -327,6 +328,7 @@ const action = async ({ request, params }: ActionFunctionArgs): Promise<ActionDa
notification_type: _notificationType,
config: getConfigBodyNotificationType(formData, _integrationType as string),
filters: _filters,
send_summary: formData.get('sendSummary') === 'on',
},
});
}
Expand Down

0 comments on commit c887ed4

Please sign in to comment.