From d7b8d61da547090dd9213409bf88624c9980b5d5 Mon Sep 17 00:00:00 2001 From: Fanch Date: Tue, 14 Oct 2025 18:30:46 +0200 Subject: [PATCH] init checkPahekoLdap.py --- bin/checkPahekoLdap.py | 48 ++++++++++++++++++++++++++++++++++++++++++ bin/lib/config.py | 2 ++ bin/lib/paheko.py | 16 ++++++++++---- 3 files changed, 62 insertions(+), 4 deletions(-) create mode 100755 bin/checkPahekoLdap.py diff --git a/bin/checkPahekoLdap.py b/bin/checkPahekoLdap.py new file mode 100755 index 0000000..57f4fea --- /dev/null +++ b/bin/checkPahekoLdap.py @@ -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 \ No newline at end of file diff --git a/bin/lib/config.py b/bin/lib/config.py index a08373e..a6557f7 100644 --- a/bin/lib/config.py +++ b/bin/lib/config.py @@ -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}") diff --git a/bin/lib/paheko.py b/bin/lib/paheko.py index 3999c77..e01cb7e 100644 --- a/bin/lib/paheko.py +++ b/bin/lib/paheko.py @@ -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)