init checkPahekoLdap.py
This commit is contained in:
@@ -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}")
|
||||
|
||||
|
@@ -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)
|
||||
|
||||
|
Reference in New Issue
Block a user