25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-12-22 17:28:25 +01:00

Solve Travis build xref problem

Travis build failed on xref because some functions that I used did not exist in OTP versions 17.5, 18.3
Those functions are: ets:take/2, lists:join/2, erlang:timestamp/0.
This commit is contained in:
Konstantinos Kallas 2017-09-06 18:10:38 +03:00
parent 80b44d8c15
commit f55a8d045d
2 changed files with 20 additions and 6 deletions

View File

@ -96,8 +96,9 @@ ets_put_key_authorization(Tkn, KeyAuthz) ->
-spec ets_get_key_authorization([bitstring()]) -> bitstring().
ets_get_key_authorization(Key) ->
Tab = ets_get_acme_table(),
case ets:take(Tab, Key) of
case ets:lookup(Tab, Key) of
[{Key, KeyAuthz}] ->
ets:delete(Tab, Key),
KeyAuthz;
_ ->
?ERROR_MSG("Unable to serve key authorization in: ~p", [Key]),

View File

@ -128,13 +128,14 @@ format_get_certificates_result(Certs) ->
Cond = lists:all(fun(Cert) ->
not is_error(Cert)
end, Certs),
FormattedCerts = string:join([format_get_certificate(C) || C <- Certs], "\n"),
%% FormattedCerts = string:join([format_get_certificate(C) || C <- Certs], "\n"),
FormattedCerts = str:join([format_get_certificate(C) || C <- Certs], $\n),
case Cond of
true ->
Result = io_lib:format("Success:~n~s", [FormattedCerts]),
lists:flatten(Result);
_ ->
Result = io_lib:format("Error with one or more certificates~n~s", [lists:flatten(FormattedCerts)]),
Result = io_lib:format("Error with one or more certificates~n~s", [FormattedCerts]),
lists:flatten(Result)
end.
@ -771,10 +772,11 @@ get_challenges(Body) ->
-spec not_before_not_after() -> {binary(), binary()}.
not_before_not_after() ->
{MegS, Sec, MicS} = erlang:timestamp(),
NotBefore = xmpp_util:encode_timestamp({MegS, Sec, MicS}),
{Date, Time} = calendar:universal_time(),
NotBefore = encode_calendar_datetime({Date, Time}),
%% The certificate will be valid for 90 Days after today
NotAfter = xmpp_util:encode_timestamp({MegS+7, Sec+776000, MicS}),
AfterDate = add_days_to_date(90, Date),
NotAfter = encode_calendar_datetime({AfterDate, Time}),
{NotBefore, NotAfter}.
-spec to_public(jose_jwk:key()) -> jose_jwk:key().
@ -788,6 +790,17 @@ pem_to_certificate(Pem) ->
Certificate = public_key:pem_entry_decode(PemEntryCert),
Certificate.
-spec add_days_to_date(integer(), calendar:date()) -> calendar:date().
add_days_to_date(Days, Date) ->
Date1 = calendar:date_to_gregorian_days(Date),
calendar:gregorian_days_to_date(Date1 + Days).
-spec encode_calendar_datetime(calendar:datetime()) -> binary().
encode_calendar_datetime({{Year, Month, Day}, {Hour, Minute, Second}}) ->
list_to_binary(io_lib:format("~4..0B-~2..0B-~2..0BT"
"~2..0B:~2..0B:~2..0BZ",
[Year, Month, Day, Hour, Minute, Second])).
%% TODO: Find a better and more robust way to parse the utc string
-spec utc_string_to_datetime(string()) -> calendar:datetime().
utc_string_to_datetime(UtcString) ->