25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-12-24 17:29:28 +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(). -spec ets_get_key_authorization([bitstring()]) -> bitstring().
ets_get_key_authorization(Key) -> ets_get_key_authorization(Key) ->
Tab = ets_get_acme_table(), Tab = ets_get_acme_table(),
case ets:take(Tab, Key) of case ets:lookup(Tab, Key) of
[{Key, KeyAuthz}] -> [{Key, KeyAuthz}] ->
ets:delete(Tab, Key),
KeyAuthz; KeyAuthz;
_ -> _ ->
?ERROR_MSG("Unable to serve key authorization in: ~p", [Key]), ?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) -> Cond = lists:all(fun(Cert) ->
not is_error(Cert) not is_error(Cert)
end, Certs), 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 case Cond of
true -> true ->
Result = io_lib:format("Success:~n~s", [FormattedCerts]), Result = io_lib:format("Success:~n~s", [FormattedCerts]),
lists:flatten(Result); 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) lists:flatten(Result)
end. end.
@ -771,10 +772,11 @@ get_challenges(Body) ->
-spec not_before_not_after() -> {binary(), binary()}. -spec not_before_not_after() -> {binary(), binary()}.
not_before_not_after() -> not_before_not_after() ->
{MegS, Sec, MicS} = erlang:timestamp(), {Date, Time} = calendar:universal_time(),
NotBefore = xmpp_util:encode_timestamp({MegS, Sec, MicS}), NotBefore = encode_calendar_datetime({Date, Time}),
%% The certificate will be valid for 90 Days after today %% 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}. {NotBefore, NotAfter}.
-spec to_public(jose_jwk:key()) -> jose_jwk:key(). -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 = public_key:pem_entry_decode(PemEntryCert),
Certificate. 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 %% TODO: Find a better and more robust way to parse the utc string
-spec utc_string_to_datetime(string()) -> calendar:datetime(). -spec utc_string_to_datetime(string()) -> calendar:datetime().
utc_string_to_datetime(UtcString) -> utc_string_to_datetime(UtcString) ->