/
cb_devices.erl
493 lines (454 loc) · 22.3 KB
/
cb_devices.erl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
%%%-------------------------------------------------------------------
%%% @copyright (C) 2011, VoIP INC
%%% @doc
%%% Devices module
%%%
%%% Handle client requests for device documents
%%%
%%% @end
%%% @contributors
%%% Karl Anderson
%%% James Aimonetti
%%%-------------------------------------------------------------------
-module(cb_devices).
-export([init/0
,allowed_methods/0, allowed_methods/1
,resource_exists/0, resource_exists/1
,billing/1
,validate/1, validate/2
,put/1
,post/2
,delete/2
]).
-include_lib("crossbar/include/crossbar.hrl").
-define(MOD_CONFIG_CAT, <<(?CONFIG_CAT)/binary, ".devices">>).
-define(CB_LIST, <<"devices/crossbar_listing">>).
%%%===================================================================
%%% API
%%%===================================================================
init() ->
_ = crossbar_bindings:bind(<<"v1_resource.allowed_methods.devices">>, ?MODULE, allowed_methods),
_ = crossbar_bindings:bind(<<"v1_resource.resource_exists.devices">>, ?MODULE, resource_exists),
_ = crossbar_bindings:bind(<<"v1_resource.billing">>, ?MODULE, billing),
_ = crossbar_bindings:bind(<<"v1_resource.validate.devices">>, ?MODULE, validate),
_ = crossbar_bindings:bind(<<"v1_resource.execute.put.devices">>, ?MODULE, put),
_ = crossbar_bindings:bind(<<"v1_resource.execute.post.devices">>, ?MODULE, post),
crossbar_bindings:bind(<<"v1_resource.execute.delete.devices">>, ?MODULE, delete).
%%--------------------------------------------------------------------
%% @public
%% @doc
%% This function determines the verbs that are appropriate for the
%% given Nouns. IE: '/accounts/' can only accept GET and PUT
%%
%% Failure here returns 405
%% @end
%%--------------------------------------------------------------------
-spec allowed_methods/0 :: () -> http_methods().
-spec allowed_methods/1 :: (path_token()) -> http_methods().
allowed_methods() ->
['GET', 'PUT'].
allowed_methods(<<"status">>) ->
['GET'];
allowed_methods(_) ->
['GET', 'POST', 'DELETE'].
%%--------------------------------------------------------------------
%% @public
%% @doc
%% This function determines if the provided list of Nouns are valid.
%%
%% Failure here returns 404
%% @end
%%--------------------------------------------------------------------
-spec resource_exists/0 :: () -> 'true'.
-spec resource_exists/1 :: (path_token()) -> 'true'.
resource_exists() -> true.
resource_exists(_) -> true.
%%--------------------------------------------------------------------
%% @public
%% @doc
%% Bill for limits
%% @end
%%--------------------------------------------------------------------
billing(#cb_context{req_nouns=[{<<"devices">>, _}|_], req_verb = <<"put">>, doc=JObj
,account_id=AccountId, db_name=Db}=Context) ->
case wh_resellers:fetch(AccountId) of
{error, no_service_plan} -> Context;
{ok, Resellers} ->
try
DeviceType = get_device_type(JObj),
R1 = wh_service_devices:activate_device_type(DeviceType, Resellers),
{ok, Devices} = couch_mgr:get_all_results(Db, ?CB_LIST),
DeviceTypes = [get_device_type(Device) || Device <- Devices],
R2 = wh_service_devices:update([DeviceType | DeviceTypes], R1, created),
ok = wh_resellers:commit_changes(R2)
catch
throw:{Error, Reason} ->
crossbar_util:response(error, wh_util:to_binary(Error), 500, Reason, Context)
end
end;
billing(#cb_context{req_nouns=[{<<"devices">>, _}|_], req_verb = <<"post">>
,account_id=AccountId, db_name=Db}=Context) ->
case wh_resellers:fetch(AccountId) of
{error, no_service_plan} -> Context;
{ok, Resellers} ->
try
{ok, Devices} = couch_mgr:get_all_results(Db, ?CB_LIST),
DeviceTypes = [get_device_type(Device) || Device <- Devices],
R = wh_service_devices:update(DeviceTypes, Resellers),
ok = wh_resellers:commit_changes(R)
catch
throw:{Error, Reason} ->
crossbar_util:response(error, wh_util:to_binary(Error), 500, Reason, Context)
end
end;
billing(#cb_context{req_nouns=[{<<"devices">>, _}|_], req_verb = <<"delete">>, doc=JObj
,account_id=AccountId, db_name=Db}=Context) ->
case wh_resellers:fetch(AccountId) of
{error, no_service_plan} -> Context;
{ok, Resellers} ->
try
DeviceType = get_device_type(JObj),
{ok, Devices} = couch_mgr:get_all_results(Db, ?CB_LIST),
DeviceTypes = [get_device_type(Device) || Device <- Devices],
R = wh_service_devices:update(lists:delete(DeviceType, DeviceTypes), Resellers, deleted),
ok = wh_resellers:commit_changes(R)
catch
throw:{Error, Reason} ->
crossbar_util:response(error, wh_util:to_binary(Error), 500, Reason, Context)
end
end;
billing(Context) -> Context.
%%--------------------------------------------------------------------
%% @public
%% @doc
%% This function determines if the parameters and content are correct
%% for this request
%%
%% Failure here returns 400
%% @end
%%--------------------------------------------------------------------
-spec validate/1 :: (#cb_context{}) -> #cb_context{}.
-spec validate/2 :: (#cb_context{}, path_token()) -> #cb_context{}.
validate(#cb_context{req_verb = <<"get">>}=Context) ->
load_device_summary(Context);
validate(#cb_context{req_verb = <<"put">>}=Context) ->
create_device(Context).
validate(#cb_context{req_verb = <<"get">>}=Context, <<"status">>) ->
load_device_status(Context);
validate(#cb_context{req_verb = <<"get">>}=Context, DocId) ->
load_device(DocId, Context);
validate(#cb_context{req_verb = <<"post">>}=Context, DocId) ->
update_device(DocId, Context);
validate(#cb_context{req_verb = <<"delete">>}=Context, DocId) ->
load_device(DocId, Context).
-spec post/2 :: (#cb_context{}, path_token()) -> #cb_context{}.
post(#cb_context{}=Context, _DocId) ->
_ = crossbar_util:put_reqid(Context),
case crossbar_doc:save(Context) of
#cb_context{resp_status=success, doc=Doc1, account_id=AcctId}=Context1 ->
case wh_json:get_ne_value([<<"sip">>, <<"realm">>], Doc1) of
undefined -> ok;
_Else ->
lager:debug("adding device to the sip auth aggregate"),
couch_mgr:ensure_saved(?WH_SIP_DB, wh_json:delete_key(<<"_rev">>, Doc1))
end,
case wh_json:get_ne_value([<<"sip">>, <<"ip">>], Doc1) of
undefined -> ok;
DeviceIP ->
lager:debug("adding device to the sip auth aggregate"),
{ok, D} = couch_mgr:ensure_saved(?WH_SIP_DB, wh_json:delete_key(<<"_rev">>, Doc1)),
maybe_update_acls(DeviceIP, AcctId, wh_json:get_value(<<"_id">>, D))
end,
spawn(fun() -> do_simple_provision(Context1) end),
Context1;
Else ->
Else
end.
-spec put/1 :: (#cb_context{}) -> #cb_context{}.
put(#cb_context{}=Context) ->
_ = crossbar_util:put_reqid(Context),
case crossbar_doc:save(Context) of
#cb_context{resp_status=success, doc=Doc1, account_id=AcctId}=Context1 ->
case wh_json:get_ne_value([<<"sip">>, <<"realm">>], Doc1) of
undefined -> ok;
_Else ->
lager:debug("adding device to the sip auth aggregate"),
couch_mgr:ensure_saved(?WH_SIP_DB, wh_json:delete_key(<<"_rev">>, Doc1))
end,
case wh_json:get_ne_value([<<"sip">>, <<"ip">>], Doc1) of
undefined -> ok;
DeviceIP ->
lager:debug("adding device to the sip auth aggregate"),
{ok, D} = couch_mgr:ensure_saved(?WH_SIP_DB, wh_json:delete_key(<<"_rev">>, Doc1)),
maybe_update_acls(DeviceIP, AcctId, wh_json:get_value(<<"_id">>, D))
end,
spawn(fun() -> do_simple_provision(Context1) end),
Context1;
Else ->
Else
end.
-spec delete/2 :: (#cb_context{}, path_token()) -> #cb_context{}.
delete(#cb_context{doc=Doc}=Context, _DocId) ->
_ = crossbar_util:put_reqid(Context),
case crossbar_doc:delete(Context) of
#cb_context{resp_status=success}=Context1 ->
DeviceId = wh_json:get_value(<<"_id">>, Doc),
case couch_mgr:lookup_doc_rev(?WH_SIP_DB, DeviceId) of
{ok, Rev} ->
couch_mgr:del_doc(?WH_SIP_DB, wh_json:set_value(<<"_rev">>, Rev, Doc));
{error, not_found} ->
ok
end,
wapi_switch:reloadacl(),
Context1;
Else ->
Else
end.
%%%===================================================================
%%% Internal functions
%%%===================================================================
%%--------------------------------------------------------------------
%% @private
%% @doc
%% Attempt to load list of accounts, each summarized. Or a specific
%% account summary.
%% @end
%%--------------------------------------------------------------------
-spec load_device_summary/1 :: (#cb_context{}) -> #cb_context{}.
load_device_summary(Context) ->
crossbar_doc:load_view(?CB_LIST, [], Context, fun normalize_view_results/2).
%%--------------------------------------------------------------------
%% @private
%% @doc
%% Create a new device document with the data provided, if it is valid
%% @end
%%--------------------------------------------------------------------
-spec create_device/1 :: (#cb_context{}) -> #cb_context{}.
create_device(#cb_context{req_data=Req, db_name=Db}=Context) ->
SIPRealm = wh_json:get_ne_value([<<"sip">>, <<"realm">>], Req, <<>>),
AccountRealm = crossbar_util:get_account_realm(Context),
Data = case AccountRealm =:= SIPRealm of
true ->
wh_json:delete_key([<<"sip">>, <<"realm">>], Req);
false ->
Req
end,
Username = wh_json:get_ne_value([<<"sip">>, <<"username">>], Data),
Realm = wh_json:get_ne_value([<<"sip">>, <<"realm">>], Data),
IsCredsUnique = is_sip_creds_unique(Db, Realm, Username),
Data1 = set_outbound_flags(Data, wh_json:get_value(<<"outbound_flags">>, Data)),
case wh_json_validator:is_valid(Data1, <<"devices">>) of
{fail, Errors} when not IsCredsUnique ->
E = wh_json:set_value([<<"sip">>, <<"username">>, <<"unique">>]
,<<"SIP credentials are already in use">>
,Errors),
crossbar_util:response_invalid_data(E, Context);
{fail, Errors} ->
crossbar_util:response_invalid_data(Errors, Context);
{pass, _} when not IsCredsUnique ->
E = wh_json:set_value([<<"sip">>, <<"username">>, <<"unique">>]
,<<"SIP credentials are already in use">>
,wh_json:new()),
crossbar_util:response_invalid_data(E, Context);
{pass, JObj} ->
Context#cb_context{resp_status=success
,doc=wh_json:set_value([<<"pvt_type">>, <<"device">>], JObj)
}
end.
%%--------------------------------------------------------------------
%% @private
%% @doc
%% Load a device document from the database
%% @end
%%--------------------------------------------------------------------
-spec load_device/2 :: (ne_binary(), #cb_context{}) -> #cb_context{}.
load_device(DocId, Context) ->
crossbar_doc:load(DocId, Context).
%%--------------------------------------------------------------------
%% @private
%% @doc
%% Update an existing device document with the data provided, if it is
%% valid
%% @end
%%--------------------------------------------------------------------
-spec update_device/2 :: (ne_binary(), #cb_context{}) -> #cb_context{}.
update_device(DocId, #cb_context{req_data=Req, db_name=Db}=Context) ->
SIPRealm = wh_json:get_ne_value([<<"sip">>, <<"realm">>], Req, <<>>),
AccountRealm = crossbar_util:get_account_realm(Context),
Data = case AccountRealm =:= SIPRealm of
true ->
wh_json:delete_key([<<"sip">>, <<"realm">>], Req);
false ->
Req
end,
Username = wh_json:get_ne_value([<<"sip">>, <<"username">>], Data),
Realm = wh_json:get_ne_value([<<"sip">>, <<"realm">>], Data),
IsCredsUnique = is_sip_creds_unique(Db, Realm, Username, DocId),
Data1 = set_outbound_flags(Data, wh_json:get_value(<<"outbound_flags">>, Data)),
case wh_json_validator:is_valid(Data1, <<"devices">>) of
{fail, Errors} when not IsCredsUnique ->
E = wh_json:set_value([<<"sip">>, <<"username">>, <<"unique">>]
,<<"SIP credentials are already in use">>
,Errors),
crossbar_util:response_invalid_data(E, Context);
{fail, Errors} ->
crossbar_util:response_invalid_data(Errors, Context);
{pass, _} when not IsCredsUnique ->
E = wh_json:set_value([<<"sip">>, <<"username">>, <<"unique">>]
,<<"SIP credentials are already in use">>
,wh_json:new()),
crossbar_util:response_invalid_data(E, Context);
{pass, JObj} ->
crossbar_doc:load_merge(DocId, JObj, Context)
end.
%%--------------------------------------------------------------------
%% @private
%% @doc
%% Retrieve the status of the devices linked to the account
%% Reads registered devices in registrations, then map to devices of the account
%% @end
%%--------------------------------------------------------------------
-spec load_device_status/1 :: (#cb_context{}) -> #cb_context{}.
load_device_status(Context) ->
AccountRealm = crossbar_util:get_account_realm(Context),
crossbar_util:response(lookup_regs(AccountRealm), Context).
%%--------------------------------------------------------------------
%% @private
%% @doc
%% Normalizes the resuts of a view
%% @end
%%--------------------------------------------------------------------
-spec normalize_view_results/2 :: (wh_json:json_object(), wh_json:json_objects()) -> wh_json:json_objects().
normalize_view_results(JObj, Acc) ->
[wh_json:get_value(<<"value">>, JObj)|Acc].
%%--------------------------------------------------------------------
%% @private
%% @doc
%% Returns the complete list of registrations in a the first registrar
%% to respond for a given account realm. This is not 100% accurate
%% as an endpoint might be stored in another registrar, but it is
%% accurate enough for the status icons.
%% @end
%%--------------------------------------------------------------------
-spec lookup_regs/1 :: (ne_binary()) -> wh_json:json_objects().
lookup_regs(AccountRealm) ->
Q = amqp_util:new_queue(),
ok = amqp_util:bind_q_to_targeted(Q),
ok = amqp_util:basic_consume(Q),
Req = [{<<"Realm">>, AccountRealm}
,{<<"Fields">>, [<<"Authorizing-ID">>]}
| wh_api:default_headers(Q, ?APP_NAME, ?APP_VERSION)
],
wapi_registration:publish_query_req(Req),
receive
{_, #amqp_msg{payload = Payload}} ->
JObj = wh_json:decode(Payload),
true = wapi_registration:query_resp_v(JObj),
case wh_json:get_value(<<"Fields">>, JObj) of
undefined -> [];
Regs ->
[wh_json:from_list([{<<"device_id">>, AuthorizingId}
,{<<"registered">>, true}
])
|| Reg <- Regs
,(AuthorizingId = wh_json:get_value(<<"Authorizing-ID">>, Reg)) =/= undefined
]
end
after
1000 -> []
end.
%%--------------------------------------------------------------------
%% @private
%% @doc
%% Check if the device sip creds are unique
%% @end
%%--------------------------------------------------------------------
-spec is_sip_creds_unique/3 :: (undefined | ne_binary(), undefined | ne_binary(), undefined | ne_binary() ) -> boolean().
-spec is_sip_creds_unique/4 :: (undefined | ne_binary(), undefined | ne_binary(), undefined | ne_binary(), undefined | ne_binary())
-> boolean().
is_sip_creds_unique(AccountDb, Realm, Username) ->
is_sip_creds_unique(AccountDb, Realm, Username, undefined).
%% no account id and no doc id (ie initial create with no account)
is_sip_creds_unique(undefined, _, _, undefined) ->
true;
is_sip_creds_unique(_, _, undefined, undefined) ->
true;
is_sip_creds_unique(AccountDb, undefined, Username, DocId) ->
case couch_mgr:get_results(AccountDb, <<"devices/sip_credentials">>, [{<<"key">>, Username}]) of
{ok, []} -> true;
{ok, [JObj]} ->
wh_json:get_value(<<"id">>, JObj) =:= DocId;
{error, not_found} -> true;
_ -> false
end;
is_sip_creds_unique(_, Realm, Username, DocId) ->
ViewOptions = [{<<"key">>, [Realm, Username]}],
case couch_mgr:get_results(?WH_SIP_DB, <<"credentials/lookup">>, ViewOptions) of
{ok, []} -> true;
{ok, [JObj]} -> wh_json:get_value(<<"id">>, JObj) =:= DocId;
{error, not_found} -> true;
_ -> false
end.
%%--------------------------------------------------------------------
%% @private
%% @doc
%% post data to a provisiong server
%% @end
%%--------------------------------------------------------------------
-spec do_simple_provision/1 :: (#cb_context{}) -> 'ok'.
do_simple_provision(#cb_context{doc=JObj}=Context) ->
case whapps_config:get_string(?MOD_CONFIG_CAT, <<"provisioning_url">>) of
undefined -> ok;
Url ->
AccountRealm = crossbar_util:get_account_realm(Context),
Headers = [{K, V}
|| {K, V} <- [{"Host", whapps_config:get_string(?MOD_CONFIG_CAT, <<"provisioning_host">>)}
,{"Referer", whapps_config:get_string(?MOD_CONFIG_CAT, <<"provisioning_referer">>)}
,{"User-Agent", wh_util:to_list(erlang:node())}
,{"Content-Type", "application/x-www-form-urlencoded"}]
,V =/= undefined],
HTTPOptions = [],
Body = [{"device[mac]", re:replace(wh_json:get_string_value(<<"mac_address">>, JObj, ""), "[^0-9a-fA-F]", "", [{return, list}, global])}
,{"device[label]", wh_json:get_string_value(<<"name">>, JObj)}
,{"sip[realm]", wh_json:get_string_value([<<"sip">>, <<"realm">>], JObj, AccountRealm)}
,{"sip[username]", wh_json:get_string_value([<<"sip">>, <<"username">>], JObj)}
,{"sip[password]", wh_json:get_string_value([<<"sip">>, <<"password">>], JObj)}
,{"submit", "true"}],
Encoded = mochiweb_util:urlencode(Body),
lager:debug("posting to ~s with ~s", [Url, Encoded]),
ibrowse:send_req(Url, Headers, post, Encoded, HTTPOptions)
end.
-spec maybe_update_acls/3 :: (ne_binary(), ne_binary(), ne_binary()) -> 'ok'.
maybe_update_acls(DeviceIP, AcctId, DeviceId) ->
CIDR = <<DeviceIP/binary, "/32">>,
Acls = wh_json:set_value(CIDR
,wh_json:from_list([{<<"network-list-name">>, <<"trusted">>}
,{<<"type">>, <<"allow">>}
,{<<"cidr">>, CIDR}
,{<<"account_id">>, AcctId}
,{<<"device_id">>, DeviceId}
])
,whapps_config:get(<<"ecallmgr">>, <<"acls">>, wh_json:new())
),
lager:debug("setting ~s into system acls", [CIDR]),
whapps_config:set_default(<<"ecallmgr">>, <<"acls">>, Acls),
wapi_switch:publish_reloadacl().
-spec get_device_type/1 :: (wh_json:json_object()) -> ne_binary().
get_device_type(JObj) ->
DeviceType = wh_json:get_value(<<"device_type">>, JObj
,wh_json:get_value([<<"value">>, <<"device_type">>], JObj, <<"sip_device">>)),
case lists:member(DeviceType, [<<"sip_device">>, <<"cellphone">>, <<"softphone">>]) of
true -> DeviceType;
false -> <<"sip_device">>
end.
set_outbound_flags(JObj, undefined) ->
wh_json:set_value(<<"outbound_flags">>, [], JObj);
set_outbound_flags(JObj, []) ->
JObj;
set_outbound_flags(JObj, <<>>) ->
wh_json:set_value(<<"outbound_flags">>, [], JObj);
set_outbound_flags(JObj, L) when is_list(L) ->
lager:debug("flags: ~p", [[wh_util:strip_binary(B) || B <- L]]),
wh_json:set_value(<<"outbound_flags">>, [wh_util:strip_binary(B) || B <- L], JObj);
set_outbound_flags(JObj, _) -> JObj.
Aug 7 22:46:21 app01-vm-lab30 whistle_apps[14254]: |8e901138d2323787cc8376b4121970d4|crossbar_bindings:406 (<0.2138.0>) excepted: {undef,[{wh_json,set_value,[{<<"pvt_type">>,<<"device">>},{[{<<"enabled">>,true},{<<"caller_id">>,{[]}},{<<"media">>,{[{<<"bypass_media">>,<<"auto">>},{<<"audio">>,{[{<<"codecs">>,[<<"PCMU">>,<<"PCMA">>]}]}},{<<"video">>,{[{<<"codecs">>,[]}]}},{<<"fax">>,{[{<<"option">>,<<"false">>}]}},{<<"fax_option">>,<<"auto">>},{<<"ignore_early_media">>,false}]}},{<<"sip">>,{[{<<"method">>,<<"password">>},{<<"invite_format">>,<<"username">>},{<<"username">>,<<"user_rtzlee">>},{<<"password">>,<<"hox0yay2eo63">>},{<<"expire_seconds">>,<<"360">>},{<<"custom_sip_headers">>,{[]}},{<<"registration_expiration">>,300}]}},{<<"call_forward">>,{[{<<"enabled">>,false},{<<"substitute">>,true},{<<"require_keypress">>,true},{<<"keep_caller_id">>,true},{<<"direct_calls_only">>,false},{<<"ignore_early_media">>,true}]}},{<<"music_on_hold">>,{[]}},{<<"device_type">>,<<"sip_device">>},{<<"provision">>,{[]}},{<<"name">>,<<"test_2600hz">>},{<<"suppress_unregister_notifications">>,true},{<<"outbound_flags">>,[]},{<<"caller_id_options">>,{[]}},{<<"ringtones">>,{[]}}]}]},{cb_devices,create_device,1},{crossbar_bindings,fold_bind_results,5},{lists,foldl,3},{crossbar_bindings,fold_processor,3},{v1_util,validate,1},{v1_resource,resource_exists,2},{cowboy_http_rest,expect,6}]}