-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #67 from nomasystems/build/0-1-2
build: 0.1.2
- Loading branch information
Showing
25 changed files
with
1,505 additions
and
904 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,9 @@ | ||
name: erf ci | ||
name: CI | ||
|
||
on: | ||
push: | ||
branches: [main] | ||
pull_request: | ||
branches: [main] | ||
|
||
env: | ||
OTP-VERSION: 25.2.3 | ||
|
@@ -17,10 +16,6 @@ jobs: | |
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- uses: webfactory/[email protected] | ||
with: | ||
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} | ||
|
||
- uses: erlef/setup-beam@v1 | ||
with: | ||
otp-version: ${{ env.OTP-VERSION }} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,10 +15,6 @@ jobs: | |
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- uses: webfactory/[email protected] | ||
with: | ||
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} | ||
|
||
- uses: erlef/setup-beam@v1 | ||
with: | ||
otp-version: ${{ env.OTP-VERSION }} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{application, users, [ | ||
{description, "A tiny app exemplifying erf usage"}, | ||
{vsn, "0.1.0"}, | ||
{registered, []}, | ||
{applications, [kernel, stdlib, erf]}, | ||
{mod, {users, []}}, | ||
{env, []} | ||
]}. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
-module(users). | ||
|
||
-behaviour(application). | ||
|
||
-export([start/2, stop/1]). | ||
|
||
start(_StartType, _StartArgs) -> | ||
users_sup:start_link(). | ||
|
||
stop(_State) -> | ||
ok. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
%% An <code>erf</code> postprocess middleware for the users REST API. | ||
-module(users_postprocess). | ||
|
||
-behaviour(erf_postprocess_middleware). | ||
|
||
%%% EXTERNAL EXPORTS | ||
-export([ | ||
postprocess/2 | ||
]). | ||
|
||
%%%------------------------------------------------------- | ||
%%% EXTERNAL EXPORTS | ||
%%%------------------------------------------------------- | ||
% Here we exemplify how information previously inserted on the request context | ||
% can be used to condition the request processing flow. | ||
postprocess(#{method := post, context := #{post_init := PostInitT}} = _Request, Response) -> | ||
PostEndT = erlang:timestamp(), | ||
Diff = timer:now_diff(PostEndT, PostInitT), | ||
io:format("Post time diff : ~p~n", [Diff]), | ||
Response; | ||
postprocess(_Request, Response) -> | ||
Response. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
%% An <code>erf</code> preprocess middleware for the users REST API. | ||
-module(users_preprocess). | ||
|
||
-behaviour(erf_preprocess_middleware). | ||
|
||
%%% EXTERNAL EXPORTS | ||
-export([ | ||
preprocess/1 | ||
]). | ||
|
||
%%%------------------------------------------------------- | ||
%%% EXTERNAL EXPORTS | ||
%%%------------------------------------------------------- | ||
preprocess(#{headers := Headers} = Request) -> | ||
Authorization = proplists:get_value(<<"x-api-key">>, Headers, undefined), | ||
case is_authorized(Authorization) of | ||
false -> | ||
% For delete operations, if delete is disabled, | ||
% we skip to the post-process middlewares. | ||
{stop, {403, [], <<"Missing valid basic authorization header">>}}; | ||
true -> | ||
PostInitT = erlang:timestamp(), | ||
Context = maps:get(context, Request, #{}), | ||
% We store the current timestamp on the the request context | ||
% for latter use. | ||
Request#{context => Context#{post_init => PostInitT}} | ||
end. | ||
|
||
%%%------------------------------------------------------- | ||
%%% INTERNAL FUNCTIONS | ||
%%%------------------------------------------------------- | ||
is_authorized(undefined) -> | ||
false; | ||
is_authorized(<<"api-key">>) -> | ||
true; | ||
is_authorized(_) -> | ||
false. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
-module(users_sup). | ||
|
||
%%% BEHAVIOURS | ||
-behaviour(supervisor). | ||
|
||
%%% START/STOP EXPORTS | ||
-export([start_link/0]). | ||
|
||
%%% INTERNAL EXPORTS | ||
-export([init/1]). | ||
|
||
%%%------------------------------------------------------- | ||
%%% START/STOP EXPORTS | ||
%%%------------------------------------------------------- | ||
start_link() -> | ||
supervisor:start_link({local, ?MODULE}, ?MODULE, []). | ||
|
||
%%%------------------------------------------------------- | ||
%%% INTERNAL EXPORTS | ||
%%%------------------------------------------------------- | ||
init([]) -> | ||
% Users storage | ||
ets:new(users, [public, named_table]), | ||
UsersAPIConf = #{ | ||
spec_path => filename:join(code:priv_dir(users), <<"users.openapi.json">>), | ||
callback => users_callback, | ||
preprocess_middlewares => [users_preprocess], | ||
postprocess_middlewares => [users_postprocess], | ||
port => 8080 | ||
}, | ||
UsersChildSpec = { | ||
public_api_server, | ||
{erf, start_link, [UsersAPIConf]}, | ||
permanent, | ||
5000, | ||
worker, | ||
[erf] | ||
}, | ||
{ok, {{one_for_one, 5, 10}, [UsersChildSpec]}}. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,13 +4,13 @@ | |
]}. | ||
|
||
{deps, [ | ||
{elli, {git, "git@github.com:elli-lib/elli.git", {branch, "main"}}}, | ||
{ndto, {git, "git@github.com:nomasystems/ndto.git", {branch, "main"}}}, | ||
{njson, {git, "git@github.com:nomasystems/njson.git", {branch, "main"}}} | ||
{elli, {git, "https://github.com/elli-lib/elli.git", {branch, "main"}}}, | ||
{ndto, {git, "https://github.com/nomasystems/ndto.git", {tag, "0.3.1"}}}, | ||
{njson, {git, "https://github.com/nomasystems/njson.git", {tag, "2.0.0"}}} | ||
]}. | ||
|
||
{plugins, [ | ||
{rebar3_ndto, {git, "git@github.com:nomasystems/rebar3_ndto.git", {tag, "0.1.0"}}} | ||
{rebar3_ndto, {git, "https://github.com/nomasystems/rebar3_ndto.git", {tag, "0.3.1"}}} | ||
]}. | ||
{ndto, [ | ||
{specs, [ | ||
|
@@ -26,21 +26,24 @@ | |
]}. | ||
|
||
{project_plugins, [ | ||
{erlfmt, {git, "[email protected]:WhatsApp/erlfmt.git", {branch, "main"}}}, | ||
{gradualizer, {git, "git@github.com:josefs/Gradualizer.git", {branch, "master"}}}, | ||
erlfmt, | ||
{gradualizer, {git, "https://github.com/josefs/Gradualizer.git", {tag, "0.3.0"}}}, | ||
rebar3_ex_doc | ||
]}. | ||
{erlfmt, [write]}. | ||
|
||
{profiles, [ | ||
{examples, [ | ||
{extra_src_dirs, ["examples"]} | ||
{project_app_dirs, ["examples/users", "."]}, | ||
{shell, [ | ||
{apps, [users]} | ||
]} | ||
]}, | ||
{test, [ | ||
{erl_opts, [nowarn_export_all]}, | ||
{deps, [ | ||
{meck, {git, "git@github.com:eproxus/meck.git", {branch, "master"}}}, | ||
{nct_util, {git, "git@github.com:nomasystems/nct_util.git", {branch, "main"}}} | ||
{meck, {git, "https://github.com/eproxus/meck.git", {branch, "master"}}}, | ||
{nct_util, {git, "https://github.com/nomasystems/nct_util.git", {branch, "main"}}} | ||
]} | ||
]} | ||
]}. | ||
|
@@ -88,5 +91,7 @@ | |
|
||
{gradualizer_opts, [ | ||
%% TODO: address | ||
{exclude, ["src/erf_oas_3_0.erl", "src/erf_router.erl"]} | ||
{exclude, [ | ||
"src/erf_router.erl" | ||
]} | ||
]}. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
[{<<"elli">>, | ||
{git,"git@github.com:elli-lib/elli.git", | ||
{git,"https://github.com/elli-lib/elli.git", | ||
{ref,"3ec352293ef493c142767127f4113c85541c32cc"}}, | ||
0}, | ||
{<<"ncalendar">>, | ||
{git,"git@github.com:nomasystems/ncalendar.git", | ||
{ref,"0237766de898145bbd55bb26eef8917535f341ca"}}, | ||
{git,"https://github.com/nomasystems/ncalendar.git", | ||
{ref,"aa5615f6723585e45e82fa5524cb976cdfe3d7f7"}}, | ||
1}, | ||
{<<"ndto">>, | ||
{git,"git@github.com:nomasystems/ndto.git", | ||
{ref,"491a2441e43afa2fb037c6e7e826c45a383e3bd9"}}, | ||
{git,"https://github.com/nomasystems/ndto.git", | ||
{ref,"295281b72ea4ac85e7c4d5ca42337c68b1aac137"}}, | ||
0}, | ||
{<<"njson">>, | ||
{git,"git@github.com:nomasystems/njson.git", | ||
{ref,"76ab40033ee977f876e7b3addca5de981ff4a9ef"}}, | ||
{git,"https://github.com/nomasystems/njson.git", | ||
{ref,"94c586b92a7e24c403089cdbe2994b7e7c87b9cc"}}, | ||
0}]. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.