| 424 | |
| 425 | |
| 426 | Option<Error> validateCheckInfo(const CheckInfo& checkInfo) |
| 427 | { |
| 428 | if (!checkInfo.has_type()) { |
| 429 | return Error("CheckInfo must specify 'type'"); |
| 430 | } |
| 431 | |
| 432 | switch (checkInfo.type()) { |
| 433 | case CheckInfo::COMMAND: { |
| 434 | if (!checkInfo.has_command()) { |
| 435 | return Error("Expecting 'command' to be set for COMMAND check"); |
| 436 | } |
| 437 | |
| 438 | const CommandInfo& command = checkInfo.command().command(); |
| 439 | |
| 440 | if (!command.has_value()) { |
| 441 | string commandType = |
| 442 | (command.shell() ? "'shell command'" : "'executable path'"); |
| 443 | |
| 444 | return Error("Command check must contain " + commandType); |
| 445 | } |
| 446 | |
| 447 | Option<Error> error = |
| 448 | common::validation::validateCommandInfo(command); |
| 449 | if (error.isSome()) { |
| 450 | return Error( |
| 451 | "Check's `CommandInfo` is invalid: " + error->message); |
| 452 | } |
| 453 | |
| 454 | // TODO(alexr): Make sure irrelevant fields, e.g., `uris` are not set. |
| 455 | |
| 456 | break; |
| 457 | } |
| 458 | case CheckInfo::HTTP: { |
| 459 | if (!checkInfo.has_http()) { |
| 460 | return Error("Expecting 'http' to be set for HTTP check"); |
| 461 | } |
| 462 | |
| 463 | const CheckInfo::Http& http = checkInfo.http(); |
| 464 | |
| 465 | if (http.has_path() && !strings::startsWith(http.path(), '/')) { |
| 466 | return Error( |
| 467 | "The path '" + http.path() + "' of HTTP check must start with '/'"); |
| 468 | } |
| 469 | |
| 470 | break; |
| 471 | } |
| 472 | case CheckInfo::TCP: { |
| 473 | if (!checkInfo.has_tcp()) { |
| 474 | return Error("Expecting 'tcp' to be set for TCP check"); |
| 475 | } |
| 476 | |
| 477 | break; |
| 478 | } |
| 479 | case CheckInfo::UNKNOWN: { |
| 480 | return Error( |
| 481 | "'" + CheckInfo::Type_Name(checkInfo.type()) + "'" |
| 482 | " is not a valid check type"); |
| 483 | } |