Skip to content
This repository has been archived by the owner on Sep 27, 2023. It is now read-only.

Commit

Permalink
add ion creds to logplex api
Browse files Browse the repository at this point in the history
  • Loading branch information
jkvor committed Apr 17, 2012
1 parent be90618 commit 2fb0994
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/logplex_api.erl
Expand Up @@ -462,9 +462,10 @@ authorize(Req) ->
AuthKey = os:getenv("LOGPLEX_AUTH_KEY"),
case Req:get_header_value("Authorization") of
[$B, $a, $s, $i, $c, $ | Encoded] ->
CoreUserPass = os:getenv("LOGPLEX_CORE_USERPASS"),
case binary_to_list(base64:decode(list_to_binary(Encoded))) of
CoreUserPass when is_list(CoreUserPass), length(CoreUserPass) > 0 ->
TrustedValues = [os:getenv("LOGPLEX_CORE_USERPASS"),
os:getenv("LOGPLEX_ION_USERPASS")],
case basic_auth_is_valid(binary_to_list(base64:decode(list_to_binary(Encoded))), TrustedValues) of
true ->
true;
_ ->
throw({401, <<"Not Authorized">>})
Expand All @@ -475,6 +476,15 @@ authorize(Req) ->
throw({401, <<"Not Authorized">>})
end.

basic_auth_is_valid(Val, [Val|_]) when is_list(Val), length(Val) > 0 ->
true;

basic_auth_is_valid(Val, [_|Tail]) ->
basic_auth_is_valid(Val, Tail);

basic_auth_is_valid(_, []) ->
false.

error_resp(RespCode, Body) ->
throw({RespCode, Body}).

Expand Down

0 comments on commit 2fb0994

Please sign in to comment.