| 333 | |
| 334 | |
| 335 | Option<Error> validateHealthCheck(const HealthCheck& healthCheck) |
| 336 | { |
| 337 | if (!healthCheck.has_type()) { |
| 338 | return Error("HealthCheck must specify 'type'"); |
| 339 | } |
| 340 | |
| 341 | switch (healthCheck.type()) { |
| 342 | case HealthCheck::COMMAND: { |
| 343 | if (!healthCheck.has_command()) { |
| 344 | return Error("Expecting 'command' to be set for COMMAND health check"); |
| 345 | } |
| 346 | |
| 347 | const CommandInfo& command = healthCheck.command(); |
| 348 | |
| 349 | if (!command.has_value()) { |
| 350 | string commandType = |
| 351 | (command.shell() ? "'shell command'" : "'executable path'"); |
| 352 | |
| 353 | return Error("Command health check must contain " + commandType); |
| 354 | } |
| 355 | |
| 356 | Option<Error> error = |
| 357 | common::validation::validateCommandInfo(command); |
| 358 | if (error.isSome()) { |
| 359 | return Error( |
| 360 | "Health check's `CommandInfo` is invalid: " + error->message); |
| 361 | } |
| 362 | |
| 363 | // TODO(alexr): Make sure irrelevant fields, e.g., `uris` are not set. |
| 364 | |
| 365 | break; |
| 366 | } |
| 367 | case HealthCheck::HTTP: { |
| 368 | if (!healthCheck.has_http()) { |
| 369 | return Error("Expecting 'http' to be set for HTTP health check"); |
| 370 | } |
| 371 | |
| 372 | const HealthCheck::HTTPCheckInfo& http = healthCheck.http(); |
| 373 | |
| 374 | if (http.has_scheme() && |
| 375 | http.scheme() != "http" && |
| 376 | http.scheme() != "https") { |
| 377 | return Error( |
| 378 | "Unsupported HTTP health check scheme: '" + http.scheme() + "'"); |
| 379 | } |
| 380 | |
| 381 | if (http.has_path() && !strings::startsWith(http.path(), '/')) { |
| 382 | return Error( |
| 383 | "The path '" + http.path() + |
| 384 | "' of HTTP health check must start with '/'"); |
| 385 | } |
| 386 | |
| 387 | break; |
| 388 | } |
| 389 | case HealthCheck::TCP: { |
| 390 | if (!healthCheck.has_tcp()) { |
| 391 | return Error("Expecting 'tcp' to be set for TCP health check"); |
| 392 | } |