fix(kube): use https when port is 443 in various tables [EE-6592] (#11443)
parent
e3a8853212
commit
86c4b3059e
|
@ -4,6 +4,8 @@ import KubernetesNamespaceHelper from 'Kubernetes/helpers/namespaceHelper';
|
|||
import { KubernetesConfigurationKinds } from 'Kubernetes/models/configuration/models';
|
||||
import { KubernetesApplicationDeploymentTypes, KubernetesApplicationTypes } from 'Kubernetes/models/application/models/appConstants';
|
||||
|
||||
import { getSchemeFromPort } from '@/react/common/network-utils';
|
||||
|
||||
angular.module('portainer.kubernetes').controller('KubernetesApplicationsDatatableController', [
|
||||
'$scope',
|
||||
'$controller',
|
||||
|
@ -105,7 +107,10 @@ angular.module('portainer.kubernetes').controller('KubernetesApplicationsDatatab
|
|||
// Map all load balancer service ports to ip address
|
||||
let loadBalancerURLs = [];
|
||||
if (item.LoadBalancerIPAddress) {
|
||||
loadBalancerURLs = item.PublishedPorts.map((pp) => `http://${item.LoadBalancerIPAddress}:${pp.Port}`);
|
||||
loadBalancerURLs = item.PublishedPorts.map((pp) => {
|
||||
const scheme = getSchemeFromPort(pp.Port);
|
||||
return `${scheme}://${item.LoadBalancerIPAddress}:${pp.Port}`;
|
||||
});
|
||||
}
|
||||
|
||||
// combine ingress urls
|
||||
|
|
|
@ -3,6 +3,7 @@ import { CellContext } from '@tanstack/react-table';
|
|||
|
||||
import { ContainerGroup } from '@/react/azure/types';
|
||||
import { getPorts } from '@/react/azure/utils';
|
||||
import { getSchemeFromPort } from '@/react/common/network-utils';
|
||||
|
||||
import { Icon } from '@@/Icon';
|
||||
|
||||
|
@ -27,10 +28,17 @@ function PortsCell({
|
|||
return '-';
|
||||
}
|
||||
|
||||
return ports.map((port) => (
|
||||
<a className="image-tag" href={`http://${ip}:${port.host}`} key={port.host}>
|
||||
<Icon icon={ExternalLink} className="mr-1" />
|
||||
{ip}:{port.host}
|
||||
</a>
|
||||
));
|
||||
return ports.map((port) => {
|
||||
const scheme = getSchemeFromPort(port.host);
|
||||
return (
|
||||
<a
|
||||
className="image-tag"
|
||||
href={`${scheme}://${ip}:${port.host}`}
|
||||
key={port.host}
|
||||
>
|
||||
<Icon icon={ExternalLink} className="mr-1" />
|
||||
{ip}:{port.host}
|
||||
</a>
|
||||
);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
export function getSchemeFromPort(port?: number): 'http' | 'https' {
|
||||
if (!port) {
|
||||
return 'http';
|
||||
}
|
||||
|
||||
const hostPort = String(port);
|
||||
return hostPort.endsWith('443') ? 'https' : 'http';
|
||||
}
|
|
@ -3,6 +3,7 @@ import { ExternalLink } from 'lucide-react';
|
|||
import { CellContext } from '@tanstack/react-table';
|
||||
|
||||
import type { DockerContainer } from '@/react/docker/containers/types';
|
||||
import { getSchemeFromPort } from '@/react/common/network-utils';
|
||||
|
||||
import { Icon } from '@@/Icon';
|
||||
|
||||
|
@ -31,18 +32,46 @@ function Cell({ row }: CellContext<DockerContainer, string>) {
|
|||
return '-';
|
||||
}
|
||||
|
||||
const { PublicURL: publicUrl } = environment;
|
||||
const publicURL = getPublicUrl(environment.PublicURL);
|
||||
|
||||
return _.uniqBy(ports, 'public').map((port) => (
|
||||
<a
|
||||
key={`${port.host}:${port.public}`}
|
||||
className="image-tag"
|
||||
href={`http://${publicUrl || port.host}:${port.public}`}
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
>
|
||||
<Icon icon={ExternalLink} />
|
||||
{port.public}:{port.private}
|
||||
</a>
|
||||
));
|
||||
return _.uniqBy(ports, 'public').map((port) => {
|
||||
let url = publicURL || port.host || '';
|
||||
if (!url.startsWith('http')) {
|
||||
const scheme = getSchemeFromPort(port.private);
|
||||
url = `${scheme}://${url}`;
|
||||
}
|
||||
url = `${url}:${port.public}`;
|
||||
|
||||
return (
|
||||
<a
|
||||
key={`${port.host}:${port.public}`}
|
||||
className="image-tag"
|
||||
href={url}
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
>
|
||||
<Icon icon={ExternalLink} />
|
||||
{port.public}:{port.private}
|
||||
</a>
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
function getPublicUrl(url?: string): string {
|
||||
if (!url) {
|
||||
return '';
|
||||
}
|
||||
|
||||
// Add protocol if missing
|
||||
const u =
|
||||
url.startsWith('http://') || url.startsWith('https://')
|
||||
? url
|
||||
: `http://${url}`;
|
||||
|
||||
try {
|
||||
const parsedUrl = new URL(u);
|
||||
return `${parsedUrl.protocol}://${parsedUrl.hostname}`;
|
||||
} catch (error) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ import { CellContext } from '@tanstack/react-table';
|
|||
|
||||
import { ServiceViewModel } from '@/docker/models/service';
|
||||
import { useCurrentEnvironment } from '@/react/hooks/useCurrentEnvironment';
|
||||
import { getSchemeFromPort } from '@/react/common/network-utils';
|
||||
|
||||
import { Icon } from '@@/Icon';
|
||||
|
||||
|
@ -40,16 +41,20 @@ function Cell({
|
|||
|
||||
return ports
|
||||
.filter((port) => port.PublishedPort)
|
||||
.map((port) => (
|
||||
<a
|
||||
key={`${publicUrl}:${port.PublishedPort}`}
|
||||
className="image-tag vertical-center"
|
||||
href={`http://${publicUrl}:${port.PublishedPort}`}
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
>
|
||||
<Icon icon={ExternalLink} />
|
||||
{port.PublishedPort}:{port.TargetPort}
|
||||
</a>
|
||||
));
|
||||
.map((port) => {
|
||||
const scheme = getSchemeFromPort(port.TargetPort);
|
||||
|
||||
return (
|
||||
<a
|
||||
key={`${publicUrl}:${port.PublishedPort}`}
|
||||
className="image-tag vertical-center"
|
||||
href={`${scheme}://${publicUrl}:${port.PublishedPort}`}
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
>
|
||||
<Icon icon={ExternalLink} />
|
||||
{port.PublishedPort}:{port.TargetPort}
|
||||
</a>
|
||||
);
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue