import { getOptions } from 'utils/index';
import { yesNoOptions } from 'utils/constants';
import globalRootStore from 'stores/root';
import { getDefaultFilter } from './firewall';
export const actionInfos = {
allow: t('ALLOW'),
deny: t('DENY'),
reject: t('REJECT'),
};
export const protocolInfos = {
tcp: t('TCP'),
udp: t('UDP'),
icmp: t('ICMP'),
any: t('ANY'),
};
export const tableColumns = [
{
title: t('Rule Name'),
dataIndex: 'name',
},
{
title: t('Description'),
dataIndex: 'description',
isHideable: true,
},
{
title: t('Protocol'),
dataIndex: 'protocol',
valueMap: protocolInfos,
},
{
title: t('Source IP'),
dataIndex: 'source_ip_address',
},
{
title: t('Source Port'),
dataIndex: 'source_port',
},
{
title: t('Destination IP'),
dataIndex: 'destination_ip_address',
},
{
title: t('Destination Port'),
dataIndex: 'destination_port',
},
{
title: t('Rule Action'),
dataIndex: 'action',
valueMap: actionInfos,
},
{
title: t('Enabled'),
dataIndex: 'enabled',
valueRender: 'yesNo',
},
{
title: t('Shared Rule'),
dataIndex: 'shared',
valueRender: 'yesNo',
},
];
export const tableFilter = [
{
label: t('Rule Name'),
name: 'name',
},
{
label: t('Protocol'),
name: 'protocol',
options: getOptions(protocolInfos),
},
{
label: t('Rule Action'),
name: 'action',
options: getOptions(actionInfos),
},
{
label: t('Enabled'),
name: 'enabled',
options: yesNoOptions,
},
{
label: t('Shared Rule'),
name: 'shared',
options: yesNoOptions,
},
getDefaultFilter(t('Hide Default Rules')),
];
export const tableOptions = {
filterParams: tableFilter,
columns: tableColumns,
};
export const isMine = (item) => item.project_id === globalRootStore.projectId;
export const isDefault = (item) =>
[
'default egress ipv4',
'default egress ipv6',
'default ingress ipv4',
'default ingress ipv6',
].includes(item.name);