anchor.diff:                               ["controller", "setFastWarmup"] ->
                                    {auth, fun handle_set_fast_warmup/1};
                                ["pools", PoolId, "buckets", Id] ->
  -                                 {auth_bucket, fun menelaus_web_buckets:handle_bucket_update/3,
  +                                 {auth_check_bucket_uuid, fun menelaus_web_buckets:handle_bucket_update/3,
                                     [PoolId, Id]};
                                ["pools", PoolId, "buckets"] ->
                                    {auth, fun menelaus_web_buckets:handle_bucket_create/2,
                                     [PoolId]};
                                ["pools", PoolId, "buckets", Id, "controller", "doFlush"] ->
  -                                 {auth, fun menelaus_web_buckets:handle_bucket_flush/3,
  -                                [PoolId, Id]};
  +                                 {auth_check_bucket_uuid,
  +                                  fun menelaus_web_buckets:handle_bucket_flush/3, [PoolId, Id]};
                                ["pools", PoolId, "buckets", Id, "controller", "compactBucket"] ->
  -                                 {auth, fun menelaus_web_buckets:handle_compact_bucket/3, [PoolId, Id]};
  +                                 {auth_check_bucket_uuid,
  +                                  fun menelaus_web_buckets:handle_compact_bucket/3, [PoolId, Id]};
                                ["pools", PoolId, "buckets", Id, "controller", "compactDatabases"] ->
  -                                 {auth, fun menelaus_web_buckets:handle_compact_databases/3, [PoolId, Id]};
  +                                 {auth_check_bucket_uuid,
  +                                  fun menelaus_web_buckets:handle_compact_databases/3, [PoolId, Id]};
                                ["pools", PoolId, "buckets", Id,
                                 "ddocs", DDocId, "controller", "compactView"] ->
  -                                 {auth, fun menelaus_web_buckets:handle_compact_view/4, [PoolId, Id, DDocId]};
  +                                 {auth_check_bucket_uuid,
  +                                  fun menelaus_web_buckets:handle_compact_view/4, [PoolId, Id, DDocId]};
                                ["pools", "default", "remoteClusters"] ->
                                    {auth, fun menelaus_web_remote_clusters:handle_remote_clusters_post/1};
                                ["pools", "default", "remoteClusters", Id] ->
  
positive.code:     {Alerts, AlertsSilenceToken} = menelaus_web_alerts_srv:fetch_alerts(),
  
      Controllers = {struct, [
        {addNode, {struct, [{uri, <<"/controller/addNode">>}]}},
        {rebalance, {struct, [{uri, <<"/controller/rebalance">>}]}},
        {failOver, {struct, [{uri, <<"/controller/failOver">>}]}},
        {reAddNode, {struct, [{uri, <<"/controller/reAddNode">>}]}},
        {ejectNode, {struct, [{uri, <<"/controller/ejectNode">>}]}},
        {setAutoCompaction, {struct, [
          {uri, <<"/controller/setAutoCompaction">>},
          {validateURI, <<"/controller/setAutoCompaction?just_validate=1">>}
        ]}},
        {replication, {struct, [
          {createURI, <<"/controller/createReplication">>},
          {replicatorDBURI, <<"/couchBase/_replicator">>},
          {infosURI, <<"/couchBase/_replicator/_design/_replicator_info/_view/infos?group_level=1">>}
        ]}},
        %% IMPORTANT: currently all the fast warmup related REST calls are
        %% stubs; so they must not be documented in any case
        {setFastWarmup, {struct, [
          {uri, <<"/controller/setFastWarmup">>},
          {validateURI, <<"/controller/setFastWarmup?just_validate=1">>}
        ]}}
      ]},
  
negative.code:             reply_json(Req, [list_to_binary("Unexpected server error, request logged.")], 500)
      end.
  
  auth(Req, F, Args) ->
      menelaus_auth:apply_auth(Req, fun check_uuid/3, [F, Args]).
  
  auth_any_bucket(Req, F, Args) ->
      menelaus_auth:apply_auth_bucket(Req, fun check_uuid/3, [F, Args]).
  
  check_uuid(F, Args, Req) ->
      ReqUUID0 = proplists:get_value("uuid", Req:parse_qs()),
      case ReqUUID0 =/= undefined of
          true ->
              ReqUUID = list_to_binary(ReqUUID0),
              UUID = get_uuid(),
  
              case ReqUUID =:= UUID of
                  true ->
                      erlang:apply(F, Args ++ [Req]);
                  false ->
                      Req:respond({404, server_header(),
                                   "Cluster uuid does not match the requested.\r\n"})
              end;
          false ->
              erlang:apply(F, Args ++ [Req])
      end.
  
  auth_check_bucket_uuid(Req, F, Args) ->
      menelaus_auth:apply_auth_bucket(Req, fun check_bucket_uuid/3, [F, Args]).
  
  check_bucket_uuid(F, [PoolId, Bucket | _] = Args, Req) ->
      case ns_bucket:get_bucket(Bucket) of
          not_present ->
              Req:respond({404, server_header(),
                           "Requested resource not found.\r\n"});
          {ok, BucketConfig} ->
              menelaus_web_buckets:checking_bucket_uuid(
                PoolId, Req, BucketConfig,
                fun () ->
                        erlang:apply(F, Args ++ [Req])
                end)
      end.
  
  %% Internal API
  -define(SAMPLES_LOADING_TIMEOUT, 60000).
  