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

fix address validation when creating agent endpoint
pull/7426/head
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
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)
if err != nil {
return nil, &httperror.HandlerError{http.StatusInternalServerError, "Unable to get environment type", err}

View File

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

View File

@ -8,10 +8,11 @@ export function EnvironmentUrlField() {
return (
<FormControl
label="Environment URL"
label="Environment address"
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."
>
<Field
id="environment-url-field"