Verified Commit 0410165e authored by Cyril Vazquez's avatar Cyril Vazquez
Browse files

New connector params validation based on config

parent 4df8ea9d
Pipeline #14820 failed with stages
in 39 seconds
......@@ -115,26 +115,36 @@ class ArchiveTransfer extends abstractMessage
$this->sendError("404", 'The parameter %1$s is unknown in the configuration', [$name]);
break;
}
$confParam = $confParams[$name];
}
if (!isset($confParam["type"])) {
$confParam["type"] = "text";
foreach ($confParams as $name => $confParam) {
// Default value
if (isset($confParam["default"])) {
$value = $confParam["default"];
}
if (isset($confParam["default"]) && $confParam["type"] != "file" && $param == '') {
$params[$name] = $confParam["default"];
if (isset($params[$name]) && $params[$name] !== "") {
$value = $params[$name];
}
if (isset($confParam["required"]) && $confParam["required"] && $param == '') {
$this->sendError("404", 'The parameter %1$s is required', [$name]);
$params[$name] = $value;
if ($param == "") {
if (isset($confParam["required"]) && $confParam["required"]) {
$this->sendError("404", 'The parameter %1$s is required', [$name]);
}
continue;
}
if ($param == '') {
continue;
// Default type
if (!isset($confParam["type"])) {
$type = "text";
} else {
$type = $confParam["type"];
}
switch ($confParam["type"]) {
switch ($type) {
case 'number':
if (!is_numeric($param)) {
$this->sendError("405", 'The parameter %1$s needs to be a number', [$name]);
......@@ -166,11 +176,13 @@ class ArchiveTransfer extends abstractMessage
break;
}
}
if (count($this->errors) > 0) {
$exception = \laabs::newException('medona/invalidMessageException', "Invalid message", 400);
$exception->errors = $this->errors;
throw $exception;
}
return $params;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment