Sets password only if changed

This commit is contained in:
Tobias Herre 2023-11-03 12:54:27 +01:00
parent 9b76402251
commit e2517d06f6
1 changed files with 33 additions and 7 deletions

View File

@ -8,6 +8,14 @@ classes:
"runpw" expression => isvariable("cfg[password]"); "runpw" expression => isvariable("cfg[password]");
vars: vars:
"tpl_deps" slist => { "rspamd_pkgs_installed","rspamd_cfg_dir_created" };
runpw::
"tpl_deps" slist => { "rspamd_pkgs_installed","rspamd_cfg_dir_created","rspamd_password_ready" };
any::
"cfgfiles" slist => { "cfgfiles" slist => {
"local.d/milter_headers.conf", "local.d/milter_headers.conf",
# "local.d/actions.conf", # "local.d/actions.conf",
@ -44,11 +52,32 @@ vars:
"root_group" string => "root"; "root_group" string => "root";
"rspamadm" string => "/usr//bin/rspamadm"; "rspamadm" string => "/usr//bin/rspamadm";
any:: runpw::
"password" string => execresult("$(rspamadm) pw -p $(cfg[password])","noshell");
"password" string => readfile("$(sys.workdir)/data/agent/rspamd/password-hash.txt"),
handle => "rspamd_password_ready",
depends_on => {"rspamd_password_hash_created"};
files:
runpw::
"$(sys.workdir)/data/agent/rspamd/password.txt"
create => "true",
content => "$(cfg[password])",
handle => "rspamd_password_created",
classes => if_repaired("rspamd_password_repaired");
rspamd_password_repaired::
"$(sys.workdir)/data/agent/rspamd/password-hash.txt"
content => execresult("$(rspamadm) pw -p $(cfg[password])","noshell"),
depends_on => {"rspamd_password_created"},
handle => "rspamd_password_hash_created";
commands:
!rspamd_password_repaired::
"/usr/bin/true"
depends_on => {"rspamd_password_created"},
handle => "rspamd_password_hash_created",
inform => "false";
methods: methods:
"any" usebundle => install_rspamd_pkgs; "any" usebundle => install_rspamd_pkgs;
@ -67,16 +96,13 @@ files:
template_method => "mustache", template_method => "mustache",
perms => m("644"), perms => m("644"),
template_data => bundlestate("$(this.bundle)"), template_data => bundlestate("$(this.bundle)"),
depends_on => { "rspamd_pkgs_installed","rspamd_cfg_dir_created" }, depends_on => @(tpl_deps),
classes => if_repaired(rspamd_repaired), classes => if_repaired(rspamd_repaired),
handle => "rspamd_cfgs_done"; handle => "rspamd_cfgs_done";
reports: reports:
# "RSPAMD: $(cfgjs)";
# "RSJ: $(worker_normalx)";
} }