anchor.diff:      end},
   
       {['DELETE', "/channels/(\\d+)"], fun(Req, [ChannelId]) ->
  +	authorize(Req),
           logplex_channel:delete(list_to_binary(ChannelId)),
           Req:respond({200, [], <<"OK">>})
       end},
   
       {['POST', "/channels/(\\d+)/token"], fun(Req, [ChannelId]) ->
  -	    {struct, Params} = mochijson2:decode(Req:recv_body()),
  +	authorize(Req),
  +	{struct, Params} = mochijson2:decode(Req:recv_body()),
           TokenName = proplists:get_value(<<"name">>, Params),
           TokenName == undefined andalso error_resp(Req, 400, <<"name post param missing">>),
           Token = logplex_token:create(list_to_binary(ChannelId), TokenName),
  
positive.code:     end},
  
      {['GET', "/channels/(\\d+)/info"], fun(Req, [ChannelId]) ->
          Info = logplex_channel:info(list_to_binary(ChannelId)),
          Req:respond({200, [], mochijson2:encode({struct, Info})})
      end},
  
      {['POST', "/channels/(\\d+)/drains"], fun(Req, _Match) ->
          Req:respond({200, [], <<"OK">>})
      end},
  
      {['GET', "/channels/(\\d+)/drains"], fun(Req, _Match) ->
          Req:respond({200, [], <<"OK">>})
      end},
  
      {['GET', "/channels/(\\d+)/drains/(\\w+)"], fun(Req, _Match) ->
          Req:respond({200, [], <<"OK">>})
      end},
  
      {['DELETE', "/channels/(\\d+)/drains"], fun(Req, _Match) ->
          Req:respond({200, [], <<"OK">>})
      end}].
  
  
negative.code:     end.
  
  authorize(Req) ->
      AuthKey = os:getenv("LOGPLEX_AUTH_KEY"),
      case Req:get_header_value("Authorization") of
  	AuthKey ->
  	    true;
          _ ->
              Req:respond({401, [{"Content-Type", "text/html"}], "Not Authorized"}),
  	    throw(normal)
      end.
  
  error_resp(Req, RespCode, Body) ->
      Req:respond({RespCode, [{"Content-Type", "text/html"}], Body}),
  