Permalink
Browse files

WHISTLE-1441: dialyzer spec updates

  • Loading branch information...
James Aimonetti
James Aimonetti committed Dec 3, 2012
1 parent b80ce28 commit e0dddb585ad9d0caae9b07610b37254d60b5d311
@@ -1,10 +1,11 @@
-ifndef(CROSSBAR_HRL).
-include_lib("cowboy/include/http.hrl").
-include_lib("whistle/include/wh_types.hrl").
-include_lib("whistle/include/wh_amqp.hrl").
-include_lib("whistle/include/wh_log.hrl").
-include_lib("whistle/include/wh_databases.hrl").
-include_lib("cowboy/include/http.hrl").
-include("include/crossbar_types.hrl").
@@ -50,37 +51,37 @@
,content_types_accepted = [] :: crossbar_content_handlers()
,allowed_methods = ?ALLOWED_METHODS :: http_methods()
,allow_methods = ?ALLOWED_METHODS :: http_methods()
,languages_provided = [<<"en">>, <<"en-us">>] :: [ne_binary(),...] %% english by default
,charsets_provided = [<<"iso-8859-1">>] :: [ne_binary(),...] %% all charsets provided
,encodings_provided = [<<"gzip;q=1.0">>,<<"identity;q=0.5">>] :: [ne_binary(),...] %% gzip and identity
,languages_provided = [<<"en">>, <<"en-us">>] :: ne_binaries() %% english by default
,charsets_provided = [<<"iso-8859-1">>] :: ne_binaries() %% all charsets provided
,encodings_provided = [<<"gzip;q=1.0">>,<<"identity;q=0.5">>] :: ne_binaries() %% gzip and identity
,auth_token = <<>> :: binary()
,auth_account_id :: ne_binary()
,auth_doc :: wh_json:json_object()
,auth_doc :: wh_json:object()
,req_verb = <<"get">> :: ne_binary() % <<"get">>, <<"post">>, <<"put">>, <<"delete">>, <<"head">>
,req_nouns = [{<<"404">>, []}] :: [{ne_binary(), wh_json:json_strings()},...] | [] % {module, [id]} most typical
,req_json = wh_json:new() :: wh_json:json_object() | {'malformed', binary()} %% the request JSON envelope
,req_files = [] :: [{ne_binary(), wh_json:json_object()},...] | [] %% {file_name, {"contents":<<bin>>, "headers":{"content-type":"", "content-length":1}}}
,req_json = wh_json:new() :: wh_json:object() | {'malformed', binary()} %% the request JSON envelope
,req_files = [] :: [{ne_binary(), wh_json:object()},...] | [] %% {file_name, {"contents":<<bin>>, "headers":{"content-type":"", "content-length":1}}}
,req_data :: wh_json:json_term() % the "data" from the request JSON envelope
,query_json = wh_json:new() :: wh_json:json_object()
,query_json = wh_json:new() :: wh_json:object()
,account_id :: ne_binary()
,db_name :: ne_binary()
,doc :: wh_json:json_object() | wh_json:json_objects()
,doc :: wh_json:object() | wh_json:objects()
,resp_expires = {{1999,1,1},{0,0,0}} :: wh_datetime()
,resp_etag :: 'automatic' | string() | ne_binary()
,resp_status = 'error' :: crossbar_status()
,resp_error_msg :: wh_json:json_string()
,resp_error_code :: wh_json:json_number()
,resp_data :: wh_json:json_object() | wh_json:json_objects() | binary() | wh_json:json_term()
,resp_headers = [] :: proplist() %% allow the modules to set headers (like Location: XXX to get a 201 response code)
,resp_error_code :: pos_integer()
,resp_data :: wh_json:object() | wh_json:objects() | binary() | wh_json:json_term()
,resp_headers = [] :: wh_proplist() %% allow the modules to set headers (like Location: XXX to get a 201 response code)
,start = erlang:now() :: wh_now()
,req_id = <<"000000000000">> :: ne_binary()
,storage = [] :: proplist()
,storage = [] :: wh_proplist()
,raw_host = <<>> :: binary()
,port = 8000 :: integer()
,raw_path = <<>> :: binary()
,raw_qs = <<>> :: binary()
,method = 'GET' :: http_method()
,validation_errors = wh_json:new() :: wh_json:json_object()
,validation_errors = wh_json:new() :: wh_json:object()
}).
-define(CROSSBAR_HRL, true).
@@ -1,9 +1,9 @@
-ifndef(CROSSBAR_TYPES_INCLUDED).
-type crossbar_status() :: 'success' | 'error' | 'fatal'.
-type crossbar_module_result() :: {crossbar_status(), proplist()}
| {crossbar_status(), proplist(), string()}
| {crossbar_status(), proplist(), string(), integer()}.
-type crossbar_module_result() :: {crossbar_status(), wh_proplist()}
| {crossbar_status(), wh_proplist(), string()}
| {crossbar_status(), wh_proplist(), string(), integer()}.
-type path_token() :: ne_binary().
-type path_tokens() :: [path_token(),...] | [].
@@ -16,7 +16,13 @@
-type crossbar_content_handler() :: {atom(), [{ne_binary(), ne_binary()},...]}.
-type crossbar_content_handlers() :: [crossbar_content_handler(),...] | [].
-type http_method() :: 'POST' | 'GET' | 'PUT' | 'DELETE' | 'PATCH' | 'OPTIONS'.
-type http_method() :: 'GET'
| 'POST'
| 'PUT'
| 'DELETE'
| 'OPTIONS'
| 'HEAD'
| 'PATCH'.
-type http_methods() :: [http_method(),...] | [].
-type validator() :: 'required' | 'not_empty' | 'is_type'
@@ -26,7 +32,7 @@
-type validator_rule() :: {validator(), list() | []}.
-type validator_rules() :: [validator_rule(),...] | [].
-type couch_doc_path() :: list(binary()).
-type couch_doc_path() :: ne_binaries().
-type couch_schema() :: list({couch_doc_path(), validator_rules()}).
-define(CROSSBAR_TYPES_INCLUDED, 'true').
@@ -65,7 +65,8 @@
-type payload() :: path_tokens() | % mapping over path tokens in URI
[#cb_context{} | path_token() | 'undefined',...] |
#cb_context{} |
{#cb_context{}, proplist()} | % v1_resource:rest_init/2
{#cb_context{}, wh_proplist()} | % v1_resource:rest_init/2
{'error', _} | % v1_util:execute_request/2
{wh_json:json_strings(), #cb_context{}, path_tokens()} |
{wh_datetime(), #http_req{}, #cb_context{}} | % v1_resource:expires/2
{#http_req{}, #cb_context{}}. % mapping over the request/context records
@@ -83,7 +84,7 @@
%% is the payload, possibly modified
%% @end
%%--------------------------------------------------------------------
-type map_results() :: [boolean() | http_method(),...] | [].
-type map_results() :: [boolean() | http_methods(),...] | [].
-spec map/2 :: (ne_binary(), payload()) -> map_results().
map(Routing, Payload) ->
map_processor(Routing, Payload, gen_server:call(?MODULE, current_bindings)).
@@ -95,7 +96,8 @@ map(Routing, Payload) ->
%% all matching bindings
%% @end
%%--------------------------------------------------------------------
-spec fold/2 :: (ne_binary(), payload()) -> term().
-type fold_results() :: payload().
-spec fold/2 :: (ne_binary(), payload()) -> fold_results().
fold(Routing, Payload) ->
fold_processor(Routing, Payload, gen_server:call(?MODULE, current_bindings)).
@@ -104,16 +106,16 @@ fold(Routing, Payload) ->
%% Helper functions for working on a result set of bindings
%% @end
%%-------------------------------------------------------------------
-spec any/1 :: (proplist()) -> boolean().
-spec any/1 :: (wh_proplist()) -> boolean().
any(Res) when is_list(Res) -> lists:any(fun check_bool/1, Res).
-spec all/1 :: (proplist()) -> boolean().
-spec all/1 :: (wh_proplist()) -> boolean().
all(Res) when is_list(Res) -> lists:all(fun check_bool/1, Res).
-spec failed/1 :: (wh_proplist()) -> wh_proplist() | http_methods().
-spec failed/1 :: (map_results()) -> map_results().
failed(Res) when is_list(Res) -> [R || R <- Res, filter_out_succeeded(R)].
-spec succeeded/1 :: (wh_proplist()) -> wh_proplist() | http_methods().
-spec succeeded/1 :: (map_results()) -> map_results().
succeeded(Res) when is_list(Res) -> [R || R <- Res, filter_out_failed(R)].
%%--------------------------------------------------------------------
@@ -471,8 +473,8 @@ map_processor(Routing, Payload, Bs) ->
end
end, [], Bs).
-spec fold_processor/3 :: (ne_binary(), payload(), wh_json:json_strings()) -> any().
-spec fold_processor/5 :: (ne_binary(), payload(), ne_binary(), call_from(), wh_json:json_strings()) -> any().
-spec fold_processor/3 :: (ne_binary(), payload(), wh_json:json_strings()) -> fold_results().
-spec fold_processor/5 :: (ne_binary(), payload(), ne_binary(), call_from(), wh_json:json_strings()) -> 'ok'.
fold_processor(Routing, Payload, ReqId, From, Bs) ->
put(callid, ReqId),
Reply = fold_processor(Routing, Payload, Bs),
@@ -351,7 +351,7 @@ create_account(AccountName, Realm, Username, Password) ->
_E:_R ->
lager:debug("crashed creating account: ~s: ~p", [_E, _R]),
ST = erlang:get_stacktrace(),
[lager:debug("st: ~p", [S]) || S <- ST],
_ = [lager:debug("st: ~p", [S]) || S <- ST],
failed
end.
@@ -155,7 +155,7 @@ content_types_accepted(#cb_context{req_verb = <<"post">>}=Context, _Number, ?POR
%% known, or false if not.
%% @end
%%--------------------------------------------------------------------
-spec authenticate/1 :: (cb_context:context()) -> boolean().
-spec authenticate/1 :: (cb_context:context()) -> 'true'.
authenticate(#cb_context{req_nouns=[{<<"phone_numbers">>,[]}], req_verb = <<"get">>}) -> true.
%%--------------------------------------------------------------------
@@ -165,7 +165,7 @@ authenticate(#cb_context{req_nouns=[{<<"phone_numbers">>,[]}], req_verb = <<"get
%% allowed to access the resource, or false if not.
%% @end
%%--------------------------------------------------------------------
-spec authorize/1 :: (cb_context:context()) -> boolean().
-spec authorize/1 :: (cb_context:context()) -> 'true'.
authorize(#cb_context{req_nouns=[{<<"phone_numbers">>,[]}], req_verb = <<"get">>}) -> true.
%%--------------------------------------------------------------------
@@ -73,16 +73,17 @@ rest_init(Req0, Opts) ->
lager:debug("~s: ~s?~s", [Method, Path, QS]),
Context0 = #cb_context{req_id=ReqId
,raw_host=Host
,port=Port
,raw_path=Path
,raw_qs=QS
,method=Method
,resp_status=fatal
,resp_error_msg = <<"init failed">>
,resp_error_code=500
},
Context0 = #cb_context{
req_id = wh_util:to_binary(ReqId)
,raw_host = wh_util:to_binary(Host)
,port = wh_util:to_integer(Port)
,raw_path = wh_util:to_binary(Path)
,raw_qs = wh_util:to_binary(QS)
,method = wh_util:to_atom(Method)
,resp_status = 'fatal'
,resp_error_msg = <<"init failed">>
,resp_error_code = 500
},
{Context1, _} = crossbar_bindings:fold(<<"v1_resource.init">>, {Context0, Opts}),
{ok, Req6} = cowboy_http_req:set_resp_header(<<"X-Request-ID">>, ReqId, Req5),
@@ -204,7 +205,7 @@ is_authorized(Req, Context) ->
v1_util:is_authentic(Req, Context).
-spec forbidden/2 :: (#http_req{}, cb_context:context()) ->
{boolean(), #http_req{}, cb_context:context()}.
{'false', #http_req{}, cb_context:context()}.
forbidden(Req0, Context0) ->
case v1_util:is_permitted(Req0, Context0) of
{halt, _, _}=Reply -> Reply;
@@ -401,14 +401,14 @@ is_cb_module(Elem, Ebin) ->
%% 'POST' from the allowed methods.
%% @end
%%--------------------------------------------------------------------
-spec allow_methods/4 :: (http_methods(), http_methods(), ne_binary(), http_method()) -> http_methods().
-spec allow_methods/4 :: ([http_methods(),...], http_methods(), ne_binary(), http_method()) -> http_methods().
allow_methods(Responses, Available, ReqVerb, HttpVerb) ->
lager:debug("resps: ~p", [Responses]),
case crossbar_bindings:succeeded(Responses) of
[] -> [];
Succeeded ->
AllowedSet = lists:foldr(fun(Response, Acc) ->
Set = sets:from_list(Response),
sets:intersection(Acc, Set)
sets:intersection(Acc, sets:from_list(Response))
end, sets:from_list(Available), Succeeded),
maybe_add_post_method(ReqVerb, HttpVerb, sets:to_list(AllowedSet))
end.
@@ -442,12 +442,9 @@ is_authentic(Req0, Context0) ->
[] ->
lager:debug("failed to authenticate"),
?MODULE:halt(Req0, cb_context:add_system_error(invalid_credentials, Context0));
[true|_] ->
_ ->
lager:debug("is_authentic: true"),
{true, Req1, Context1};
[{true, Context2}|_] ->
lager:debug("is_authentic: true"),
{true, Req1, Context2}
{true, Req1, Context1}
end.
-spec get_auth_token/2 :: (#http_req{}, cb_context:context()) -> {#http_req{}, cb_context:context()}.
@@ -493,12 +490,9 @@ is_permitted(Req0, Context0) ->
[] ->
lager:debug("no on authz the request"),
?MODULE:halt(Req0, cb_context:add_system_error(forbidden, Context0));
[true|_] ->
lager:debug("request was authz"),
{true, Req0, Context0};
[{true, Context1}|_] ->
_ ->
lager:debug("request was authz"),
{true, Req0, Context1}
{true, Req0, Context0}
end.
-spec is_known_content_type/2 :: (#http_req{}, cb_context:context()) -> {boolean(), #http_req{}, cb_context:context()}.

0 comments on commit e0dddb5

Please sign in to comment.