Skip to content

Commit

Permalink
dialyze hard (2600hz#5837)
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesaimonetti committed Jun 4, 2019
1 parent 946d5f2 commit 906c5d3
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 30 deletions.
49 changes: 26 additions & 23 deletions applications/doodle/src/doodle_inbound_handler.erl
Original file line number Diff line number Diff line change
Expand Up @@ -86,37 +86,40 @@ send_route_win(FetchId, CallId, JObj) ->
| kz_api:default_headers(<<"dialplan">>, <<"route_win">>, ?APP_NAME, ?APP_VERSION)
],
lager:debug("sms inbound handler sending route_win to ~s", [ServerQ]),
kz_amqp_worker:cast(Win, fun(Payload) -> kapi_route:publish_win(ServerQ, Payload) end),
_ = kz_amqp_worker:cast(Win, fun(Payload) -> kapi_route:publish_win(ServerQ, Payload) end),
'ack'.

custom_header_token(#{request := JObj} = Map) ->
case kz_json:get_ne_binary_value([<<"Custom-SIP-Headers">>, <<"X-AUTH-Token">>], JObj) of
'undefined' -> Map;
Token ->
case binary:split(Token, <<"@">>, ['global']) of
[AuthorizingId, AccountId | _] ->
AccountRealm = kzd_accounts:fetch_realm(AccountId),
AccountDb = kz_util:format_account_db(AccountId),
case kz_datamgr:open_cache_doc(AccountDb, AuthorizingId) of
{'ok', Doc} ->
Props = props:filter_undefined([{?CCV(<<"Authorizing-Type">>), kz_doc:type(Doc)}
,{?CCV(<<"Authorizing-ID">>), AuthorizingId}
,{?CCV(<<"Owner-ID">>), kzd_devices:owner_id(Doc)}
,{?CCV(<<"Account-ID">>), AccountId}
,{?CCV(<<"Account-Realm">>), AccountRealm}
]),
Map#{authorizing_id => AuthorizingId
,account_id => AccountId
,request => kz_json:set_values(Props, JObj)
};
_Else ->
lager:warning("unexpected result reading doc ~s/~s => ~p", [AuthorizingId, AccountId, _Else]),
Map
end;
custom_header_token(Map, JObj, Token)
end.

custom_header_token(Map, JObj, Token) ->
case binary:split(Token, <<"@">>, ['global']) of
[AuthorizingId, AccountId | _] ->
AccountRealm = kzd_accounts:fetch_realm(AccountId),
AccountDb = kz_util:format_account_db(AccountId),
case kz_datamgr:open_cache_doc(AccountDb, AuthorizingId) of
{'ok', Doc} ->
Props = props:filter_undefined([{?CCV(<<"Authorizing-Type">>), kz_doc:type(Doc)}
,{?CCV(<<"Authorizing-ID">>), AuthorizingId}
,{?CCV(<<"Owner-ID">>), kzd_devices:owner_id(Doc)}
,{?CCV(<<"Account-ID">>), AccountId}
,{?CCV(<<"Account-Realm">>), AccountRealm}
]),
Map#{authorizing_id => AuthorizingId
,account_id => AccountId
,request => kz_json:set_values(Props, JObj)
};
_Else ->
lager:warning("unexpected result spliting Token => ~p", [_Else]),
lager:warning("unexpected result reading doc ~s/~s => ~p", [AuthorizingId, AccountId, _Else]),
Map
end
end;
_Else ->
lager:warning("unexpected result spliting Token => ~p", [_Else]),
Map
end.


Expand Down
2 changes: 1 addition & 1 deletion applications/doodle/src/doodle_inbound_listener_sup.erl
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ connections() ->
JObj -> [default_connection()] ++ kz_json:foldl(fun connections_fold/3, [], JObj)
end.

-spec connections_fold(kz_json:path(), kz_json:json_term(), amqp_listener_connections()) ->
-spec connections_fold(kz_json:key(), kz_json:object(), amqp_listener_connections()) ->
amqp_listener_connections().
connections_fold(K, V, Acc) ->
C = #amqp_listener_connection{name = K
Expand Down
2 changes: 1 addition & 1 deletion applications/doodle/src/doodle_route_win.erl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ execute_text_flow(JObj, Call) ->
'true' ->
lager:debug("endpoint is restricted from sending this text, terminate", []),
_ = send_service_unavailable(JObj, Call),
doodle_util:save_sms(doodle_util:set_flow_error(<<"error">>, ?RESTRICTED_MSG, Call)),
_Call = doodle_util:save_sms(doodle_util:set_flow_error(<<"error">>, ?RESTRICTED_MSG, Call)),
'ok';
'false' ->
maybe_scheduled_delivery(JObj, Call, ?SCHEDULED(Call) , kz_time:now_s())
Expand Down
2 changes: 1 addition & 1 deletion applications/doodle/src/doodle_util.erl
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ apply_reschedule_rule(<<"report">>, V, JObj) ->
,{<<"Account-ID">>, kapps_call:account_id(Call)}
| kz_api:default_headers(?APP_NAME, ?APP_VERSION)
],
kz_amqp_worker:cast(Notify, fun kapi_notifications:publish_system_alert/1),
_ = kz_amqp_worker:cast(Notify, fun kapi_notifications:publish_system_alert/1),
JObj;
apply_reschedule_rule(_, _, JObj) -> JObj.

Expand Down
5 changes: 3 additions & 2 deletions applications/doodle/src/kz_flow.erl
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,14 @@ load_patterns(AccountId) ->
{'error', 'not_found'}
end.

-spec compile_patterns(kz_term:ne_binary(), kz_json:objects()) -> {'ok', patterns()}.
compile_patterns(AccountId, JObjs) ->
compile_patterns(AccountId, JObjs, []).

compile_patterns(AccountId, [], Acc) ->
cache_patterns(AccountId, Acc);
compile_patterns(AccountId, [JObj | JObjs], Acc) ->
Regex = kz_json:get_value(<<"key">>, JObj),
Regex = kz_json:get_ne_binary_value(<<"key">>, JObj),
FlowId = kz_doc:id(JObj),
case re:compile(Regex) of
{'ok', {'re_pattern', Groups, _, _, _} = MP}
Expand All @@ -167,7 +168,7 @@ compile_patterns(AccountId, [JObj | JObjs], Acc) ->
-spec cache_patterns(kz_term:ne_binary(), patterns()) -> {'ok', patterns()}.
cache_patterns(AccountId, Patterns) ->
AccountDb = kz_util:format_account_db(AccountId),
CacheOptions = [{'origin', [{'db', AccountDb, kz_doc:type(Patterns)}]}],
CacheOptions = [{'origin', [{'db', AccountDb, <<"textflow">>}]}],
kz_cache:store_local(?CACHE_NAME, ?MSG_PATTERN_CACHE_KEY(AccountId), Patterns, CacheOptions),
{'ok', Patterns}.

Expand Down
4 changes: 2 additions & 2 deletions core/kazoo_call/src/kapps_sms_command.erl
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ send(<<"sip">>, API, Endpoint, Timeout) ->
Payload = props:set_values( [{<<"Endpoints">>, [Endpoint]} | Options], API),
CallId = props:get_value(<<"Call-ID">>, Payload),
lager:debug("sending sms and waiting for response ~s", [CallId]),
kz_amqp_worker:cast(Payload, fun kapi_sms:publish_message/1),
_ = kz_amqp_worker:cast(Payload, fun kapi_sms:publish_message/1),
wait_for_correlated_message(CallId, <<"delivery">>, <<"message">>, Timeout);
send(<<"amqp">>, API, Endpoint, _Timeout) ->
CallId = props:get_value(<<"Call-ID">>, API),
Expand Down Expand Up @@ -233,7 +233,7 @@ maybe_add_broker(Broker, Exchange, RouteId, ExchangeType, ExchangeOptions, Broke
-spec maybe_add_broker(kz_term:api_binary(), kz_term:api_binary(), kz_term:api_binary(), kz_term:ne_binary(), kz_term:proplist(), kz_term:ne_binary(), kz_term:api_pid()) -> 'ok'.
maybe_add_broker(Broker, Exchange, RouteId, ExchangeType, ExchangeOptions, BrokerName, 'undefined') ->
Exchanges = [{Exchange, ExchangeType, ExchangeOptions}],
kz_amqp_sup:add_amqp_pool(?SMS_POOL(Exchange, RouteId, BrokerName), Broker, 5, 5, [], Exchanges, 'true'),
_ = kz_amqp_sup:add_amqp_pool(?SMS_POOL(Exchange, RouteId, BrokerName), Broker, 5, 5, [], Exchanges, 'true'),
'ok';
maybe_add_broker(_Broker, _Exchange, _RouteId, _ExchangeType, _ExchangeOptions, _BrokerName, _Pid) -> 'ok'.

Expand Down

0 comments on commit 906c5d3

Please sign in to comment.