Packages
diint_utilites_common_app
1.2.2
1.4.23
1.4.22
1.4.21
1.4.20
1.4.19
1.4.18
1.4.17
1.4.16
1.4.15
1.4.14
1.4.12
1.4.11
1.4.10
1.4.9
1.4.8
1.4.7
1.4.6
1.4.5
1.4.4
1.4.3
1.4.2
1.4.1
1.4.0
1.3.9
1.3.8
1.3.7
1.3.6
1.3.5
1.3.4
1.3.3
1.3.2
1.3.1
1.3.0
1.2.101
1.2.11
1.2.10
1.2.9
1.2.8
1.2.7
1.2.6
1.2.5
1.2.4
1.2.3
1.2.2
1.2.1
1.2.0
1.1.7
1.1.6
1.1.5
1.1.4
1.1.3
1.1.2
1.1.1
1.1.0
1.0.13
1.0.12
1.0.11
1.0.10
1.0.9
1.0.8
1.0.7
1.0.6
1.0.5
1.0.4
1.0.3
1.0.2
1.0.1
библиотеки для работы с ребитом и протоколы
Current section
Files
Jump to
Current section
Files
src/security/diint_start.erl
%%%-------------------------------------------------------------------
%%% @author cheese
%%% @copyright (C) 2015, <COMPANY>
%%% @doc
%%%
%%% @end
%%% Created : 23. Nov 2015 14:28
%%%-------------------------------------------------------------------
-module(diint_start).
-author("cheese").
-define(LOG_FILE, "log/diint_start.log").
%% API
-export([get_data/2, send_to_start/1, get_request_param/2, get_mssql/1, get_password/1]).
get_mssql(Key) ->
get_data(Key, <<"2">>).
get_password(Key) ->
get_data(Key, <<"1">>).
get_data(Key, Type) ->
Request = <<"{\"Type\":\"", Type/binary, "\", \"Name\":\"", Key/binary, "\"}">>,
case send_to_start(Request) of
{ok, Response} ->
Json = jsx:decode(list_to_binary(Response)),
%logger:info("Json ~w~n ", [Json], ?LOG_FILE),
case get_request_param(Json, <<"IsSuccess">>) of
true ->
case get_request_param(Json, <<"Message">>) of
undefined ->
{error, {json_response_error, message_not_found}};
Data ->
{ok, Data}
end;
IsSuccess ->
{error, {json_response_error, {is_succces_value, IsSuccess}}}
end;
{error, Reason} ->
logger_Cheese:info("Failed get ~s from start. ~w", [Key, Reason], ?LOG_FILE),
{error, Reason}
end.
get_request_param([{ParamName, Value} | _OtherJson], ParamName) ->
Value;
get_request_param([{_Name, _Value} | OtherJson], ParamName) ->
get_request_param(OtherJson, ParamName);
get_request_param(_Other, _ParamName) ->
undefined.
send_to_start(Request) ->
Url = "https://start-secondary.diint.it.loc:8084/DIINTStart/GetLite.aspx",
logger_Cheese:info("http post ~s~n ", [Url], ?LOG_FILE),
logger_Cheese:info("=> ~s~n ", [Request], ?LOG_FILE),
Certfile = "data/cert/start_crt.pem",
Keyfile = "data/cert/start_key.pem",
case file_utilites:file_exist(Certfile) of
true ->
case file_utilites:file_exist(Keyfile) of
true ->
case httpc:request(post, {Url, [], "application/octet-stream", Request}, [{timeout, 10000}, {ssl, [{certfile, Certfile}, {keyfile, Keyfile}, {active, true}, binary]}], []) of
{ok, {{_, HttpStatus, _}, _, Response}} ->
logger_Cheese:info("<= (~w): ~w Bytes~n ", [HttpStatus, length(Response)], ?LOG_FILE),
case HttpStatus of
200 ->
{ok, Response};
Other ->
{error, {Other, Response}}
end;
ErrResponse ->
logger_Cheese:info("<= (error): ~p~n ", [ErrResponse], ?LOG_FILE),
{error, ErrResponse}
end;
_ ->
{error, {file_is_absent, Keyfile}}
end;
_ ->
{error, {file_is_absent, Certfile}}
end.