mirror of
https://github.com/portainer/portainer.git
synced 2025-07-25 08:19:40 +02:00
feat(docker/services): show port ranges [EE-4012] (#10657)
Some checks failed
ci / build_images (map[arch:amd64 platform:windows version:ltsc2022]) (push) Has been cancelled
ci / build_images (map[arch:arm platform:linux version:]) (push) Has been cancelled
ci / build_images (map[arch:arm64 platform:linux version:]) (push) Has been cancelled
ci / build_images (map[arch:ppc64le platform:linux version:]) (push) Has been cancelled
ci / build_images (map[arch:s390x platform:linux version:]) (push) Has been cancelled
ci / build_images (map[arch:amd64 platform:linux version:]) (push) Has been cancelled
ci / build_images (map[arch:amd64 platform:windows version:1809]) (push) Has been cancelled
/ triage (push) Has been cancelled
Lint / Run linters (push) Has been cancelled
Test / test-client (push) Has been cancelled
Test / test-server (map[arch:amd64 platform:linux]) (push) Has been cancelled
Test / test-server (map[arch:amd64 platform:windows version:1809]) (push) Has been cancelled
Test / test-server (map[arch:amd64 platform:windows version:ltsc2022]) (push) Has been cancelled
Test / test-server (map[arch:arm64 platform:linux]) (push) Has been cancelled
ci / build_manifests (push) Has been cancelled
Some checks failed
ci / build_images (map[arch:amd64 platform:windows version:ltsc2022]) (push) Has been cancelled
ci / build_images (map[arch:arm platform:linux version:]) (push) Has been cancelled
ci / build_images (map[arch:arm64 platform:linux version:]) (push) Has been cancelled
ci / build_images (map[arch:ppc64le platform:linux version:]) (push) Has been cancelled
ci / build_images (map[arch:s390x platform:linux version:]) (push) Has been cancelled
ci / build_images (map[arch:amd64 platform:linux version:]) (push) Has been cancelled
ci / build_images (map[arch:amd64 platform:windows version:1809]) (push) Has been cancelled
/ triage (push) Has been cancelled
Lint / Run linters (push) Has been cancelled
Test / test-client (push) Has been cancelled
Test / test-server (map[arch:amd64 platform:linux]) (push) Has been cancelled
Test / test-server (map[arch:amd64 platform:windows version:1809]) (push) Has been cancelled
Test / test-server (map[arch:amd64 platform:windows version:ltsc2022]) (push) Has been cancelled
Test / test-server (map[arch:arm64 platform:linux]) (push) Has been cancelled
ci / build_manifests (push) Has been cancelled
This commit is contained in:
parent
4ca6292805
commit
d336a14e50
37 changed files with 1406 additions and 148 deletions
|
@ -0,0 +1,64 @@
|
|||
import {
|
||||
array,
|
||||
lazy,
|
||||
mixed,
|
||||
number,
|
||||
NumberSchema,
|
||||
object,
|
||||
SchemaOf,
|
||||
} from 'yup';
|
||||
|
||||
import { Range, isRange } from './types';
|
||||
|
||||
export function validation() {
|
||||
return array(
|
||||
object({
|
||||
hostPort: rangeOrNumber(),
|
||||
containerPort: mixed().when('hostPort', {
|
||||
is: (hostPort: Range | number | undefined) =>
|
||||
!hostPort || isRange(hostPort),
|
||||
then: rangeOrNumber(),
|
||||
otherwise: port().typeError(
|
||||
'Container port must be a number when host port is not a range'
|
||||
),
|
||||
}),
|
||||
protocol: mixed().oneOf(['tcp', 'udp']),
|
||||
publishMode: mixed().oneOf(['ingress', 'host']),
|
||||
}).test({
|
||||
message:
|
||||
'Invalid port specification: host port range must be equal to container port range',
|
||||
test: (portBinding) => {
|
||||
const hostPort = portBinding.hostPort as Range | number | undefined;
|
||||
return !(
|
||||
isRange(hostPort) &&
|
||||
isRange(portBinding.containerPort) &&
|
||||
hostPort.end - hostPort.start !==
|
||||
portBinding.containerPort.end - portBinding.containerPort.start
|
||||
);
|
||||
},
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
function port() {
|
||||
return number()
|
||||
.optional()
|
||||
.min(0, 'Port must be a number between 0 to 65535')
|
||||
.max(65535, 'Port must be a number between 0 to 65535');
|
||||
}
|
||||
|
||||
function rangeOrNumber() {
|
||||
return lazy<SchemaOf<Range> | NumberSchema>(
|
||||
(value: Range | number | undefined) => (isRange(value) ? range() : port())
|
||||
);
|
||||
}
|
||||
|
||||
function range(): SchemaOf<Range> {
|
||||
return object({
|
||||
start: port().required(),
|
||||
end: port().required(),
|
||||
}).test({
|
||||
message: 'Start port must be less than end port',
|
||||
test: (value) => !value.start || !value.end || value.start <= value.end,
|
||||
});
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue