1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-22 23:09:41 +02:00

fix(endpoint handler): fix endpoint address(url) parsing EE-3081] (#7408)

fix address validation when creating agent endpoint
This commit is contained in:
Matt Hook 2022-08-05 09:30:54 +12:00 committed by GitHub
parent 0141e55936
commit 4e9b3a8940
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 2 deletions

View file

@ -258,6 +258,15 @@ func (handler *Handler) createEndpoint(payload *endpointCreatePayload) (*portain
endpointType := portainer.DockerEnvironment endpointType := portainer.DockerEnvironment
if payload.EndpointCreationType == agentEnvironment { if payload.EndpointCreationType == agentEnvironment {
// Case insensitive strip http or https scheme if URL entered
index := strings.Index(payload.URL, "://")
if index >= 0 {
payload.URL = payload.URL[index+3:]
}
payload.URL = "tcp://" + payload.URL
agentPlatform, err := handler.pingAndCheckPlatform(payload) agentPlatform, err := handler.pingAndCheckPlatform(payload)
if err != nil { if err != nil {
return nil, &httperror.HandlerError{http.StatusInternalServerError, "Unable to get environment type", err} return nil, &httperror.HandlerError{http.StatusInternalServerError, "Unable to get environment type", err}

View file

@ -130,7 +130,7 @@ export async function createRemoteEnvironment({
}: CreateRemoteEnvironment) { }: CreateRemoteEnvironment) {
return createEnvironment(name, creationType, { return createEnvironment(name, creationType, {
...options, ...options,
url: `tcp://${url}`, url: `${url}`,
}); });
} }

View file

@ -8,10 +8,11 @@ export function EnvironmentUrlField() {
return ( return (
<FormControl <FormControl
label="Environment URL" label="Environment address"
errors={meta.error} errors={meta.error}
required required
inputId="environment-url-field" inputId="environment-url-field"
tooltip="A host:port combination. The host can be either an IP address or a host name."
> >
<Field <Field
id="environment-url-field" id="environment-url-field"