| 2678 | |
| 2679 | |
| 2680 | Future<Response> Http::statistics( |
| 2681 | const Request& request, |
| 2682 | const Option<Principal>& principal) const |
| 2683 | { |
| 2684 | // TODO(nfnt): Remove check for enabled |
| 2685 | // authorization as part of MESOS-5346. |
| 2686 | if (request.method != "GET" && slave->authorizer.isSome()) { |
| 2687 | return MethodNotAllowed({"GET"}, request.method); |
| 2688 | } |
| 2689 | |
| 2690 | Try<string> endpoint = extractEndpoint(request.url); |
| 2691 | if (endpoint.isError()) { |
| 2692 | return Failure("Failed to extract endpoint: " + endpoint.error()); |
| 2693 | } |
| 2694 | |
| 2695 | return authorizeEndpoint( |
| 2696 | endpoint.get(), |
| 2697 | request.method, |
| 2698 | slave->authorizer, |
| 2699 | principal) |
| 2700 | .then(defer( |
| 2701 | slave->self(), |
| 2702 | [this, request](bool authorized) -> Future<Response> { |
| 2703 | if (!authorized) { |
| 2704 | return Forbidden(); |
| 2705 | } |
| 2706 | |
| 2707 | return statisticsLimiter->acquire() |
| 2708 | .then(defer(slave->self(), &Slave::usage)) |
| 2709 | .then(defer(slave->self(), |
| 2710 | [this, request](const ResourceUsage& usage) { |
| 2711 | return _statistics(usage, request); |
| 2712 | })); |
| 2713 | })); |
| 2714 | } |
| 2715 | |
| 2716 | |
| 2717 | Response Http::_statistics( |