init checkPahekoLdap.py

This commit is contained in:
2025-10-14 18:30:46 +02:00
parent a93d19423f
commit d7b8d61da5
3 changed files with 62 additions and 4 deletions

48
bin/checkPahekoLdap.py Executable file
View File

@@ -0,0 +1,48 @@
#!/usr/bin/python3
import sys
from lib.paheko import Paheko
from lib.ldap import Ldap
paheko = Paheko()
categorie_membres = paheko.get_categorie_id("Membres")
membres = paheko.get_users_in_categorie(categorie_membres)
def test_quota(paheko_entry, ldap_entry):
ok = True
quota_disque = paheko_entry["quota_disque"].strip("'")
if f"{quota_disque}G".encode() != ldap_entry[1]['mailQuota'][0]:
ok = False
return ok
def test_mail_secours(paheko_entry, ldap_entry):
try:
if paheko_entry["email_secours"]:
return paheko_entry["email_secours"].strip("'").encode() == ldap_entry[1]['mailDeSecours'][0]
else:
return False
except e:
print(paheko_entry)
print(ldap_entry)
raise e
with Ldap() as ldap:
try:
for membre in membres:
ldap_entry = ldap.get_email(membre["email"])[0]
ok = True
#ok &= test_quota(membre, ldap_entry)
ok &= test_mail_secours(membre, ldap_entry)
if not ok:
print(membre)
print(ldap_entry)
print()
except Exception as e:
print(membre)
print(ldap.get_email(membre["email"]))
raise e

View File

@@ -6,10 +6,12 @@ def getDockersConfig(key):
for line in config:
if line.startswith(f"{key}="):
return line.split("=", 1)[1].split("#")[0].strip()
raise Exception(f"getDockersConfig(): No config for {key}")
def getSecretConfig(serv, key):
with open(SECRETS.format(serv=serv)) as config:
for line in config:
if line.startswith(f"{key}="):
return line.split("=", 2)[1].split("#")[0].strip()
raise Exception(f"getSecretConfig(): No config for {serv}/{key}")

View File

@@ -3,8 +3,8 @@ import requests
from .config import getDockersConfig, getSecretConfig
paheko_ident = getDockersConfig("paheko_API_USER")
paheko_pass = getDockersConfig("paheko_API_PASSWORD")
paheko_ident = getSecretConfig("paheko", "API_USER")
paheko_pass = getSecretConfig("paheko", "API_PASSWORD")
paheko_auth = (paheko_ident, paheko_pass)
paheko_url = f"https://kaz-paheko.{getDockersConfig('domain')}"
@@ -24,14 +24,22 @@ class Paheko:
return None
def get_categorie_id(self, categorie_name):
categories = self.get_categories()
for categorie in categories.values():
if categorie["name"] == categorie_name:
return categorie["id"]
return None
def get_users_in_categorie(self,categorie):
"""
Afficher les membres d'une catégorie Paheko
"""
if not categorie.isdigit():
if not (isinstance(categorie, int) or categorie.isdigit()):
return 'Id de category non valide', 400
api_url = paheko_url + '/api/user/category/'+categorie+'.json'
api_url = f"{paheko_url}/api/user/category/{categorie}.json"
response = requests.get(api_url, auth=paheko_auth)