2022-09-21 04:49:42 +00:00
|
|
|
import { CellProps, Column } from 'react-table';
|
2022-11-28 02:00:28 +00:00
|
|
|
import { AlertTriangle, ArrowRight } from 'lucide-react';
|
2022-09-21 04:49:42 +00:00
|
|
|
|
|
|
|
import { Icon } from '@@/Icon';
|
2022-10-06 02:24:59 +00:00
|
|
|
import { Badge } from '@@/Badge';
|
2022-09-21 04:49:42 +00:00
|
|
|
|
|
|
|
import { Ingress, TLS, Path } from '../../types';
|
|
|
|
|
|
|
|
function isHTTP(TLSs: TLS[], host: string) {
|
|
|
|
return TLSs.filter((t) => t.Hosts.indexOf(host) !== -1).length === 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
function link(host: string, path: string, isHttp: boolean) {
|
|
|
|
if (!host) {
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<a
|
|
|
|
href={`${isHttp ? 'http' : 'https'}://${host}${path}`}
|
|
|
|
target="_blank"
|
|
|
|
rel="noreferrer"
|
|
|
|
>
|
|
|
|
{`${isHttp ? 'http' : 'https'}://${host}${path}`}
|
|
|
|
</a>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export const ingressRules: Column<Ingress> = {
|
|
|
|
Header: 'Rules and Paths',
|
|
|
|
accessor: 'Paths',
|
|
|
|
Cell: ({ row }: CellProps<Ingress, Path[]>) => {
|
|
|
|
const results = row.original.Paths?.map((path: Path) => {
|
|
|
|
const isHttp = isHTTP(row.original.TLS || [], path.Host);
|
|
|
|
return (
|
|
|
|
<div key={`${path.Host}${path.Path}${path.ServiceName}:${path.Port}`}>
|
2023-02-12 21:04:24 +00:00
|
|
|
<span className="flex flex-nowrap items-center gap-1 px-2">
|
2022-10-06 02:24:59 +00:00
|
|
|
{link(path.Host, path.Path, isHttp)}
|
2022-11-28 02:00:28 +00:00
|
|
|
<Icon icon={ArrowRight} />
|
2022-10-06 02:24:59 +00:00
|
|
|
{`${path.ServiceName}:${path.Port}`}
|
|
|
|
{!path.HasService && (
|
|
|
|
<Badge type="warn" className="ml-1 gap-1">
|
2022-11-28 02:00:28 +00:00
|
|
|
<Icon icon={AlertTriangle} />
|
2022-10-06 02:24:59 +00:00
|
|
|
Service doesn't exist
|
|
|
|
</Badge>
|
|
|
|
)}
|
2022-09-21 04:49:42 +00:00
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
return results || <div />;
|
|
|
|
},
|
|
|
|
id: 'ingressRules',
|
|
|
|
disableFilters: true,
|
|
|
|
canHide: true,
|
|
|
|
disableSortBy: true,
|
|
|
|
};
|