Skip to content
Open
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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ rel/example_project
logs
*.iml
*.d
.erlang.mk/
.erlang.mk/
_build
log
28 changes: 28 additions & 0 deletions config/shell.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[
{consulerl, [
{hostname, "127.0.0.1"},
{port, 8500},
{acl, []}
]},

{sasl, [
{sasl_error_logger, {file, "logs/sasl.log"}}
]},
{lager, [
{log_root, "logs"},
{handlers, [
{lager_console_backend, [{level, info}]},
{lager_file_backend, [{file, "error.log"}, {level, error}]},
{lager_file_backend, [{file, "console.log"}, {level, info}]},
{lager_file_backend, [{file, "debug.log"}, {level, debug}]}
]}
]},
{sync, [
{growl, all},
{log, all},
{non_descendants, fix},
{executable, auto},
{whitelisted_modules, []},
{excluded_modules, []}
]}
].
3 changes: 3 additions & 0 deletions config/sys.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[
{consulerl, []}
].
6 changes: 6 additions & 0 deletions config/vm.args
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-sname crm_push_server

-setcookie crm_push_server_cookie

+K true
+A30
41 changes: 19 additions & 22 deletions include/consulerl.hrl
Original file line number Diff line number Diff line change
@@ -1,43 +1,40 @@
-define(API_VERSION, "v1").
-define(MIME_FORM, {<<"content-type">>, <<"application/x-www-form-urlencoded; charset=UTF-8">>}).
-define(MIME_FORM,
{<<"content-type">>, <<"application/x-www-form-urlencoded; charset=UTF-8">>}).
-define(CONTENT_FORM, "application/x-www-form-urlencoded; charset=UTF-8").
-define(CONTENT_JSON, "application/json; charset=UTF-8").
-define(SCHEME, "http").
-define(JSON, jiffy).

-record(state, {host, port, acl}).

-define(EVENT_RESPONSE, consulerl_response).

-type verb() ::
set |
cas |
lock |
unlock |
get |
get_tree |
check_index |
check_session |
delete |
delete_tree |
delete_case.

set |
cas |
lock |
unlock |
get |
get_tree |
check_index |
check_session |
delete |
delete_tree |
delete_case.
-type ok() :: {ok, term()}.
-type error() :: {error, term()} | {error, term(), term()}.
-type return() :: ok() | error().

-type ref() :: pid() | {pid(), reference()} | fun((term()) -> ok).

-export_type([
ok/0,
error/0,
return/0,
ref/0,
verb/0
]).

-export_type([ok/0, error/0, return/0, ref/0, verb/0]).

-ifdef(TEST).

-define(TIMEOUT, 10).

-else.

-define(TIMEOUT, timer:seconds(5)).

-endif.
50 changes: 50 additions & 0 deletions rebar.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{erl_opts, [
{parse_transform, lager_transform}
]}.
{deps, [
jiffy,
{uuid, {git, "https://github.com/okeuday/uuid.git", {branch, "master"}}},
hackney,
lager
]}.

{eunit_opts, [export_all]}.% same as options for eunit:test(Tests, ...)
{eunit_tests, []}. % same as Tests argument in eunit:test(Tests, ...)
{eunit_compile_opts, [
{i, "include"},{sys_config, "config/shell.config"}]}.
{cover_enabled, true}.
{ct_opts, [{sys_config, "./config/shell.config"}]}.

{relx, [{release, {consulerl, "0.1.0"},
[consulerl,
sasl]},

{mode, dev},

%% automatically picked up if the files
%% exist but can be set manually, which
%% is required if the names aren't exactly
%% sys.config and vm.args
{sys_config, "./config/sys.config"},
{vm_args, "./config/vm.args"}

%% the .src form of the configuration files do
%% not require setting RELX_REPLACE_OS_VARS
%% {sys_config_src, "./config/sys.config.src"},
%% {vm_args_src, "./config/vm.args.src"}
]}.

{profiles, [
{test, [{erl_opts, [{d, 'TEST'},nowarn_export_all, export_all]},
{shell, [{config, "config/shell.config"}]},
{deps, [meck, sync]}]},
{prod, [{relx,
[%% prod is the default mode when prod
%% profile is used, so does not have
%% to be explicitly included like this
{mode, prod}

%% use minimal mode to exclude ERTS
%% {mode, minimal}
]
}]}]}.
46 changes: 46 additions & 0 deletions rebar.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{"1.2.0",
[{<<"certifi">>,{pkg,<<"certifi">>,<<"2.5.2">>},1},
{<<"goldrush">>,{pkg,<<"goldrush">>,<<"0.1.9">>},1},
{<<"hackney">>,{pkg,<<"hackney">>,<<"1.16.0">>},0},
{<<"idna">>,{pkg,<<"idna">>,<<"6.0.1">>},1},
{<<"jiffy">>,{pkg,<<"jiffy">>,<<"1.0.8">>},0},
{<<"lager">>,{pkg,<<"lager">>,<<"3.8.1">>},0},
{<<"metrics">>,{pkg,<<"metrics">>,<<"1.0.1">>},1},
{<<"mimerl">>,{pkg,<<"mimerl">>,<<"1.2.0">>},1},
{<<"parse_trans">>,{pkg,<<"parse_trans">>,<<"3.3.0">>},1},
{<<"quickrand">>,
{git,"https://github.com/okeuday/quickrand.git",
{ref,"c80077162f32c10002219f70e0afadb71e05f88c"}},
1},
{<<"ssl_verify_fun">>,{pkg,<<"ssl_verify_fun">>,<<"1.1.6">>},1},
{<<"unicode_util_compat">>,{pkg,<<"unicode_util_compat">>,<<"0.5.0">>},2},
{<<"uuid">>,
{git,"https://github.com/okeuday/uuid.git",
{ref,"9312cc158a94c76e40c82ca45fd5056fb191c889"}},
0}]}.
[
{pkg_hash,[
{<<"certifi">>, <<"B7CFEAE9D2ED395695DD8201C57A2D019C0C43ECAF8B8BCB9320B40D6662F340">>},
{<<"goldrush">>, <<"F06E5D5F1277DA5C413E84D5A2924174182FB108DABB39D5EC548B27424CD106">>},
{<<"hackney">>, <<"5096AC8E823E3A441477B2D187E30DD3FFF1A82991A806B2003845CE72CE2D84">>},
{<<"idna">>, <<"1D038FB2E7668CE41FBF681D2C45902E52B3CB9E9C77B55334353B222C2EE50C">>},
{<<"jiffy">>, <<"60E36F00BE35E5AC6E6CF2D4CAF3BDF3103D4460AFF385F543A8D7DF2D6D9613">>},
{<<"lager">>, <<"652EDFFBBEFFDE78F12220E1C64F6F6BFB173A8738CE73AF6ED3B1723A71C5BD">>},
{<<"metrics">>, <<"25F094DEA2CDA98213CECC3AEFF09E940299D950904393B2A29D191C346A8486">>},
{<<"mimerl">>, <<"67E2D3F571088D5CFD3E550C383094B47159F3EEE8FFA08E64106CDF5E981BE3">>},
{<<"parse_trans">>, <<"09765507A3C7590A784615CFD421D101AEC25098D50B89D7AA1D66646BC571C1">>},
{<<"ssl_verify_fun">>, <<"CF344F5692C82D2CD7554F5EC8FD961548D4FD09E7D22F5B62482E5AEAEBD4B0">>},
{<<"unicode_util_compat">>, <<"8516502659002CEC19E244EBD90D312183064BE95025A319A6C7E89F4BCCD65B">>}]},
{pkg_hash_ext,[
{<<"certifi">>, <<"3B3B5F36493004AC3455966991EAF6E768CE9884693D9968055AEEEB1E575040">>},
{<<"goldrush">>, <<"99CB4128CFFCB3227581E5D4D803D5413FA643F4EB96523F77D9E6937D994CEB">>},
{<<"hackney">>, <<"3BF0BEBBD5D3092A3543B783BF065165FA5D3AD4B899B836810E513064134E18">>},
{<<"idna">>, <<"A02C8A1C4FD601215BB0B0324C8A6986749F807CE35F25449EC9E69758708122">>},
{<<"jiffy">>, <<"F9AE986BA5A0854EB48CF6A76192D9367086DA86C20197DA430630BE7C087A4E">>},
{<<"lager">>, <<"F8945D2CBAAB3560C2373F0808EB6262E7CFF1BD2EC550FD7DB38716180B7465">>},
{<<"metrics">>, <<"69B09ADDDC4F74A40716AE54D140F93BEB0FB8978D8636EADED0C31B6F099F16">>},
{<<"mimerl">>, <<"F278585650AA581986264638EBF698F8BB19DF297F66AD91B18910DFC6E19323">>},
{<<"parse_trans">>, <<"17EF63ABDE837AD30680EA7F857DD9E7CED9476CDD7B0394432AF4BFC241B960">>},
{<<"ssl_verify_fun">>, <<"BDB0D2471F453C88FF3908E7686F86F9BE327D065CC1EC16FA4540197EA04680">>},
{<<"unicode_util_compat">>, <<"D48D002E15F5CC105A696CF2F1BBB3FC72B4B770A184D8420C8DB20DA2674B38">>}]}
].
23 changes: 23 additions & 0 deletions src/consulerl.app.src
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{application, consulerl,
[{description, "An OTP application"},
{vsn, "0.1.0"},
{registered, []},
{mod, {consulerl_app, []}},
{applications,
[kernel,
stdlib,
hackney,
uuid,
jiffy,
lager
]},
{env,[
{hostname, "127.0.0.1"},
{port, 8500},
{acl, []}
]},
{modules, []},

{licenses, ["Apache 2.0"]},
{links, []}
]}.
11 changes: 4 additions & 7 deletions src/consulerl_json.erl
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
-module(consulerl_json).

%% API
-export([
decode/2,
encode/2
]).
-export([decode/2, encode/2]).

-spec decode(atom(), iodata()) -> term().
decode(jiffy, IoData) ->
Decoded = jiffy:decode(IoData, [return_maps]),
consulerl_atom:keys_to_atom(Decoded).
Decoded = jiffy:decode(IoData, [return_maps]),
consulerl_atom:keys_to_atom(Decoded).

-spec encode(atom(), term()) -> iodata().
encode(jiffy, Term) ->
jiffy:encode(Term, []).
jiffy:encode(Term, []).