Small code refactor of the jobs and the scheduler's function that generates configs
This commit is contained in:
parent
0ab07678d3
commit
0d1580cffd
|
@ -1,6 +1,6 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
from os import getenv, makedirs
|
||||
from os import getenv
|
||||
from pathlib import Path
|
||||
from shutil import copy
|
||||
from sys import exit as sys_exit, path as sys_path
|
||||
|
@ -120,7 +120,7 @@ def check_cert(cert_path, key_path, first_server: Optional[str] = None) -> bool:
|
|||
status = 0
|
||||
|
||||
try:
|
||||
makedirs("/var/cache/bunkerweb/customcert/", exist_ok=True)
|
||||
Path("/var/cache/bunkerweb/customcert/").mkdir(parents=True, exist_ok=True)
|
||||
|
||||
# Multisite case
|
||||
if getenv("MULTISITE") == "yes":
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
from hashlib import sha256
|
||||
from io import BytesIO
|
||||
from os import getenv, listdir, chmod, stat, _exit
|
||||
from os import getenv, listdir, chmod, _exit
|
||||
from os.path import basename, dirname
|
||||
from pathlib import Path
|
||||
from stat import S_IEXEC
|
||||
|
@ -49,7 +49,7 @@ def install_plugin(plugin_dir) -> bool:
|
|||
copytree(plugin_dir, f"/etc/bunkerweb/plugins/{metadata['id']}")
|
||||
# Add u+x permissions to jobs files
|
||||
for job_file in glob(f"{plugin_dir}/jobs/*"):
|
||||
st = stat(job_file)
|
||||
st = Path(job_file).stat()
|
||||
chmod(job_file, st.st_mode | S_IEXEC)
|
||||
logger.info(f"Plugin {metadata['id']} installed")
|
||||
return True
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
from os import getenv, makedirs
|
||||
from os import getenv
|
||||
from pathlib import Path
|
||||
from sys import exit as sys_exit, path as sys_path
|
||||
from threading import Lock
|
||||
|
@ -75,7 +75,7 @@ try:
|
|||
# Linux case
|
||||
else:
|
||||
root_dir = "/var/tmp/bunkerweb/lets-encrypt/.well-known/acme-challenge/"
|
||||
makedirs(root_dir, exist_ok=True)
|
||||
Path(root_dir).mkdir(parents=True, exist_ok=True)
|
||||
Path(f"{root_dir}{token}").write_text(validation)
|
||||
except:
|
||||
status = 1
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
from os import getenv
|
||||
from os.path import isfile
|
||||
from pathlib import Path
|
||||
from sys import exit as sys_exit, path as sys_path
|
||||
from threading import Lock
|
||||
|
@ -73,7 +72,7 @@ try:
|
|||
challenge_path = (
|
||||
f"/var/tmp/bunkerweb/lets-encrypt/.well-known/acme-challenge/{token}"
|
||||
)
|
||||
if isfile(challenge_path):
|
||||
if Path(challenge_path).exists():
|
||||
Path(challenge_path).unlink()
|
||||
except:
|
||||
status = 1
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
from os import getenv, makedirs
|
||||
from os.path import isfile
|
||||
from os import getenv
|
||||
from pathlib import Path
|
||||
from subprocess import DEVNULL, run
|
||||
from sys import exit as sys_exit, path as sys_path
|
||||
from traceback import format_exc
|
||||
|
@ -48,8 +48,10 @@ try:
|
|||
|
||||
# Generate the self-signed certificate
|
||||
if need_default_cert:
|
||||
makedirs("/var/cache/bunkerweb/default-server-cert", exist_ok=True)
|
||||
if not isfile("/var/cache/bunkerweb/default-server-cert/cert.pem"):
|
||||
Path("/var/cache/bunkerweb/default-server-cert").mkdir(
|
||||
parents=True, exist_ok=True
|
||||
)
|
||||
if not Path("/var/cache/bunkerweb/default-server-cert/cert.pem").is_file():
|
||||
logger.info("Generating self-signed certificate for default server")
|
||||
|
||||
cmd = "openssl req -nodes -x509 -newkey rsa:4096 -keyout /var/cache/bunkerweb/default-server-cert/cert.key -out /var/cache/bunkerweb/default-server-cert/cert.pem -days 3650".split(
|
||||
|
|
|
@ -10,7 +10,6 @@ from os import (
|
|||
getenv,
|
||||
getpid,
|
||||
listdir,
|
||||
stat,
|
||||
walk,
|
||||
)
|
||||
from os.path import dirname, join
|
||||
|
@ -134,7 +133,7 @@ def generate_external_plugins(
|
|||
Path(tmp_path).unlink()
|
||||
|
||||
for job_file in glob(f"{plugin_dir}/jobs/*"):
|
||||
st = stat(job_file)
|
||||
st = Path(job_file).stat()
|
||||
chmod(job_file, st.st_mode | S_IEXEC)
|
||||
|
||||
if integration in ("Autoconf", "Swarm", "Kubernetes", "Docker"):
|
||||
|
|
Loading…
Reference in New Issue