Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.3] KZOO-75: Added ftp url for call recording #6645

Merged
merged 1 commit into from Oct 16, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 23 additions & 6 deletions core/kazoo_schemas/src/kz_json_schema_extensions.erl
Expand Up @@ -104,7 +104,7 @@ extra_validation(<<"metaflows.pivot.voice_url">>, URL, State) ->
extra_validation(<<"metaflows.record_call.url">>, URL, State) ->
url_validation(URL, State);
extra_validation(<<"call_recording.parameters.url">>, URL, State) ->
url_validation(URL, State);
storage_url_validation(URL, State);
extra_validation(<<"faxbox.notifications.inbound.callback.url">>, URL, State) ->
url_validation(URL, State);
extra_validation(<<"faxbox.notifications.outbound.callback.url">>, URL, State) ->
Expand Down Expand Up @@ -210,13 +210,19 @@ stability_level_to_int(<<"alpha">>) -> 1.
url_validation(URL, State) ->
case is_valid_client_url(URL) of
'true' -> State;
'false' ->
lager:info("client URL '~s' not valid", [URL]),
UpdatedState = jesse_error:handle_data_invalid({'external_error', <<"invalid client URL">>}, URL, State),
lager:info("~p", [UpdatedState]),
UpdatedState
'false' -> url_error(URL, State)
end.

storage_url_validation(<<"http", _/binary>>=URL, State) ->
url_validation(URL, State);
storage_url_validation(<<"ftp", _/binary>>=URL, State) ->
case is_valid_ftp_url(URL) of
'true' -> State;
'false' -> url_error(URL, State)
end;
storage_url_validation(URL, State) ->
url_error(URL, State).

is_valid_client_url({Scheme, Host, _Path, _QueryString, _Fragment}) ->
lists:all(fun is_valid_url_part/1
,[{fun is_valid_scheme/1, Scheme}
Expand All @@ -233,6 +239,11 @@ is_valid_scheme(<<"http">>) -> 'true';
is_valid_scheme(<<"https">>) -> 'true';
is_valid_scheme(_) -> 'false'.

is_valid_ftp_url({'ok',{'ftp', _UserPass, Host, _Port, _FullPath,_Query}}) ->
is_valid_host(kz_term:to_binary(Host));
is_valid_ftp_url(<<URL/binary>>) ->
is_valid_ftp_url(http_uri:parse(kz_term:to_list(URL))).

-spec is_valid_host(kz_http_util:location()) -> boolean().
is_valid_host(<<Host/binary>>) ->
is_valid_host(kz_term:to_lower_binary(Host), kz_network_utils:is_ip(Host));
Expand All @@ -247,6 +258,12 @@ is_valid_host(Host, 'true') ->
is_valid_host(Host, 'false') ->
is_valid_host_value(Host, 'false', kz_http_util:client_host_blacklist()).

url_error(URL, State) ->
lager:info("client URL '~s' not valid", [URL]),
UpdatedState = jesse_error:handle_data_invalid({'external_error', <<"invalid client URL">>}, URL, State),
lager:info("~p", [UpdatedState]),
UpdatedState.

-spec is_valid_host_value(kz_term:ne_binary(), boolean(), kz_term:api_ne_binaries()) -> boolean().
is_valid_host_value(_Host, _IsIp, 'undefined') -> 'true';
is_valid_host_value(Host, IsIp, Blacklist) ->
Expand Down