mirror of
https://github.com/portainer/portainer.git
synced 2025-08-09 07:45:22 +02:00
fix(swarm): fixed issue parsing url with no scheme [EE-4017] (#7502)
This commit is contained in:
parent
27095ede22
commit
a54c54ef24
11 changed files with 67 additions and 50 deletions
|
@ -130,7 +130,7 @@ export async function createRemoteEnvironment({
|
|||
}: CreateRemoteEnvironment) {
|
||||
return createEnvironment(name, creationType, {
|
||||
...options,
|
||||
url: `${url}`,
|
||||
url: `tcp://${url}`,
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -110,9 +110,11 @@
|
|||
<span ng-if="!state.agentEndpoint">Environment URL</span>
|
||||
<span ng-if="state.agentEndpoint">Environment address</span>
|
||||
<portainer-tooltip
|
||||
ng-if="!state.agentEndpoint"
|
||||
message="'URL or IP address of a Docker host. The Docker API must be exposed over a TCP port. Please refer to the Docker documentation to configure it.'"
|
||||
>
|
||||
</portainer-tooltip>
|
||||
<portainer-tooltip ng-if="state.agentEndpoint" message="'The address for the Portainer agent in the format <HOST>:<PORT> or <IP>:<PORT>'"> </portainer-tooltip>
|
||||
</label>
|
||||
<div class="col-sm-9 col-lg-10">
|
||||
<input
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue