| 269 | |
| 270 | |
| 271 | Future<http::Response> ResourceProviderManagerProcess::api( |
| 272 | const http::Request& request, |
| 273 | const Option<Principal>& principal) |
| 274 | { |
| 275 | // TODO(bbannier): This implementation does not limit the number of messages |
| 276 | // in the actor's inbox which could become large should a big number of |
| 277 | // resource providers attempt to subscribe before recovery completed. Consider |
| 278 | // rejecting requests until the resource provider manager has recovered. This |
| 279 | // would likely require implementing retry logic in resource providers. |
| 280 | return recovered.future().then(defer( |
| 281 | self(), [this, request, principal](const Nothing&) -> http::Response { |
| 282 | if (request.method != "POST") { |
| 283 | return MethodNotAllowed({"POST"}, request.method); |
| 284 | } |
| 285 | |
| 286 | v1::resource_provider::Call v1Call; |
| 287 | |
| 288 | // TODO(anand): Content type values are case-insensitive. |
| 289 | Option<string> contentType = request.headers.get("Content-Type"); |
| 290 | |
| 291 | if (contentType.isNone()) { |
| 292 | return BadRequest("Expecting 'Content-Type' to be present"); |
| 293 | } |
| 294 | |
| 295 | if (contentType.get() == APPLICATION_PROTOBUF) { |
| 296 | if (!v1Call.ParseFromString(request.body)) { |
| 297 | return BadRequest("Failed to parse body into Call protobuf"); |
| 298 | } |
| 299 | } else if (contentType.get() == APPLICATION_JSON) { |
| 300 | Try<JSON::Value> value = JSON::parse(request.body); |
| 301 | if (value.isError()) { |
| 302 | return BadRequest( |
| 303 | "Failed to parse body into JSON: " + value.error()); |
| 304 | } |
| 305 | |
| 306 | Try<v1::resource_provider::Call> parse = |
| 307 | ::protobuf::parse<v1::resource_provider::Call>(value.get()); |
| 308 | |
| 309 | if (parse.isError()) { |
| 310 | return BadRequest( |
| 311 | "Failed to convert JSON into Call protobuf: " + parse.error()); |
| 312 | } |
| 313 | |
| 314 | v1Call = parse.get(); |
| 315 | } else { |
| 316 | return UnsupportedMediaType( |
| 317 | string("Expecting 'Content-Type' of ") + APPLICATION_JSON + |
| 318 | " or " + APPLICATION_PROTOBUF); |
| 319 | } |
| 320 | |
| 321 | Call call = devolve(v1Call); |
| 322 | |
| 323 | Option<Error> error = validate(call, None()); |
| 324 | if (error.isSome()) { |
| 325 | return BadRequest( |
| 326 | "Failed to validate resource_provider::Call: " + error->message); |
| 327 | } |
| 328 |
nothing calls this directly
no test coverage detected