Skip to content

Commit

Permalink
allow verb from options in call recordings (2600hz#2863)
Browse files Browse the repository at this point in the history
* allow verb from options in call recordings

* HELP-26577 add config param for media proxy host name

support for haproxy deployments
when using a store proxy, the params needed are in the url in a encoded
form, so it can be use stateless by any media store proxy.

* properly handle no_defaults/no_required
  • Loading branch information
lazedo authored and fenollp committed Dec 5, 2016
1 parent 3ef84b7 commit 085d51c
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@
"media.normalize_destination_args": "media normalize destination args",
"media.normalize_executable": "media normalize executable",
"media.normalize_source_args": "media normalize source args",
"media.proxy_hostname": "media proxy hostname to be used with haproxy",
"media.proxy_listeners": "media proxy listeners",
"media.proxy_password": "media proxy password",
"media.proxy_port": "media proxy port",
Expand Down
4 changes: 4 additions & 0 deletions applications/crossbar/priv/api/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -9558,6 +9558,10 @@
"description": "media normalize source args",
"type": "string"
},
"proxy_hostname": {
"description": "media proxy hostname to be used with haproxy",
"type": "string"
},
"proxy_listeners": {
"default": 25,
"description": "media proxy listeners",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@
"description": "media normalize source args",
"type": "string"
},
"proxy_hostname": {
"description": "media proxy hostname to be used with haproxy",
"type": "string"
},
"proxy_listeners": {
"default": 25,
"description": "media proxy listeners",
Expand Down
5 changes: 4 additions & 1 deletion core/kazoo_ast/src/kapps_config_usage.erl
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,15 @@ static_fields(Name, JObj) ->
],
kz_json:set_values(Values, kz_doc:set_id(JObj, Id)).

-define(NO_DEFAULTS_EXCEPTIONS, [<<"proxy_hostname">>]).

-spec fields_without_defaults(kz_json:object()) -> ne_binaries().
fields_without_defaults(JObj0) ->
JObj = kz_json:get_value(?FIELD_PROPERTIES, JObj0),
lists:sort([Field
|| {Field, Content} <- kz_json:to_proplist(JObj),
'undefined' =:= kz_json:get_value(?FIELD_DEFAULT, Content)
'undefined' =:= kz_json:get_value(?FIELD_DEFAULT, Content),
not lists:member(Field, ?NO_DEFAULTS_EXCEPTIONS)
]).

-spec process_project() -> kz_json:object().
Expand Down
10 changes: 6 additions & 4 deletions core/kazoo_media/src/kz_media_file.erl
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ maybe_proxy(JObj, #media_store_path{db = Db
,opt = Options
}=Store) ->
lager:debug("fetching attachment url for '~p' , '~p', '~p'", [Db, Id, Attachment]),
case kz_datamgr:attachment_url(Db, Id, Attachment, Options) of
StreamType = kz_media_util:convert_stream_type(kz_json:get_value(<<"Stream-Type">>, JObj)),
case kz_datamgr:attachment_url(Db, Id, Attachment, [{'stream_type',StreamType} | Options]) of
{'error', 'not_found'} -> <<>>;
{'proxy', _} -> proxy_uri(JObj, Store);
<<_/binary>> = URI -> URI
Expand All @@ -83,7 +84,10 @@ proxy_uri(JObj, #media_store_path{db = Db
}=Store) ->
StreamType = kz_media_util:convert_stream_type(kz_json:get_value(<<"Stream-Type">>, JObj)),
_ = maybe_prepare_proxy(StreamType, Store),
Host = kz_network_utils:get_hostname(),
Host = case kapps_config:get_ne_binary(?CONFIG_CAT, <<"proxy_hostname">>) of
'undefined' -> kz_network_utils:get_hostname();
ProxyHostname -> ProxyHostname
end,
Port = kapps_config:get_binary(?CONFIG_CAT, <<"proxy_port">>, 24517),
Permissions = case StreamType =:= <<"store">> of
'true' -> 'proxy_store';
Expand All @@ -97,8 +101,6 @@ proxy_uri(JObj, #media_store_path{db = Db
,"/", File/binary
>>.



-spec find_attachment(ne_binaries() | ne_binary() | kz_proplist()) ->
{'ok', media_store_path()} |
{'error', 'not_found'}.
Expand Down
6 changes: 5 additions & 1 deletion core/kazoo_media/src/kz_media_recording.erl
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
,store_attempted = 'false' :: boolean()
,is_recording = 'false' :: boolean()
,retries = 0 :: integer()
,verb = 'put' :: atom()
}).
-type state() :: #state{}.

Expand Down Expand Up @@ -167,6 +168,7 @@ init([Call, Data]) ->
MediaName = kz_json:get_value(?RECORDING_ID_KEY, Data, DefaultMediaName),
Url = kz_json:get_value(<<"url">>, Data),
ShouldStore = should_store_recording(AccountId, Url),
Verb = kz_json:get_atom_value(<<"method">>, Data, 'put'),

{'ok', #state{url=Url
,format=Format
Expand All @@ -183,6 +185,7 @@ init([Call, Data]) ->
,sample_rate = SampleRate
,record_min_sec = RecordMinSec
,retries = ?STORAGE_RETRY_TIMES(AccountId)
,verb = Verb
}}.

%%--------------------------------------------------------------------
Expand Down Expand Up @@ -487,9 +490,10 @@ store_url(#state{doc_db=Db
,media={_,MediaName}
,format=Ext
,should_store={'true', 'other', Url}
,verb=Verb
}, _Rev) ->
HttpOptions = #{url => Url
,verb => 'put'
,verb => Verb
,field_separator => <<>>
,field_list => [<<"call_recording_">>
,{field, <<"call_id">>}
Expand Down

0 comments on commit 085d51c

Please sign in to comment.