diff options
author | Konstantinos Kallas <konstantinos.kallas@hotmail.com> | 2017-09-06 18:10:38 +0300 |
---|---|---|
committer | Konstantinos Kallas <konstantinos.kallas@hotmail.com> | 2017-09-06 18:10:38 +0300 |
commit | f55a8d045d637ad4e94753de011ed1d228037072 (patch) | |
tree | f30598ec671460ce03f00fbdf2471469d605f3a1 /src/ejabberd_acme.erl | |
parent | Remove some unused variable warnings, replace lists:join with string join (diff) |
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.
Diffstat (limited to '')
-rw-r--r-- | src/ejabberd_acme.erl | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/src/ejabberd_acme.erl b/src/ejabberd_acme.erl index e40ad9ccf..4eb4316b3 100644 --- a/src/ejabberd_acme.erl +++ b/src/ejabberd_acme.erl @@ -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) -> |