Update monitor and infrastrucutre validation to allow for port numbers
This commit is contained in:
1 parent
1102d77bfa
commit
9b76bd566a
1 file changed
+36
-8
@@ -91,10 +91,24 @@ const credentials = joi.object({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const monitorValidation = joi.object({
|
const monitorValidation = joi.object({
|
||||||
url: joi.string().uri({ allowRelative: true }).trim().messages({
|
url: joi
|
||||||
"string.empty": "This field is required.",
|
.string()
|
||||||
"string.uri": "The URL you provided is not valid.",
|
.trim()
|
||||||
}),
|
.custom((value, helpers) => {
|
||||||
|
const urlRegex =
|
||||||
|
/^(https?:\/\/)?(([0-9]{1,3}\.){3}[0-9]{1,3}|[\da-z\.-]+)(\.[a-z\.]{2,6})?(:(\d+))?([\/\w \.-]*)*\/?$/i;
|
||||||
|
|
||||||
|
if (!urlRegex.test(value)) {
|
||||||
|
return helpers.error("string.invalidUrl");
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
})
|
||||||
|
.messages({
|
||||||
|
"string.empty": "This field is required.",
|
||||||
|
"string.uri": "The URL you provided is not valid.",
|
||||||
|
"string.invalidUrl": "Please enter a valid URL with optional port",
|
||||||
|
}),
|
||||||
name: joi.string().trim().max(50).allow("").messages({
|
name: joi.string().trim().max(50).allow("").messages({
|
||||||
"string.max": "This field should not exceed the 50 characters limit.",
|
"string.max": "This field should not exceed the 50 characters limit.",
|
||||||
}),
|
}),
|
||||||
@@ -176,10 +190,24 @@ const advancedSettingsValidation = joi.object({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const infrastructureMonitorValidation = joi.object({
|
const infrastructureMonitorValidation = joi.object({
|
||||||
url: joi.string().uri({ allowRelative: true }).trim().messages({
|
url: joi
|
||||||
"string.empty": "This field is required.",
|
.string()
|
||||||
"string.uri": "The URL you provided is not valid.",
|
.trim()
|
||||||
}),
|
.custom((value, helpers) => {
|
||||||
|
const urlRegex =
|
||||||
|
/^(https?:\/\/)?(([0-9]{1,3}\.){3}[0-9]{1,3}|[\da-z\.-]+)(\.[a-z\.]{2,6})?(:(\d+))?([\/\w \.-]*)*\/?$/i;
|
||||||
|
|
||||||
|
if (!urlRegex.test(value)) {
|
||||||
|
return helpers.error("string.invalidUrl");
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
})
|
||||||
|
.messages({
|
||||||
|
"string.empty": "This field is required.",
|
||||||
|
"string.uri": "The URL you provided is not valid.",
|
||||||
|
"string.invalidUrl": "Please enter a valid URL with optional port",
|
||||||
|
}),
|
||||||
name: joi.string().trim().max(50).allow("").messages({
|
name: joi.string().trim().max(50).allow("").messages({
|
||||||
"string.max": "This field should not exceed the 50 characters limit.",
|
"string.max": "This field should not exceed the 50 characters limit.",
|
||||||
}),
|
}),
|
||||||
|
|||||||
Reference in new issue
Block a user