Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: support riak credentials parameters #30

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/krc.erl
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ conflict_ok_test() ->
{ok, Obj} = get(krc_server,
B,
K,
fun(V1, V2) -> erlang:max(V1, V2) end),
fun(Val1, Val2) -> erlang:max(Val1, Val2) end),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohh, nice find!

true = erlang:max(V1, V2) =:= krc_obj:val(Obj)
end).

Expand Down
30 changes: 29 additions & 1 deletion src/krc_server.erl
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,35 @@ opts(set_bucket)-> [].
%% Connections
copts() ->
[ {auto_reconnect, false} %exit on TCP/IP error
].
] ++ sopts().

%% Security options
sopts() ->
RiakUser = application:get_env(?APP, riak_user, undefined),
RiakPass = application:get_env(?APP, riak_pass, ""),
CACert = application:get_env(?APP, riak_cacertfile, undefined),
SSLOpts = application:get_env(?APP, riak_ssl_opts, []),

%% Only used when using certificate-based authentication
RiakCertFile = application:get_env(?APP, riak_certfile, undefined),
RiakKeyFile = application:get_env(?APP, riak_keyfile, undefined),

RiakCerts =
case RiakCertFile =/= undefined andalso RiakKeyFile =/= undefined of
true -> [{certfile, RiakCertFile}, {keyfile, RiakKeyFile}];
false -> []
end,

%% These two options are the minimum required ones for security to work
case RiakUser =/= undefined andalso CACert =/= undefined of
true ->
[ {credentials, RiakUser, RiakPass}
, {cacertfile, CACert}
, {ssl_opts, SSLOpts}
| RiakCerts ];
false ->
[]
end.

%% Reads
ropts() ->
Expand Down