diff options
author | Konstantinos Kallas <konstantinos.kallas@hotmail.com> | 2017-08-19 13:36:42 +0300 |
---|---|---|
committer | Konstantinos Kallas <konstantinos.kallas@hotmail.com> | 2017-08-19 13:36:42 +0300 |
commit | dd42d52ff9df475ff448a428280443bb72029e69 (patch) | |
tree | 74f2e2bf0581616be0ddee10ab594f6e45998d51 /src | |
parent | Cleanup some comments: (diff) | |
parent | Remove the new account option from get certificate. There is no reason for ha... (diff) |
Merge remove_account_option branch
Diffstat (limited to 'src')
-rw-r--r-- | src/ejabberd_acme.erl | 28 | ||||
-rw-r--r-- | src/ejabberd_admin.erl | 21 |
2 files changed, 23 insertions, 26 deletions
diff --git a/src/ejabberd_acme.erl b/src/ejabberd_acme.erl index 5151e3fbc..260d994b8 100644 --- a/src/ejabberd_acme.erl +++ b/src/ejabberd_acme.erl @@ -71,11 +71,11 @@ is_valid_revoke_cert(DomainOrFile) -> %% Get Certificate %% --spec get_certificates(domains_opt(), account_opt()) -> string() | {'error', _}. -get_certificates(Domains, NewAccountOpt) -> +-spec get_certificates(domains_opt()) -> string() | {'error', _}. +get_certificates(Domains) -> try CAUrl = get_config_ca_url(), - get_certificates0(CAUrl, Domains, NewAccountOpt) + get_certificates0(CAUrl, Domains) catch throw:Throw -> Throw; @@ -84,18 +84,22 @@ get_certificates(Domains, NewAccountOpt) -> {error, get_certificates} end. --spec get_certificates0(url(), domains_opt(), account_opt()) -> string(). -get_certificates0(CAUrl, Domains, "old-account") -> - %% Get the current account - {ok, _AccId, PrivateKey} = ensure_account_exists(), +-spec get_certificates0(url(), domains_opt()) -> string(). +get_certificates0(CAUrl, Domains) -> + %% Check if an account exists or create another one + {ok, _AccId, PrivateKey} = retrieve_or_create_account(CAUrl), - get_certificates1(CAUrl, Domains, PrivateKey); + get_certificates1(CAUrl, Domains, PrivateKey). -get_certificates0(CAUrl, Domains, "new-account") -> - %% Create a new account and save it to disk - {ok, _Id, PrivateKey} = create_save_new_account(CAUrl), - get_certificates1(CAUrl, Domains, PrivateKey). +retrieve_or_create_account(CAUrl) -> + case read_account_persistent() of + none -> + create_save_new_account(CAUrl); + {ok, AccId, PrivateKey} -> + {ok, AccId, PrivateKey} + end. + -spec get_certificates1(url(), domains_opt(), jose_jwk:key()) -> string(). get_certificates1(CAUrl, "all", PrivateKey) -> diff --git a/src/ejabberd_admin.erl b/src/ejabberd_admin.erl index 87ddb9327..8d022e606 100644 --- a/src/ejabberd_admin.erl +++ b/src/ejabberd_admin.erl @@ -45,7 +45,7 @@ %% Migration jabberd1.4 import_file/1, import_dir/1, %% Acme - get_certificate/2, + get_certificate/1, renew_certificate/0, list_certificates/1, revoke_certificate/1, @@ -248,13 +248,11 @@ get_commands_spec() -> args = [{file, string}], result = {res, restuple}}, #ejabberd_commands{name = get_certificate, tags = [acme], - desc = "Gets a certificate for all or the specified domains {all|domain1;domain2;...}. Can be used with {old-account|new-account}.", + desc = "Gets a certificate for all or the specified domains {all|domain1;domain2;...}.", module = ?MODULE, function = get_certificate, - args_desc = ["Domains for which to acquire a certificate", - "Whether to create a new account or use the existing one"], - args_example = ["all | www.example.com;www.example1.net", - "old-account | new-account"], - args = [{domains, string}, {option, string}], + args_desc = ["Domains for which to acquire a certificate"], + args_example = ["all | www.example.com;www.example1.net"], + args = [{domains, string}], result = {certificates, string}}, #ejabberd_commands{name = renew_certificate, tags = [acme], desc = "Renews all certificates that are close to expiring", @@ -577,15 +575,10 @@ import_dir(Path) -> %%% Acme %%% -get_certificate(Domains, UseNewAccount) -> +get_certificate(Domains) -> case ejabberd_acme:is_valid_domain_opt(Domains) of true -> - case ejabberd_acme:is_valid_account_opt(UseNewAccount) of - true -> - ejabberd_acme:get_certificates(Domains, UseNewAccount); - false -> - io_lib:format("Invalid account option: ~p", [UseNewAccount]) - end; + ejabberd_acme:get_certificates(Domains); false -> String = io_lib:format("Invalid domains: ~p", [Domains]) end. |