maj apikaz
This commit is contained in:
parent
0399869067
commit
f881a3ccfa
@ -74,6 +74,7 @@ swagger = Swagger(app, template={
|
||||
#TODO: au lieu d'avoir les IP en dur, prendre le fichier allow_ip'
|
||||
|
||||
trusted_ips = [
|
||||
"176.180.83.10",
|
||||
"82.64.20.246",
|
||||
"31.39.14.228",
|
||||
"51.75.112.172",
|
||||
@ -96,7 +97,7 @@ trusted_ips = [
|
||||
#le secret pour générer les tokens
|
||||
#app.config['JWT_SECRET_KEY'] = os.environ.get('JWT_SECRET_KEY')
|
||||
app.config['JWT_SECRET_KEY'] = os.environ.get('JWT_SECRET_KEY', 'your_jwt_secret_key')
|
||||
|
||||
app.config['JWT_ACCESS_TOKEN_EXPIRES'] = timedelta(days=7)
|
||||
|
||||
#pour le mail
|
||||
app.config['MAIL_SERVER']= os.environ.get('apikaz_MAIL_SERVER')
|
||||
@ -119,6 +120,7 @@ def limit_remote_addr():
|
||||
#authent mdp/pass basique
|
||||
def check_auth(username, password):
|
||||
return username == os.environ.get('apikaz_doc_user') and password == os.environ.get('apikaz_doc_password')
|
||||
#return True
|
||||
|
||||
def authenticate():
|
||||
return Response('tssssss.\n', 401, {'WWW-Authenticate': 'Basic realm="Login Required"'})
|
||||
|
@ -22,4 +22,4 @@ from email_validator import validate_email, EmailNotValidError
|
||||
from time import sleep
|
||||
from glob import glob
|
||||
from bs4 import BeautifulSoup
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timedelta
|
||||
|
@ -1,21 +1,25 @@
|
||||
from resources.common_imports import *
|
||||
|
||||
from resources.ldap import Ldap_user
|
||||
|
||||
#les variables globales minimum
|
||||
from resources.config import *
|
||||
|
||||
|
||||
class Test(Resource):
|
||||
|
||||
def __init__(self):
|
||||
toto="toto"
|
||||
#self.mattermost_team_resource=Mattermost_team()
|
||||
#global mattermost_url, sympa_url, webmail_url, mdp_url, site_url, nc_url
|
||||
def __init__(self):
|
||||
global paheko_ident, paheko_pass, paheko_url
|
||||
self.paheko_ident = paheko_ident
|
||||
self.paheko_pass = paheko_pass
|
||||
self.paheko_url = paheko_url
|
||||
|
||||
#********************************************************************************************
|
||||
@jwt_required()
|
||||
def get(self):
|
||||
self.ldap_user_resource = Ldap_user()
|
||||
self.client = app.test_client()
|
||||
|
||||
@jwt_required()
|
||||
def get(self):
|
||||
"""
|
||||
Pour tester des conneries: # test lançement de cmde ssh sur des serveurs distants:
|
||||
Dans le ldap, mettre le numeroMembre de paheko pour toutes les entrées
|
||||
---
|
||||
tags:
|
||||
- Test
|
||||
@ -28,6 +32,48 @@ class Test(Resource):
|
||||
401:
|
||||
description: KO
|
||||
"""
|
||||
auth = (self.paheko_ident, self.paheko_pass)
|
||||
|
||||
api_url = self.paheko_url + '/api/sql/'
|
||||
payload = { "sql": f"select * from users where id_category <> 13 and email='fab@kazkouil.fr'" }
|
||||
#payload = { "sql": f"select * from users where id_category <> 13 " }
|
||||
response = requests.post(api_url, auth=auth, data=payload)
|
||||
|
||||
if response.status_code == 200:
|
||||
#pour chaque fiche membre, on récup le numeroMembre et l'email
|
||||
data = response.json()
|
||||
for item in data['results']:
|
||||
# Afficher les valeurs de 'id' et 'email'
|
||||
print(f"ID: {item['id']}, Email: {item['email']}")
|
||||
#j'ajoute le champ numeroMembre dans le ldap'
|
||||
data = {
|
||||
"field": "numeroMembre",
|
||||
"value": item['id']
|
||||
}
|
||||
email=item['email']
|
||||
|
||||
# Utiliser le client de test pour appeler la méthode post de Ldap_user
|
||||
response = self.client.post(
|
||||
f'/ldap/user/{email}?action=add',
|
||||
data=json.dumps(data),
|
||||
content_type='application/json'
|
||||
)
|
||||
|
||||
return response.json, response.status_code
|
||||
|
||||
#if status_code != 200: raise ValueError(f"ERREUR 3 sur ldap: {email} : {res}, on arrête tout ")
|
||||
|
||||
|
||||
else:
|
||||
return "pas de résultat", response.status_code
|
||||
|
||||
|
||||
|
||||
#********************************************************************************************
|
||||
|
||||
#dans le ldap, mettre le numeroMembre de paheko pour toutes les entrées
|
||||
|
||||
|
||||
#********************************************************************************************
|
||||
|
||||
|
||||
@ -37,13 +83,13 @@ class Test(Resource):
|
||||
# risque sécu ?
|
||||
|
||||
|
||||
cmd="ssh -p 2201 fabricer@163.172.94.54 mkdir -p /tmp/toto"
|
||||
try:
|
||||
output = subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT)
|
||||
return "ok",200
|
||||
|
||||
except subprocess.CalledProcessError as e:
|
||||
return e.output.decode("utf-8"), 400
|
||||
# cmd="ssh -p 2201 fabricer@163.172.94.54 mkdir -p /tmp/toto"
|
||||
# try:
|
||||
# output = subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT)
|
||||
# return "ok",200
|
||||
#
|
||||
# except subprocess.CalledProcessError as e:
|
||||
# return e.output.decode("utf-8"), 400
|
||||
|
||||
#********************************************************************************************
|
||||
# #***** test suppression de toutes les équipes de MM sauf KAZ
|
||||
|
Loading…
Reference in New Issue
Block a user