fix(edge): allow more options for url [EE-2975] (#6781)

pull/6890/head
Chaim Lev-Ari 3 years ago committed by GitHub
parent d4c2ad4a57
commit c732ca2d2f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -19,6 +19,10 @@ func ParseHostForEdge(portainerURL string) (string, error) {
portainerHost = parsedURL.Host portainerHost = parsedURL.Host
} }
if portainerHost == "" {
return "", errors.New("hostname cannot be empty")
}
if portainerHost == "localhost" { if portainerHost == "localhost" {
return "", errors.New("cannot use localhost as environment URL") return "", errors.New("cannot use localhost as environment URL")
} }

@ -23,11 +23,20 @@ const validation = yup.object({
EdgePortainerUrl: yup EdgePortainerUrl: yup
.string() .string()
.test( .test(
'not-local', 'url',
'Cannot use localhost as environment URL', 'URL should be a valid URI and cannot include localhost',
(value) => !value?.includes('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'), .required('URL is required'),
}); });

Loading…
Cancel
Save