fix: add more debug for subprocess.check_output

This commit is contained in:
dettlaff 2024-11-21 21:20:29 +04:00
parent 74b3046e5d
commit b9ee8fad91

View file

@ -53,17 +53,22 @@ class KanidmAdminToken:
@staticmethod @staticmethod
def create_and_save_token(kanidm_admin_password: str) -> str: def create_and_save_token(kanidm_admin_password: str) -> str:
with temporary_env_var(key="KANIDM_PASSWORD", value=kanidm_admin_password): with temporary_env_var(key="KANIDM_PASSWORD", value=kanidm_admin_password):
try:
kanidm_admin_token = subprocess.check_output( kanidm_admin_token = subprocess.check_output(
[ [
"kanidm", "kanidmd",
"service-account", "recover-account",
"api-token", "-c",
"generate", "/etc/kanidm/server.toml",
"--rw", "idm_admin",
"selfprivacy", "-o",
"token2", "json",
] ],
text=True,
stderr=subprocess.DEVNULL,
) )
except subprocess.CalledProcessError as e:
print(e)
redis.set("kanidm:token", kanidm_admin_token) redis.set("kanidm:token", kanidm_admin_token)
return kanidm_admin_token return kanidm_admin_token
@ -80,14 +85,15 @@ class KanidmAdminToken:
"-o", "-o",
"json", "json",
], ],
text=True,
stderr=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
).decode("utf-8") )
new_kanidm_admin_password = re.search(r'{"password":"([^"]+)"}', output).group( new_kanidm_admin_password = re.search(r'{"password":"([^"]+)"}', output).group(
1 1
) ) # we have many not json strings in output
redis.set("kanidm:password", new_kanidm_admin_password)
redis.set("kanidm:password", new_kanidm_admin_password)
return new_kanidm_admin_password return new_kanidm_admin_password