mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2024-11-29 07:21:27 +00:00
feat: add more debbug
This commit is contained in:
parent
1a8b0a51eb
commit
c608b136cc
|
@ -4,6 +4,7 @@ import os
|
||||||
import subprocess
|
import subprocess
|
||||||
import requests
|
import requests
|
||||||
import re
|
import re
|
||||||
|
import logging
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
|
|
||||||
from selfprivacy_api.utils import get_domain
|
from selfprivacy_api.utils import get_domain
|
||||||
|
@ -17,6 +18,8 @@ KANIDM_URL = "https://127.0.0.1:3013"
|
||||||
|
|
||||||
redis = RedisPool().get_connection()
|
redis = RedisPool().get_connection()
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def temporary_env_var(key, value):
|
def temporary_env_var(key, value):
|
||||||
|
@ -52,6 +55,8 @@ class KanidmAdminToken:
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def create_and_save_token(kanidm_admin_password: str) -> str:
|
def create_and_save_token(kanidm_admin_password: str) -> str:
|
||||||
|
logging.error("create_and_save_token START")
|
||||||
|
|
||||||
with temporary_env_var(key="KANIDM_PASSWORD", value=kanidm_admin_password):
|
with temporary_env_var(key="KANIDM_PASSWORD", value=kanidm_admin_password):
|
||||||
try:
|
try:
|
||||||
kanidm_admin_token = subprocess.check_output(
|
kanidm_admin_token = subprocess.check_output(
|
||||||
|
@ -69,14 +74,17 @@ class KanidmAdminToken:
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
print(e)
|
print(e)
|
||||||
|
|
||||||
kanidm_admin_token = kanidm_admin_token.splitlines()[-1]
|
logging.error("create_and_save_token END subprocess.check_output")
|
||||||
|
|
||||||
|
kanidm_admin_token = kanidm_admin_token.splitlines()[-1]
|
||||||
|
logging.error(f"create_and_save_token FIND {kanidm_admin_token}")
|
||||||
|
|
||||||
redis.set("kanidm:token", kanidm_admin_token)
|
redis.set("kanidm:token", kanidm_admin_token)
|
||||||
return kanidm_admin_token
|
return kanidm_admin_token
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def reset_and_save_idm_admin_password() -> str:
|
def reset_and_save_idm_admin_password() -> str:
|
||||||
print("ALLLLLLLL ISSS OKKEEEEEEEYEEYEYEYEYEYEYEYEYEyFvsdsnmiosfd")
|
logging.error("reset_and_save_idm_admin_password START")
|
||||||
|
|
||||||
output = subprocess.check_output(
|
output = subprocess.check_output(
|
||||||
[
|
[
|
||||||
|
@ -91,21 +99,18 @@ class KanidmAdminToken:
|
||||||
text=True,
|
text=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
print("ALLLLLLLL ISSS OKKEEEEEEEYEEYEYEYEYEYEYEYEYEyFvsdsnmiosfdI HATE YOU")
|
logging.error("reset_and_save_idm_admin_password END subprocess.check_output")
|
||||||
|
|
||||||
os.system(f"echo '{output}' >> /root/output.txt)")
|
|
||||||
|
|
||||||
output = output.decode("utf-8")
|
output = output.decode("utf-8")
|
||||||
|
|
||||||
os.system(f"echo '{output}' >> /root/outputde.txt)")
|
|
||||||
|
|
||||||
match = re.search(r'"password":"([^"]+)"', output)
|
match = re.search(r'"password":"([^"]+)"', output)
|
||||||
new_kanidm_admin_password = match.group(
|
new_kanidm_admin_password = match.group(
|
||||||
1
|
1
|
||||||
) # we have many not json strings in output
|
) # we have many not json strings in output
|
||||||
|
|
||||||
os.system(
|
logging.error("reset_and_save_idm_admin_password FULL END")
|
||||||
f"echo '{new_kanidm_admin_password}' >> /root/new_kanidm_admin_password.txt)"
|
logging.error(
|
||||||
|
f"reset_and_save_idm_admin_password FIND {new_kanidm_admin_password}"
|
||||||
)
|
)
|
||||||
|
|
||||||
redis.set("kanidm:password", new_kanidm_admin_password)
|
redis.set("kanidm:password", new_kanidm_admin_password)
|
||||||
|
|
Loading…
Reference in a new issue