Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration to send scan summary #2236

Merged
merged 4 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,17 @@
import { merge } from 'lodash-es';
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 +21,24 @@ import {
isVulnerabilityNotification,
} from './utils';

const SendScanSumaryCheckbox = ({ 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 +101,10 @@ export const NotificationTypeField = ({
) : null} */}
</Listbox>

{canSendScanSummary(notificationType, integrationType) ? (
<SendScanSumaryCheckbox 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
Loading