1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-08-05 05:45:22 +02:00

fix(swarm): fixed issue parsing url with no scheme [EE-4017] (#7502)

This commit is contained in:
Matt Hook 2022-08-26 11:55:55 +12:00 committed by GitHub
parent 27095ede22
commit a54c54ef24
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 67 additions and 50 deletions

View file

@ -9,8 +9,42 @@ import { nameValidation } from '../NameField';
export function validation(): SchemaOf<CreateAgentEnvironmentValues> {
return object({
name: nameValidation(),
environmentUrl: string().required('This field is required.'),
environmentUrl: environmentValidation(),
meta: metadataValidation(),
gpus: gpusListValidation(),
});
}
function environmentValidation() {
return string()
.required('This field is required')
.test(
'address',
'Environment address must be of the form <IP>:<PORT> or <HOST>:<PORT>.',
(environmentUrl) => validateAddress(environmentUrl)
);
}
export function validateAddress(address: string | undefined) {
if (typeof address === 'undefined') {
return false;
}
if (address.indexOf('://') > -1) {
return false;
}
const [host, port] = address.split(':');
if (
host.length === 0 ||
Number.isNaN(parseInt(port, 10)) ||
port.match(/^[0-9]+$/) == null ||
parseInt(port, 10) < 1 ||
parseInt(port, 10) > 65535
) {
return false;
}
return true;
}

View file

@ -12,7 +12,7 @@ export function EnvironmentUrlField() {
errors={meta.error}
required
inputId="environment-url-field"
tooltip="A host:port combination. The host can be either an IP address or a host name."
tooltip="<HOST>:<PORT> or <IP>:<PORT>"
>
<Field
id="environment-url-field"