|
3 | 3 | import requests |
4 | 4 | from json import load as json_load, dump as json_dump |
5 | 5 | from pathlib import Path |
| 6 | +from time import sleep |
6 | 7 | from typing import Optional, Tuple |
7 | 8 | from datetime import datetime, timedelta |
8 | 9 | from passlib.hash import bcrypt |
@@ -121,11 +122,18 @@ def create_user(ip_address: str): |
121 | 122 |
|
122 | 123 |
|
123 | 124 | def check_roles_at_start(): |
| 125 | + log.warning("Warte auf SubData-Initialisierung, bevor ACL-Rollen überprüft werden ...") |
| 126 | + sleep(0.5) # we have a race condition at startup! |
| 127 | + # check roles and users at startup and add missing ones if user management is active |
| 128 | + if SubData.system_data["system"].data["security"]["user_management_active"] is not True: |
| 129 | + log.warning("Benutzerverwaltung ist deaktiviert.") |
| 130 | + return |
| 131 | + log.warning("Benutzerverwaltung ist aktiviert, überprüfe ACL-Rollen und System-Benutzer ...") |
124 | 132 | display_reload_required = update_acls() |
125 | 133 | flag_path = Path(_get_base_path() / "ramdisk" / "init_user_management") |
126 | 134 | if flag_path.is_file(): |
127 | 135 | with open(flag_path, "r") as file: |
128 | | - flag = file.readline() == "1" |
| 136 | + flag = file.readline().strip() == "1" |
129 | 137 | if flag: |
130 | 138 | for cp in SubData.cp_data.values(): |
131 | 139 | add_acl_role("chargepoint-<id>-access", cp.chargepoint.num) |
@@ -153,6 +161,7 @@ def check_roles_at_start(): |
153 | 161 | check_required_users() |
154 | 162 | # finally trigger a reload of a local display to ensure the new credentials are picked up |
155 | 163 | if display_reload_required: |
| 164 | + log.warning("ACLs wurden aktualisiert, lokale Displays werden neu geladen, um die Änderungen zu übernehmen.") |
156 | 165 | run_command([ |
157 | 166 | f"{_get_base_path()}/runs/update_local_display.sh", "1" |
158 | 167 | ], process_exception=True) |
0 commit comments