Merge pull request #1681 from YinDongFang/fix/docker

Fix validation error of container id
This commit is contained in:
Alexander Holliday authored and GitHub committed 2025-02-01 08:26:13 -08:00
commit 079d25389e
3 files changed
+32 -20

No files matched your search

+1 -1
View File
@@ -347,7 +347,7 @@ const Configure = () => {
<TextInput
type={monitor?.type === "http" ? "url" : "text"}
https={protocol === "https"}
startAdornment={<HttpAdornment https={protocol === "https"} />}
startAdornment={monitor?.type === "http" && <HttpAdornment https={protocol === "https"} />}
id="monitor-url"
label="URL to monitor"
placeholder="google.com"
+11 -5
View File
@@ -88,7 +88,7 @@ const CreateMonitor = () => {
? `http${https ? "s" : ""}://` + monitor.url
: monitor.url,
port: monitor.type === "port" ? monitor.port : undefined,
name: monitor.name === "" ? monitor.url : monitor.name,
name: monitor.name || monitor.url.substring(0, 50),
type: monitor.type,
interval: monitor.interval * MS_PER_MINUTE,
};
@@ -122,7 +122,7 @@ const CreateMonitor = () => {
form = {
...form,
description: form.name,
description: monitor.name || monitor.url,
teamId: user.teamId,
userId: user._id,
notifications: monitor.notifications,
@@ -138,17 +138,23 @@ const CreateMonitor = () => {
const handleChange = (event, formName) => {
const { value } = event.target;
setMonitor({
const newMonitor = {
...monitor,
[formName]: value,
});
};
if (formName === 'type') {
newMonitor.url = '';
}
setMonitor(newMonitor);
const { error } = monitorValidation.validate(
{ [formName]: value },
{ type: monitor.type, [formName]: value },
{ abortEarly: false }
);
setErrors((prev) => ({
...prev,
url: undefined,
...(error ? { [formName]: error.details[0].message } : { [formName]: undefined }),
}));
};
+20 -14
View File
@@ -91,13 +91,17 @@ const credentials = joi.object({
});
const monitorValidation = joi.object({
url: joi
.string()
.trim()
.custom((value, helpers) => {
// Regex from https://gist.github.com/dperini/729294
var urlRegex = new RegExp(
"^" +
url: joi.when('type', {
is: 'docker',
then: joi.string()
.trim().regex(/^[a-z0-9]{64}$/),
otherwise: joi
.string()
.trim()
.custom((value, helpers) => {
// Regex from https://gist.github.com/dperini/729294
var urlRegex = new RegExp(
"^" +
// protocol identifier (optional)
// short syntax // still required
"(?:(?:https?|ftp):\\/\\/)?" +
@@ -130,18 +134,20 @@ const monitorValidation = joi.object({
// resource path (optional)
"(?:[/?#]\\S*)?" +
"$",
"i"
);
if (!urlRegex.test(value)) {
return helpers.error("string.invalidUrl");
}
"i"
);
if (!urlRegex.test(value)) {
return helpers.error("string.invalidUrl");
}
return value;
})
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",
"string.pattern.base": "Please enter a valid container ID.",
}),
port: joi.number(),
name: joi.string().trim().max(50).allow("").messages({