Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Dialyzed the hell out of stuff.

  • Loading branch information...
commit 943fb740577b504968597cc749ac38e305a08b5f 1 parent 7b50669
@Licenser Licenser authored
View
97 Makefile
@@ -1,53 +1,76 @@
-APP_NAME=wiggle
-APP_DIR=apps/$(APP_NAME)
-OBJ=$(shell ls $(APP_DIR)/src/*.erl | sed -e 's/\.erl$$/.beam/' | sed -e 's;^$(APP_DIR)/src;$(APP_DIR)/ebin;g') $(shell ls $(APP_DIR)/src/*.app.src | sed -e 's/\.src$$//g' | sed -e 's;^$(APP_DIR)/src;$(APP_DIR)/ebin;g')
-DEPS=$(shell cat rebar.config |sed -e 's/%.*//'| sed -e '/{\(\w\+\), [^,]\+, {\w\+, [^,]\+, {[^,]\+, [^}]\+}}},\?/!d' | sed -e 's;{\(\w\+\), [^,]\+, {\w\+, [^,]\+, {[^,]\+, [^}]\+}}},\?;deps/\1/rebar.config;')
-ERL=erl
-PA=$(shell pwd)/$(APP_DIR)/ebin
-ERL_LIBS=`pwd`/deps/
-REBAR=./rebar
+REBAR = $(shell pwd)/rebar
-.PHONY: rel clean package deps
+.PHONY: deps rel stagedevrel
-all: $(DEPS) $(OBJ)
+all: deps compile
+
+compile:
+ $(REBAR) compile
deps:
$(REBAR) get-deps
- $(REBAR) update-deps
-
-rel: all
- -rm -r rel/$(APP_NAME)
- cd rel; ../rebar generate
-echo:
- echo $(DEPS)
-
-tar: rel
- cd rel; tar jcvf $(APP_NAME).tar.bz2 $(APP_NAME)
-
-test:
- $(REBAR) skip_deps=true eunit
clean:
$(REBAR) clean
make -C rel/pkg clean
- -rm *.beam erl_crash.dump
- -rm -r rel/$(APP_NAME)
- -rm rel/$(APP_NAME).tar.bz2
-$(DEPS):
- $(REBAR) get-deps
- $(REBAR) compile
+distclean: clean devclean relclean
+ $(REBAR) delete-deps
-$(APP_DIR)/ebin/%.app: $(APP_DIR)/src/%.app.src
- $(REBAR) compile
+test: all
+ $(REBAR) skip_deps=true xref
+ $(REBAR) skip_deps=true eunit
-$(APP_DIR)/ebin/%.beam: $(APP_DIR)/src/%.erl
- $(REBAR) compile
+rel: all
+ $(REBAR) generate
-shell: all
- ERL_LIBS="$(ERL_LIBS)" $(ERL) -pa $(PA) -config standalone -sname $(APP_NAME)
- [ -f *.beam ] && rm *.beam || true
- [ -f erl_crash.dump ] && rm erl_crash.dump || true
+relclean:
+ rm -rf rel/wiggle
package: rel
make -C rel/pkg package
+
+###
+### Docs
+###
+docs:
+ $(REBAR) skip_deps=true doc
+
+##
+## Developer targets
+##
+
+stage : rel
+ $(foreach dep,$(wildcard deps/* wildcard apps/*), rm -rf rel/wiggle/lib/$(shell basename $(dep))-* && ln -sf $(abspath $(dep)) rel/wiggle/lib;)
+
+##
+## Dialyzer
+##
+APPS = kernel stdlib sasl erts ssl tools os_mon runtime_tools crypto inets \
+ xmerl webtool snmp public_key mnesia eunit syntax_tools compiler
+COMBO_PLT = $(HOME)/.wiggle_combo_dialyzer_plt
+
+check_plt: deps compile
+ dialyzer --check_plt --plt $(COMBO_PLT) --apps $(APPS) \
+ deps/*/ebin apps/*/ebin
+
+build_plt: deps compile
+ dialyzer --build_plt --output_plt $(COMBO_PLT) --apps $(APPS) \
+ deps/*/ebin apps/*/ebin
+
+dialyzer: deps compile
+ @echo
+ @echo Use "'make check_plt'" to check PLT prior to using this target.
+ @echo Use "'make build_plt'" to build PLT prior to using this target.
+ @echo
+ @sleep 1
+ dialyzer -Wno_return --plt $(COMBO_PLT) deps/*/ebin apps/*/ebin | grep -v -f dialyzer.mittigate
+
+
+cleanplt:
+ @echo
+ @echo "Are you sure? It takes about 1/2 hour to re-build."
+ @echo Deleting $(COMBO_PLT) in 5 seconds.
+ @echo
+ sleep 5
+ rm $(COMBO_PLT)
View
2  apps/wiggle/src/wiggle.erl
@@ -2,6 +2,8 @@
-export([start/0]).
+-ignore_xref([start/0]).
+
start() ->
application:start(mdns_client_lib),
application:start(libsnarl),
View
56 apps/wiggle/src/wiggle_dataset_handler.erl
@@ -3,21 +3,35 @@
%% @doc Hello world handler.
-module(wiggle_dataset_handler).
--export([init/3,
+-export([init/3,
rest_init/2]).
--export([content_types_provided/2,
+-export([content_types_provided/2,
content_types_accepted/2,
allowed_methods/2,
resource_exists/2,
forbidden/2,
options/2,
is_authorized/2]).
+
-export([to_json/2,
from_json/2]).
+
+-ignore_xref([to_json/2,
+ from_json/2,
+ allowed_methods/2,
+ content_types_accepted/2,
+ content_types_provided/2,
+ delete_resource/2,
+ forbidden/2,
+ init/3,
+ is_authorized/2,
+ options/2,
+ resource_exists/2,
+ rest_init/2]).
-record(state, {path, method, version, token, content, reply}).
-
+
init(_Transport, _Req, []) ->
{upgrade, protocol, cowboy_http_rest}.
@@ -25,7 +39,7 @@ rest_init(Req, _) ->
{Method, Req1} = cowboy_http_req:method(Req),
{[<<"api">>, Version, <<"datasets">> | Path], Req2} = cowboy_http_req:path(Req1),
{Token, Req3} = case cowboy_http_req:header(<<"X-Snarl-Token">>, Req2) of
- {undefined, ReqX} ->
+ {undefined, ReqX} ->
{undefined, ReqX};
{TokenX, ReqX} ->
{ok, ReqX1} = cowboy_http_req:set_resp_header(<<"X-Snarl-Token">>, TokenX, ReqX),
@@ -33,12 +47,12 @@ rest_init(Req, _) ->
end,
{ok, Req4} = cowboy_http_req:set_resp_header(<<"Access-Control-Allow-Origin">>, <<"*">>, Req3),
{ok, Req5} = cowboy_http_req:set_resp_header(
- <<"Access-Control-Allow-Headers">>,
+ <<"Access-Control-Allow-Headers">>,
<<"Content-Type, X-Snarl-Token">>, Req4),
{ok, Req6} = cowboy_http_req:set_resp_header(
- <<"Access-Control-Expose-Headers">>,
+ <<"Access-Control-Expose-Headers">>,
<<"X-Snarl-Token">>, Req5),
- State = #state{version = Version,
+ State = #state{version = Version,
method = Method,
token = Token,
path = Path},
@@ -47,10 +61,10 @@ rest_init(Req, _) ->
options(Req, State) ->
Methods = allowed_methods(Req, State, State#state.path),
{ok, Req1} = cowboy_http_req:set_resp_header(
- <<"Access-Control-Allow-Methods">>,
+ <<"Access-Control-Allow-Methods">>,
string:join(
lists:map(fun erlang:atom_to_list/1,
- ['HEAD', 'OPTIONS' | Methods]), ", "), Req),
+ ['HEAD', 'OPTIONS' | Methods]), ", "), Req),
{ok, Req1, State}.
content_types_provided(Req, State) ->
@@ -77,25 +91,25 @@ resource_exists(Req, State = #state{path = []}) ->
resource_exists(Req, State = #state{path = [Dataset]}) ->
case libsniffle:dataset_attribute_get(Dataset) of
- {reply, not_found} ->
+ not_found ->
{false, Req, State};
- {reply, _} ->
+ {ok, _} ->
{true, Req, State}
end.
-is_authorized(Req, State = #state{method = 'OPTIONS'}) ->
+is_authorized(Req, State = #state{method = 'OPTIONS'}) ->
{true, Req, State};
-is_authorized(Req, State = #state{token = undefined}) ->
+is_authorized(Req, State = #state{token = undefined}) ->
{{false, <<"X-Snarl-Token">>}, Req, State};
-is_authorized(Req, State) ->
+is_authorized(Req, State) ->
{true, Req, State}.
-forbidden(Req, State = #state{method = 'OPTIONS'}) ->
+forbidden(Req, State = #state{method = 'OPTIONS'}) ->
{false, Req, State};
-forbidden(Req, State = #state{token = undefined}) ->
+forbidden(Req, State = #state{token = undefined}) ->
{true, Req, State};
forbidden(Req, State = #state{path = []}) ->
@@ -116,11 +130,11 @@ to_json(Req, State) ->
{jsx:encode(Reply), Req1, State1}.
handle_request(Req, State = #state{path = []}) ->
- {reply, {ok, Res}} = libsniffle:dataset_list(),
+ {ok, Res} = libsniffle:dataset_list(),
{Res, Req, State};
handle_request(Req, State = #state{path = [Dataset]}) ->
- {reply, Res} = libsniffle:dataset_attribute_get(Dataset),
+ {ok, Res} = libsniffle:dataset_attribute_get(Dataset),
{Res, Req, State}.
@@ -148,10 +162,10 @@ handle_write(Req, State, _Body) ->
allowed(Token, Perm) ->
case libsnarl:allowed({token, Token}, Perm) of
- {reply,not_found} ->
+ not_found ->
true;
- {reply, true} ->
+ true ->
false;
- {reply, false} ->
+ false ->
true
end.
View
44 apps/wiggle/src/wiggle_group_handler.erl
@@ -17,9 +17,23 @@
forbidden/2,
options/2,
is_authorized/2]).
+
-export([to_json/2,
from_json/2]).
+-ignore_xref([to_json/2,
+ from_json/2,
+ allowed_methods/2,
+ content_types_accepted/2,
+ content_types_provided/2,
+ delete_resource/2,
+ forbidden/2,
+ init/3,
+ is_authorized/2,
+ options/2,
+ resource_exists/2,
+ rest_init/2]).
+
-record(state, {path, method, version, token, content, reply}).
init(_Transport, _Req, []) ->
@@ -86,11 +100,11 @@ allowed_methods(_Version, _Token, [_Group, <<"permissions">> | _Permission]) ->
resource_exists(Req, State = #state{path = [Group, <<"permissions">> | Permission]}) ->
case {erlangify_permission(Permission), libsnarl:group_get(Group)} of
- {_, {reply, {ok, not_found}}} ->
+ {_, not_found} ->
{false, Req, State};
- {[], {reply, {ok, _}}} ->
+ {[], {ok, _}} ->
{true, Req, State};
- {P, {reply, {ok, {group, _Name, Permissions, _}}}} ->
+ {P, {ok, {group, _Name, Permissions, _}}} ->
{lists:member(P, Permissions), Req, State}
end;
@@ -99,9 +113,9 @@ resource_exists(Req, State = #state{path = []}) ->
resource_exists(Req, State = #state{path = [Group | _]}) ->
case libsnarl:group_get(Group) of
- {reply, {ok, not_found}} ->
+ {ok, not_found} ->
{false, Req, State};
- {reply, {ok, _}} ->
+ {ok, _} ->
{true, Req, State}
end.
@@ -163,16 +177,16 @@ to_json(Req, State) ->
{jsx:encode(Reply), Req1, State1}.
handle_request(Req, State = #state{path = []}) ->
- {reply, {ok, Res}} = libsnarl:group_list(),
+ {ok, Res} = libsnarl:group_list(),
{Res, Req, State};
handle_request(Req, State = #state{path = [Group]}) ->
- {reply, {ok, {group, Name, Permissions, _}}} = libsnarl:group_get(Group),
+ {ok, {group, Name, Permissions, _}} = libsnarl:group_get(Group),
{[{name, Name},
{permissions, lists:map(fun jsonify_permissions/1, Permissions)}], Req, State};
handle_request(Req, State = #state{path = [Group, <<"permissions">>]}) ->
- {reply, {ok, {group, _Name, Permissions, _}}} = libsnarl:group_get(Group),
+ {ok, {group, _Name, Permissions, _}} = libsnarl:group_get(Group),
{lists:map(fun jsonify_permissions/1, Permissions), Req, State}.
%%--------------------------------------------------------------------
@@ -191,12 +205,12 @@ from_json(Req, State) ->
{Reply, Req2, State1}.
handle_write(Req, State = #state{path = [Group]}, _Body) ->
- libsnarl:group_add(Group),
+ ok = libsnarl:group_add(Group),
{true, Req, State};
handle_write(Req, State = #state{path = [Group, <<"permissions">> | Permission]}, _Body) ->
P = erlangify_permission(Permission),
- {reply, ok} = libsnarl:group_grant(Group, P),
+ ok = libsnarl:group_grant(Group, P),
{true, Req, State}.
@@ -206,11 +220,11 @@ handle_write(Req, State = #state{path = [Group, <<"permissions">> | Permission]}
delete_resource(Req, State = #state{path = [Group, <<"permissions">> | Permission]}) ->
P = erlangify_permission(Permission),
- {reply, ok} = libsnarl:group_revoke(Group, P),
+ ok = libsnarl:group_revoke(Group, P),
{true, Req, State};
delete_resource(Req, State = #state{path = [Group]}) ->
- {reply, ok} = libsnarl:group_delete(Group),
+ ok = libsnarl:group_delete(Group),
{true, Req, State}.
%% Internal Functions
@@ -235,11 +249,11 @@ jsonify_permissions(P) ->
allowed(Token, Perm) ->
case libsnarl:allowed({token, Token}, Perm) of
- {reply,not_found} ->
+ not_found ->
true;
- {reply, true} ->
+ true ->
false;
- {reply, false} ->
+ false ->
true
end.
View
57 apps/wiggle/src/wiggle_hypervisor_handler.erl
@@ -3,10 +3,10 @@
%% @doc Hello world handler.
-module(wiggle_hypervisor_handler).
--export([init/3,
+-export([init/3,
rest_init/2]).
--export([content_types_provided/2,
+-export([content_types_provided/2,
content_types_accepted/2,
allowed_methods/2,
resource_exists/2,
@@ -17,8 +17,21 @@
-export([to_json/2,
from_json/2]).
+-ignore_xref([to_json/2,
+ from_json/2,
+ allowed_methods/2,
+ content_types_accepted/2,
+ content_types_provided/2,
+ delete_resource/2,
+ forbidden/2,
+ init/3,
+ is_authorized/2,
+ options/2,
+ resource_exists/2,
+ rest_init/2]).
+
-record(state, {path, method, version, token, content, reply}).
-
+
init(_Transport, _Req, []) ->
{upgrade, protocol, cowboy_http_rest}.
@@ -26,7 +39,7 @@ rest_init(Req, _) ->
{Method, Req1} = cowboy_http_req:method(Req),
{[<<"api">>, Version, <<"hypervisors">> | Path], Req2} = cowboy_http_req:path(Req1),
{Token, Req3} = case cowboy_http_req:header(<<"X-Snarl-Token">>, Req2) of
- {undefined, ReqX} ->
+ {undefined, ReqX} ->
{undefined, ReqX};
{TokenX, ReqX} ->
{ok, ReqX1} = cowboy_http_req:set_resp_header(<<"X-Snarl-Token">>, TokenX, ReqX),
@@ -34,12 +47,12 @@ rest_init(Req, _) ->
end,
{ok, Req4} = cowboy_http_req:set_resp_header(<<"Access-Control-Allow-Origin">>, <<"*">>, Req3),
{ok, Req5} = cowboy_http_req:set_resp_header(
- <<"Access-Control-Allow-Headers">>,
+ <<"Access-Control-Allow-Headers">>,
<<"Content-Type, X-Snarl-Token">>, Req4),
{ok, Req6} = cowboy_http_req:set_resp_header(
- <<"Access-Control-Expose-Headers">>,
+ <<"Access-Control-Expose-Headers">>,
<<"X-Snarl-Token">>, Req5),
- State = #state{version = Version,
+ State = #state{version = Version,
method = Method,
token = Token,
path = Path},
@@ -48,10 +61,10 @@ rest_init(Req, _) ->
options(Req, State) ->
Methods = allowed_methods(Req, State, State#state.path),
{ok, Req1} = cowboy_http_req:set_resp_header(
- <<"Access-Control-Allow-Methods">>,
+ <<"Access-Control-Allow-Methods">>,
string:join(
lists:map(fun erlang:atom_to_list/1,
- ['HEAD', 'OPTIONS' | Methods]), ", "), Req),
+ ['HEAD', 'OPTIONS' | Methods]), ", "), Req),
{ok, Req1, State}.
content_types_provided(Req, State) ->
@@ -78,25 +91,25 @@ resource_exists(Req, State = #state{path = []}) ->
resource_exists(Req, State = #state{path = [Hypervisor | _]}) ->
case libsniffle:hypervisor_resource_get(Hypervisor) of
- {reply, not_found} ->
+ not_found ->
{false, Req, State};
- {reply, _} ->
+ {ok, _} ->
{true, Req, State}
end.
-is_authorized(Req, State = #state{method = 'OPTIONS'}) ->
+is_authorized(Req, State = #state{method = 'OPTIONS'}) ->
{true, Req, State};
-is_authorized(Req, State = #state{token = undefined}) ->
+is_authorized(Req, State = #state{token = undefined}) ->
{{false, <<"X-Snarl-Token">>}, Req, State};
-is_authorized(Req, State) ->
+is_authorized(Req, State) ->
{true, Req, State}.
-forbidden(Req, State = #state{method = 'OPTIONS'}) ->
+forbidden(Req, State = #state{method = 'OPTIONS'}) ->
{false, Req, State};
-forbidden(Req, State = #state{token = undefined}) ->
+forbidden(Req, State = #state{token = undefined}) ->
{true, Req, State};
forbidden(Req, State = #state{path = []}) ->
@@ -117,12 +130,12 @@ to_json(Req, State) ->
{jsx:encode(Reply), Req1, State1}.
handle_request(Req, State = #state{path = []}) ->
- {reply, {ok, Res}} = libsniffle:hypervisor_list(),
+ {ok, Res} = libsniffle:hypervisor_list(),
{Res, Req, State};
handle_request(Req, State = #state{path = [Hypervisor]}) ->
- {reply, Dict} = libsniffle:hypervisor_resource_get(Hypervisor),
- {[{name, Hypervisor}|dict:to_list(Dict)], Req, State}.
+ {ok, Res} = libsniffle:hypervisor_resource_get(Hypervisor),
+ {[{name, Hypervisor}| Res], Req, State}.
%%--------------------------------------------------------------------
%% PUT
@@ -151,10 +164,10 @@ handle_write(Req, State, _Body) ->
allowed(Token, Perm) ->
case libsnarl:allowed({token, Token}, Perm) of
- {reply,not_found} ->
+ not_found ->
true;
- {reply, true} ->
+ true ->
false;
- {reply, false} ->
+ false ->
true
end.
View
85 apps/wiggle/src/wiggle_iprange_handler.erl
@@ -3,10 +3,10 @@
%% @doc Hello world handler.
-module(wiggle_iprange_handler).
--export([init/3,
+-export([init/3,
rest_init/2]).
--export([content_types_provided/2,
+-export([content_types_provided/2,
content_types_accepted/2,
allowed_methods/2,
resource_exists/2,
@@ -18,8 +18,21 @@
-export([to_json/2,
from_json/2]).
+-ignore_xref([to_json/2,
+ from_json/2,
+ allowed_methods/2,
+ content_types_accepted/2,
+ content_types_provided/2,
+ delete_resource/2,
+ forbidden/2,
+ init/3,
+ is_authorized/2,
+ options/2,
+ resource_exists/2,
+ rest_init/2]).
+
-record(state, {path, method, version, token, content, reply}).
-
+
init(_Transport, _Req, []) ->
{upgrade, protocol, cowboy_http_rest}.
@@ -27,7 +40,7 @@ rest_init(Req, _) ->
{Method, Req1} = cowboy_http_req:method(Req),
{[<<"api">>, Version, <<"ipranges">> | Path], Req2} = cowboy_http_req:path(Req1),
{Token, Req3} = case cowboy_http_req:header(<<"X-Snarl-Token">>, Req2) of
- {undefined, ReqX} ->
+ {undefined, ReqX} ->
{undefined, ReqX};
{TokenX, ReqX} ->
{ok, ReqX1} = cowboy_http_req:set_resp_header(<<"X-Snarl-Token">>, TokenX, ReqX),
@@ -35,12 +48,12 @@ rest_init(Req, _) ->
end,
{ok, Req4} = cowboy_http_req:set_resp_header(<<"Access-Control-Allow-Origin">>, <<"*">>, Req3),
{ok, Req5} = cowboy_http_req:set_resp_header(
- <<"Access-Control-Allow-Headers">>,
+ <<"Access-Control-Allow-Headers">>,
<<"Content-Type, X-Snarl-Token">>, Req4),
{ok, Req6} = cowboy_http_req:set_resp_header(
- <<"Access-Control-Expose-Headers">>,
+ <<"Access-Control-Expose-Headers">>,
<<"X-Snarl-Token">>, Req5),
- State = #state{version = Version,
+ State = #state{version = Version,
method = Method,
token = Token,
path = Path},
@@ -49,10 +62,10 @@ rest_init(Req, _) ->
options(Req, State) ->
Methods = allowed_methods(Req, State, State#state.path),
{ok, Req1} = cowboy_http_req:set_resp_header(
- <<"Access-Control-Allow-Methods">>,
+ <<"Access-Control-Allow-Methods">>,
string:join(
lists:map(fun erlang:atom_to_list/1,
- ['HEAD', 'OPTIONS' | Methods]), ", "), Req),
+ ['HEAD', 'OPTIONS' | Methods]), ", "), Req),
{ok, Req1, State}.
content_types_provided(Req, State) ->
@@ -79,25 +92,25 @@ resource_exists(Req, State = #state{path = []}) ->
resource_exists(Req, State = #state{path = [Iprange]}) ->
case libsniffle:iprange_get(Iprange) of
- {reply, {ok, not_found}} ->
+ not_found ->
{false, Req, State};
- {reply, _} ->
+ {ok, _} ->
{true, Req, State}
end.
-is_authorized(Req, State = #state{method = 'OPTIONS'}) ->
+is_authorized(Req, State = #state{method = 'OPTIONS'}) ->
{true, Req, State};
-is_authorized(Req, State = #state{token = undefined}) ->
+is_authorized(Req, State = #state{token = undefined}) ->
{{false, <<"X-Snarl-Token">>}, Req, State};
-is_authorized(Req, State) ->
+is_authorized(Req, State) ->
{true, Req, State}.
-forbidden(Req, State = #state{method = 'OPTIONS'}) ->
+forbidden(Req, State = #state{method = 'OPTIONS'}) ->
{false, Req, State};
-forbidden(Req, State = #state{token = undefined}) ->
+forbidden(Req, State = #state{token = undefined}) ->
{true, Req, State};
forbidden(Req, State = #state{path = []}) ->
@@ -124,22 +137,23 @@ to_json(Req, State) ->
{jsx:encode(Reply), Req1, State1}.
handle_request(Req, State = #state{path = []}) ->
- {reply, {ok, Res}} = libsniffle:iprange_list(),
+ {ok, Res} = libsniffle:iprange_list(),
{Res, Req, State};
handle_request(Req, State = #state{path = [Iprange]}) ->
- {reply, {ok, {iprange,
- Name,
- Network,
- Gateway,
- Netmask,
- First,
- Last,
- Current,
- _,
- Free}}} = libsniffle:iprange_get(Iprange),
+ {ok, {iprange,
+ Name,
+ Network,
+ Gateway,
+ Netmask,
+ First,
+ Last,
+ Current,
+ Tag,
+ Free}} = libsniffle:iprange_get(Iprange),
{[
{name, Name},
+ {tag, Tag},
{network, ip_to_str(Network)},
{gateway, ip_to_str(Gateway)},
{netmask, ip_to_str(Netmask)},
@@ -171,8 +185,13 @@ handle_write(Req, State = #state{path = [Iprange]}, Body) ->
{<<"netmask">>, Netmask} = lists:keyfind(<<"netmask">>, 1, Body),
{<<"first">>, First} = lists:keyfind(<<"first">>, 1, Body),
{<<"last">>, Last} = lists:keyfind(<<"last">>, 1, Body),
- % We use the name as tag.
- {reply, ok} = libsniffle:iprange_create(Iprange, Network, Gateway, Netmask, First, Last, Iprange),
+ Tag = case lists:keyfind(<<"tag">>, 1, Body) of
+ {<<"tag">>, T} ->
+ T;
+ _ ->
+ Iprange
+ end,
+ ok = libsniffle:iprange_create(Iprange, Network, Gateway, Netmask, First, Last, Tag),
{true, Req, State};
handle_write(Req, State, _Body) ->
@@ -183,16 +202,16 @@ handle_write(Req, State, _Body) ->
%%--------------------------------------------------------------------
delete_resource(Req, State = #state{path = [Iprange]}) ->
- {reply, ok} = libsniffle:iprange_delete(Iprange),
+ ok = libsniffle:iprange_delete(Iprange),
{true, Req, State}.
allowed(Token, Perm) ->
case libsnarl:allowed({token, Token}, Perm) of
- {reply,not_found} ->
+ not_found ->
true;
- {reply, true} ->
+ true ->
false;
- {reply, false} ->
+ false ->
true
end.
View
68 apps/wiggle/src/wiggle_package_handler.erl
@@ -3,10 +3,10 @@
%% @doc Hello world handler.
-module(wiggle_package_handler).
--export([init/3,
+-export([init/3,
rest_init/2]).
--export([content_types_provided/2,
+-export([content_types_provided/2,
content_types_accepted/2,
allowed_methods/2,
resource_exists/2,
@@ -18,8 +18,22 @@
-export([to_json/2,
from_json/2]).
+-ignore_xref([to_json/2,
+ from_json/2,
+ allowed_methods/2,
+ content_types_accepted/2,
+ content_types_provided/2,
+ delete_resource/2,
+ forbidden/2,
+ init/3,
+ is_authorized/2,
+ options/2,
+ resource_exists/2,
+ rest_init/2]).
+
+
-record(state, {path, method, version, token, content, reply}).
-
+
init(_Transport, _Req, []) ->
{upgrade, protocol, cowboy_http_rest}.
@@ -27,7 +41,7 @@ rest_init(Req, _) ->
{Method, Req1} = cowboy_http_req:method(Req),
{[<<"api">>, Version, <<"packages">> | Path], Req2} = cowboy_http_req:path(Req1),
{Token, Req3} = case cowboy_http_req:header(<<"X-Snarl-Token">>, Req2) of
- {undefined, ReqX} ->
+ {undefined, ReqX} ->
{undefined, ReqX};
{TokenX, ReqX} ->
{ok, ReqX1} = cowboy_http_req:set_resp_header(<<"X-Snarl-Token">>, TokenX, ReqX),
@@ -35,12 +49,12 @@ rest_init(Req, _) ->
end,
{ok, Req4} = cowboy_http_req:set_resp_header(<<"Access-Control-Allow-Origin">>, <<"*">>, Req3),
{ok, Req5} = cowboy_http_req:set_resp_header(
- <<"Access-Control-Allow-Headers">>,
+ <<"Access-Control-Allow-Headers">>,
<<"Content-Type, X-Snarl-Token">>, Req4),
{ok, Req6} = cowboy_http_req:set_resp_header(
- <<"Access-Control-Expose-Headers">>,
+ <<"Access-Control-Expose-Headers">>,
<<"X-Snarl-Token">>, Req5),
- State = #state{version = Version,
+ State = #state{version = Version,
method = Method,
token = Token,
path = Path},
@@ -49,10 +63,10 @@ rest_init(Req, _) ->
options(Req, State) ->
Methods = allowed_methods(Req, State, State#state.path),
{ok, Req1} = cowboy_http_req:set_resp_header(
- <<"Access-Control-Allow-Methods">>,
+ <<"Access-Control-Allow-Methods">>,
string:join(
lists:map(fun erlang:atom_to_list/1,
- ['HEAD', 'OPTIONS' | Methods]), ", "), Req),
+ ['HEAD', 'OPTIONS' | Methods]), ", "), Req),
{ok, Req1, State}.
content_types_provided(Req, State) ->
@@ -79,25 +93,25 @@ resource_exists(Req, State = #state{path = []}) ->
resource_exists(Req, State = #state{path = [Package]}) ->
case libsniffle:package_attribute_get(Package) of
- {reply, not_found} ->
+ not_found ->
{false, Req, State};
- {reply, _} ->
+ {ok, _} ->
{true, Req, State}
end.
-is_authorized(Req, State = #state{method = 'OPTIONS'}) ->
+is_authorized(Req, State = #state{method = 'OPTIONS'}) ->
{true, Req, State};
-is_authorized(Req, State = #state{token = undefined}) ->
+is_authorized(Req, State = #state{token = undefined}) ->
{{false, <<"X-Snarl-Token">>}, Req, State};
-is_authorized(Req, State) ->
+is_authorized(Req, State) ->
{true, Req, State}.
-forbidden(Req, State = #state{method = 'OPTIONS'}) ->
+forbidden(Req, State = #state{method = 'OPTIONS'}) ->
{false, Req, State};
-forbidden(Req, State = #state{token = undefined}) ->
+forbidden(Req, State = #state{token = undefined}) ->
{true, Req, State};
forbidden(Req, State = #state{path = []}) ->
@@ -124,12 +138,12 @@ to_json(Req, State) ->
{jsx:encode(Reply), Req1, State1}.
handle_request(Req, State = #state{path = []}) ->
- {reply, {ok, Res}} = libsniffle:package_list(),
+ {ok, Res} = libsniffle:package_list(),
{Res, Req, State};
handle_request(Req, State = #state{path = [Package]}) ->
- {reply, Res} = libsniffle:package_attribute_get(Package),
- {[{name, Package}|Res], Req, State}.
+ {ok, Res} = libsniffle:package_attribute_get(Package),
+ {[{name, Package}| Res], Req, State}.
%%--------------------------------------------------------------------
@@ -150,10 +164,10 @@ from_json(Req, State) ->
handle_write(Req, State = #state{path = [Package]}, Body) ->
{<<"ram">>, Ram} = lists:keyfind(<<"ram">>, 1, Body),
{<<"quota">>, Quota} = lists:keyfind(<<"quota">>, 1, Body),
- libsniffle:package_create(Package),
- {reply,ok} = libsniffle:package_attribute_set(Package,
- [{<<"quota">>, Quota},
- {<<"ram">>, Ram}]),
+ ok = libsniffle:package_create(Package),
+ ok = libsniffle:package_attribute_set(Package,
+ [{<<"quota">>, Quota},
+ {<<"ram">>, Ram}]),
{true, Req, State};
handle_write(Req, State, _Body) ->
@@ -164,15 +178,15 @@ handle_write(Req, State, _Body) ->
%%--------------------------------------------------------------------
delete_resource(Req, State = #state{path = [Package]}) ->
- {reply, ok} = libsniffle:package_delete(Package),
+ ok = libsniffle:package_delete(Package),
{true, Req, State}.
allowed(Token, Perm) ->
case libsnarl:allowed({token, Token}, Perm) of
- {reply,not_found} ->
+ not_found ->
true;
- {reply, true} ->
+ true ->
false;
- {reply, false} ->
+ false ->
true
end.
View
63 apps/wiggle/src/wiggle_user_handler.erl
@@ -18,9 +18,22 @@
forbidden/2,
options/2,
is_authorized/2]).
+
-export([to_json/2,
from_json/2]).
+-ignore_xref([to_json/2,
+ from_json/2,
+ allowed_methods/2,
+ content_types_accepted/2,
+ content_types_provided/2,
+ delete_resource/2,
+ forbidden/2,
+ init/3,
+ is_authorized/2,
+ options/2,
+ resource_exists/2,
+ rest_init/2]).
-record(state, {path, method, version, token, content, reply}).
@@ -101,31 +114,31 @@ allowed_methods(_Version, _Token, [_Login, <<"groups">>, _Group]) ->
resource_exists(Req, State = #state{path = [User, <<"permissions">> | Permission]}) ->
case {erlangify_permission(Permission), libsnarl:user_get(User)} of
- {_, {reply, {ok, not_found}}} ->
+ {_, not_found} ->
{false, Req, State};
- {[], {reply, {ok, _}}} ->
+ {[], {ok, _}} ->
{true, Req, State};
- {P, {reply, {ok, {user, _Name, _, Permissions, _Groups, _}}}} ->
+ {P, {ok, {user, _Name, _, Permissions, _Groups, _}}} ->
{lists:member(P, Permissions), Req, State}
end;
resource_exists(Req, State = #state{method = 'DELETE', path = [User, <<"groups">>, Group]}) ->
case libsnarl:user_get(User) of
- {reply, {ok, not_found}} ->
+ not_found ->
{false, Req, State};
- {reply, {ok, {user, _Name, _, _Permissions, _, Groups}}} ->
+ {ok, {user, _Name, _, _Permissions, _, Groups}} ->
{lists:member(Group, Groups), Req, State}
end;
resource_exists(Req, State = #state{method = 'PUT', path = [User, <<"groups">>, Group]}) ->
case libsnarl:user_get(User) of
- {reply, {ok, not_found}} ->
+ not_found ->
{false, Req, State};
- {reply, {ok, _}} ->
+ {ok, _} ->
case libsnarl:group_get(Group) of
- {reply, {ok, not_found}} ->
+ not_found ->
{false, Req, State};
- {reply, {ok, _}} ->
+ {ok, _} ->
{true, Req, State}
end
end;
@@ -135,9 +148,9 @@ resource_exists(Req, State = #state{path = []}) ->
resource_exists(Req, State = #state{path = [User | _]}) ->
case libsnarl:user_get(User) of
- {reply, {ok, not_found}} ->
+ not_found ->
{false, Req, State};
- {reply, {ok, _}} ->
+ {ok, _} ->
{true, Req, State}
end.
@@ -211,21 +224,21 @@ to_json(Req, State) ->
{jsx:encode(Reply), Req1, State1}.
handle_request(Req, State = #state{path = []}) ->
- {reply, {ok, Res}} = libsnarl:user_list(),
+ {ok, Res} = libsnarl:user_list(),
{Res, Req, State};
handle_request(Req, State = #state{path = [User]}) ->
- {reply, {ok, {user, Name, _, Permissions, _, Groups}}} = libsnarl:user_get(User),
+ {ok, {user, Name, _, Permissions, _, Groups}} = libsnarl:user_get(User),
{[{name, Name},
{permissions, lists:map(fun jsonify_permissions/1, Permissions)},
{groups, Groups}], Req, State};
handle_request(Req, State = #state{path = [User, <<"permissions">>]}) ->
- {reply, {ok, {user, _Name, _, Permissions, _, _Groups}}} = libsnarl:user_get(User),
+ {ok, {user, _Name, _, Permissions, _, _Groups}} = libsnarl:user_get(User),
{lists:map(fun jsonify_permissions/1, Permissions), Req, State};
handle_request(Req, State = #state{path = [User, <<"groups">>]}) ->
- {reply, {ok, {user, _Name, _, _Permissions, _, Groups}}} = libsnarl:user_get(User),
+ {ok, {user, _Name, _, _Permissions, _, Groups}} = libsnarl:user_get(User),
{Groups, Req, State}.
%%--------------------------------------------------------------------
@@ -246,22 +259,22 @@ from_json(Req, State) ->
{Reply, Req2, State1}.
handle_write(Req, State = #state{path = [User, <<"sessions">>]}, [{<<"password">>, Password}]) ->
- {reply, {ok, {token, Token}}} = libsnarl:auth(User, Password),
+ {ok, {token, Token}} = libsnarl:auth(User, Password),
{ok, Req1} = cowboy_http_req:set_resp_header(<<"X-Snarl-Token">>, Token, Req),
{true, Req1, State};
handle_write(Req, State = #state{path = [User]}, [{<<"password">>, Password}]) ->
libsnarl:user_add(User),
- {reply, ok} = libsnarl:user_passwd(User, Password),
+ ok = libsnarl:user_passwd(User, Password),
{true, Req, State};
handle_write(Req, State = #state{path = [User, <<"groups">>, Group]}, _) ->
- {reply, {ok, joined}} = libsnarl:user_join(User, Group),
+ {ok, joined} = libsnarl:user_join(User, Group),
{true, Req, State};
handle_write(Req, State = #state{path = [User, <<"permissions">> | Permission]}, _) ->
P = erlangify_permission(Permission),
- {reply, ok} = libsnarl:user_grant(User, P),
+ ok = libsnarl:user_grant(User, P),
{true, Req, State}.
@@ -271,15 +284,15 @@ handle_write(Req, State = #state{path = [User, <<"permissions">> | Permission]},
delete_resource(Req, State = #state{path = [User, <<"permissions">> | Permission]}) ->
P = erlangify_permission(Permission),
- {reply, ok} = libsnarl:user_revoke(User, P),
+ ok = libsnarl:user_revoke(User, P),
{true, Req, State};
delete_resource(Req, State = #state{path = [User]}) ->
- {reply, ok} = libsnarl:user_delete(User),
+ ok = libsnarl:user_delete(User),
{true, Req, State};
delete_resource(Req, State = #state{path = [User, <<"groups">>, Group]}) ->
- {reply, ok} = libsnarl:user_leave(User, Group),
+ ok = libsnarl:user_leave(User, Group),
{true, Req, State}.
%% Internal Functions
@@ -304,11 +317,11 @@ jsonify_permissions(P) ->
allowed(Token, Perm) ->
case libsnarl:allowed({token, Token}, Perm) of
- {reply,not_found} ->
+ not_found ->
true;
- {reply, true} ->
+ true ->
false;
- {reply, false} ->
+ false ->
true
end.
View
65 apps/wiggle/src/wiggle_vm_handler.erl
@@ -3,10 +3,10 @@
%% @doc Hello world handler.
-module(wiggle_vm_handler).
--export([init/3,
+-export([init/3,
rest_init/2]).
--export([content_types_provided/2,
+-export([content_types_provided/2,
content_types_accepted/2,
allowed_methods/2,
resource_exists/2,
@@ -20,8 +20,23 @@
-export([to_json/2,
from_json/2]).
+-ignore_xref([to_json/2,
+ from_json/2,
+ allowed_methods/2,
+ content_types_accepted/2,
+ content_types_provided/2,
+ delete_resource/2,
+ forbidden/2,
+ init/3,
+ create_path/2,
+ post_is_create/2,
+ is_authorized/2,
+ options/2,
+ resource_exists/2,
+ rest_init/2]).
+
-record(state, {path, method, version, token, content, reply}).
-
+
init(_Transport, _Req, []) ->
{upgrade, protocol, cowboy_http_rest}.
@@ -29,7 +44,7 @@ rest_init(Req, _) ->
{Method, Req1} = cowboy_http_req:method(Req),
{[<<"api">>, Version, <<"vms">> | Path], Req2} = cowboy_http_req:path(Req1),
{Token, Req3} = case cowboy_http_req:header(<<"X-Snarl-Token">>, Req2) of
- {undefined, ReqX} ->
+ {undefined, ReqX} ->
{undefined, ReqX};
{TokenX, ReqX} ->
{ok, ReqX1} = cowboy_http_req:set_resp_header(<<"X-Snarl-Token">>, TokenX, ReqX),
@@ -37,12 +52,12 @@ rest_init(Req, _) ->
end,
{ok, Req4} = cowboy_http_req:set_resp_header(<<"Access-Control-Allow-Origin">>, <<"*">>, Req3),
{ok, Req5} = cowboy_http_req:set_resp_header(
- <<"Access-Control-Allow-Headers">>,
+ <<"Access-Control-Allow-Headers">>,
<<"Content-Type, X-Snarl-Token">>, Req4),
{ok, Req6} = cowboy_http_req:set_resp_header(
- <<"Access-Control-Expose-Headers">>,
+ <<"Access-Control-Expose-Headers">>,
<<"X-Snarl-Token">>, Req5),
- State = #state{version = Version,
+ State = #state{version = Version,
method = Method,
token = Token,
path = Path},
@@ -51,10 +66,10 @@ rest_init(Req, _) ->
options(Req, State) ->
Methods = allowed_methods(Req, State, State#state.path),
{ok, Req1} = cowboy_http_req:set_resp_header(
- <<"Access-Control-Allow-Methods">>,
+ <<"Access-Control-Allow-Methods">>,
string:join(
lists:map(fun erlang:atom_to_list/1,
- ['HEAD', 'OPTIONS' | Methods]), ", "), Req),
+ ['HEAD', 'OPTIONS' | Methods]), ", "), Req),
{ok, Req1, State}.
content_types_provided(Req, State) ->
@@ -84,25 +99,25 @@ resource_exists(Req, State = #state{path = []}) ->
resource_exists(Req, State = #state{path = [Vm]}) ->
case libsniffle:vm_get(Vm) of
- {reply, {ok, not_found}} ->
+ not_found ->
{false, Req, State};
- {reply, _} ->
+ {ok, _} ->
{true, Req, State}
end.
-is_authorized(Req, State = #state{method = 'OPTIONS'}) ->
+is_authorized(Req, State = #state{method = 'OPTIONS'}) ->
{true, Req, State};
-is_authorized(Req, State = #state{token = undefined}) ->
+is_authorized(Req, State = #state{token = undefined}) ->
{{false, <<"X-Snarl-Token">>}, Req, State};
-is_authorized(Req, State) ->
+is_authorized(Req, State) ->
{true, Req, State}.
-forbidden(Req, State = #state{method = 'OPTIONS'}) ->
+forbidden(Req, State = #state{method = 'OPTIONS'}) ->
{false, Req, State};
-forbidden(Req, State = #state{token = undefined}) ->
+forbidden(Req, State = #state{token = undefined}) ->
{true, Req, State};
forbidden(Req, State = #state{method = 'GET', path = []}) ->
@@ -132,12 +147,12 @@ to_json(Req, State) ->
{jsx:encode(Reply), Req1, State1}.
handle_request(Req, State = #state{path = []}) ->
- {reply, {ok, Res}} = libsniffle:vm_list(),
+ {ok, Res} = libsniffle:vm_list(),
{Res, Req, State};
handle_request(Req, State = #state{path = [Vm]}) ->
- {reply, {ok, {vm, Name, _, Hypervisor, Dict}}} = libsniffle:vm_get(Vm),
- {[{<<"uuid">>, Name},
+ {ok, {vm, Name, _, Hypervisor, Dict}} = libsniffle:vm_get(Vm),
+ {[{<<"uuid">>, Name},
{<<"hypervisor">>, Hypervisor} | dict:to_list(Dict)], Req, State}.
@@ -159,8 +174,8 @@ create_path(Req, State = #state{path = [], version = Version, token = Token}) ->
{<<"dataset">>, Dataset} = lists:keyfind(<<"dataset">>, 1, Decoded),
{<<"package">>, Package} = lists:keyfind(<<"package">>, 1, Decoded),
{<<"config">>, Config} = lists:keyfind(<<"config">>, 1, Decoded),
- {reply, {ok, {user, Owner, _, _, _, _}}} = libsnarl:user_get({token, Token}),
- {reply, {ok, UUID}} = libsniffle:create(Package, Dataset, [{<<"owner">>, Owner} | Config]),
+ {ok, {user, Owner, _, _, _, _}} = libsnarl:user_get({token, Token}),
+ {ok, UUID} = libsniffle:create(Package, Dataset, [{<<"owner">>, Owner} | Config]),
{<<"/api/", Version/binary, "/vms/", UUID/binary>>, Req2, State}.
@@ -198,15 +213,15 @@ handle_write(Req, State, _Body) ->
%%--------------------------------------------------------------------
delete_resource(Req, State = #state{path = [Vm]}) ->
- {reply, ok} = libsniffle:vm_delete(Vm),
+ ok = libsniffle:vm_delete(Vm),
{true, Req, State}.
allowed(Token, Perm) ->
case libsnarl:allowed({token, Token}, Perm) of
- {reply,not_found} ->
+ not_found ->
true;
- {reply, true} ->
+ true ->
false;
- {reply, false} ->
+ false ->
true
end.
View
38 dialyzer.mittigate
@@ -0,0 +1,38 @@
+^leexinc.hrl:49:
+^leexinc.hrl:52:
+^leexinc.hrl:54:
+^leexinc.hrl:59:
+^leexinc.hrl:62:
+^leexinc.hrl:118:
+^leexinc.hrl:121:
+^leexinc.hrl:123:
+^leexinc.hrl:128:
+^leexinc.hrl:131:
+^leexinc.hrl:192:
+^leexinc.hrl:195:
+^leexinc.hrl:197:
+^leexinc.hrl:202:
+^leexinc.hrl:205:
+^leexinc.hrl:243:
+^leexinc.hrl:246:
+^leexinc.hrl:248:
+^leexinc.hrl:253:
+^leexinc.hrl:256:
+^leexinc.hrl:260:
+^cowboy_http_protocol.erl:36:
+^jsx_parser.erl:64:
+^jsx_parser.erl:65:
+^lager_stdlib.erl:453:
+^lager_stdlib.erl:502:
+^lager_trunc_io.erl:74:
+^lager_trunc_io.erl:98:
+^mdns_discovery_connect_node_handler.erl:30:
+^mimetypes.erl:337:
+^mimetypes.erl:344:
+^mimetypes.erl:355:
+^mimetypes.erl:363:
+^mimetypes.erl:542:
+^mimetypes.erl:549:
+^mimetypes.erl:569:
+^mimetypes.erl:577:
+^mimetypes_parse.erl:214:
View
BIN  rebar
Binary file not shown
View
3  rebar.config
@@ -8,8 +8,9 @@
[
{lager, ".*", {git, "git://github.com/basho/lager.git", {tag, "1.0.0"}}},
{jsx, ".*", {git, "http://github.com/talentdeficit/jsx.git", {tag, "v1.3.3"}}},
- {mimetypes, ".*", {git, "http://github.com/spawngrid/mimetypes.git", {tag, "e9dfab5aec98963589ecf13bdfcf0490667a730d"}}},
+ {mimetypes, ".*", {git, "http://github.com/spawngrid/mimetypes.git", {branch, master}}},
{cowboy, ".*", {git, "https://github.com/extend/cowboy.git", {tag, "0.6.1"}}},
+ {fifo_spec, ".*", {git, "https://github.com/project-fifo/fifo_spec.git", {branch, master}}},
{libsniffle, ".*", {git, "http://github.com/project-fifo/libsniffle.git", {branch, master}}},
{libsnarl, ".*", {git, "http://github.com/project-fifo/libsnarl.git", {branch, dev}}}
]}.
View
3  rel/files/app.config
@@ -1,5 +1,4 @@
-[
- {wiggle, [{acceptors, 100},
+[{wiggle, [{acceptors, 100},
{port, 8080}]},
{lager,
[{handlers, [
Please sign in to comment.
Something went wrong with that request. Please try again.