From c732ca2d2f7a124e40e96a5aff115911f626bd56 Mon Sep 17 00:00:00 2001 From: Chaim Lev-Ari Date: Thu, 5 May 2022 10:03:24 +0300 Subject: [PATCH] fix(edge): allow more options for url [EE-2975] (#6781) --- api/internal/edge/url.go | 4 ++++ .../AutoEnvCreationSettingsForm.tsx | 17 +++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/api/internal/edge/url.go b/api/internal/edge/url.go index 984eb421f..50ff44f40 100644 --- a/api/internal/edge/url.go +++ b/api/internal/edge/url.go @@ -19,6 +19,10 @@ func ParseHostForEdge(portainerURL string) (string, error) { portainerHost = parsedURL.Host } + if portainerHost == "" { + return "", errors.New("hostname cannot be empty") + } + if portainerHost == "localhost" { return "", errors.New("cannot use localhost as environment URL") } diff --git a/app/portainer/settings/edge-compute/AutomaticEdgeEnvCreation/AutoEnvCreationSettingsForm.tsx b/app/portainer/settings/edge-compute/AutomaticEdgeEnvCreation/AutoEnvCreationSettingsForm.tsx index 5cd77788a..0d9a045fb 100644 --- a/app/portainer/settings/edge-compute/AutomaticEdgeEnvCreation/AutoEnvCreationSettingsForm.tsx +++ b/app/portainer/settings/edge-compute/AutomaticEdgeEnvCreation/AutoEnvCreationSettingsForm.tsx @@ -23,11 +23,20 @@ const validation = yup.object({ EdgePortainerUrl: yup .string() .test( - 'not-local', - 'Cannot use localhost as environment URL', - (value) => !value?.includes('localhost') + 'url', + 'URL should be a valid URI and cannot include localhost', + (value) => { + if (!value) { + return false; + } + try { + const url = new URL(value); + return !!url.hostname && url.hostname !== 'localhost'; + } catch { + return false; + } + } ) - .url('URL should be a valid URI') .required('URL is required'), });