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'
|
#TODO: au lieu d'avoir les IP en dur, prendre le fichier allow_ip'
|
||||||
|
|
||||||
trusted_ips = [
|
trusted_ips = [
|
||||||
|
"176.180.83.10",
|
||||||
"82.64.20.246",
|
"82.64.20.246",
|
||||||
"31.39.14.228",
|
"31.39.14.228",
|
||||||
"51.75.112.172",
|
"51.75.112.172",
|
||||||
@ -96,7 +97,7 @@ trusted_ips = [
|
|||||||
#le secret pour générer les tokens
|
#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')
|
||||||
app.config['JWT_SECRET_KEY'] = os.environ.get('JWT_SECRET_KEY', 'your_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
|
#pour le mail
|
||||||
app.config['MAIL_SERVER']= os.environ.get('apikaz_MAIL_SERVER')
|
app.config['MAIL_SERVER']= os.environ.get('apikaz_MAIL_SERVER')
|
||||||
@ -119,6 +120,7 @@ def limit_remote_addr():
|
|||||||
#authent mdp/pass basique
|
#authent mdp/pass basique
|
||||||
def check_auth(username, password):
|
def check_auth(username, password):
|
||||||
return username == os.environ.get('apikaz_doc_user') and password == os.environ.get('apikaz_doc_password')
|
return username == os.environ.get('apikaz_doc_user') and password == os.environ.get('apikaz_doc_password')
|
||||||
|
#return True
|
||||||
|
|
||||||
def authenticate():
|
def authenticate():
|
||||||
return Response('tssssss.\n', 401, {'WWW-Authenticate': 'Basic realm="Login Required"'})
|
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 time import sleep
|
||||||
from glob import glob
|
from glob import glob
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
from datetime import datetime
|
from datetime import datetime, timedelta
|
||||||
|
@ -1,21 +1,25 @@
|
|||||||
from resources.common_imports import *
|
from resources.common_imports import *
|
||||||
|
|
||||||
|
from resources.ldap import Ldap_user
|
||||||
|
|
||||||
#les variables globales minimum
|
#les variables globales minimum
|
||||||
from resources.config import *
|
from resources.config import *
|
||||||
|
|
||||||
|
|
||||||
class Test(Resource):
|
class Test(Resource):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
toto="toto"
|
global paheko_ident, paheko_pass, paheko_url
|
||||||
#self.mattermost_team_resource=Mattermost_team()
|
self.paheko_ident = paheko_ident
|
||||||
#global mattermost_url, sympa_url, webmail_url, mdp_url, site_url, nc_url
|
self.paheko_pass = paheko_pass
|
||||||
|
self.paheko_url = paheko_url
|
||||||
#********************************************************************************************
|
|
||||||
@jwt_required()
|
self.ldap_user_resource = Ldap_user()
|
||||||
def get(self):
|
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:
|
tags:
|
||||||
- Test
|
- Test
|
||||||
@ -28,6 +32,48 @@ class Test(Resource):
|
|||||||
401:
|
401:
|
||||||
description: KO
|
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 ?
|
# risque sécu ?
|
||||||
|
|
||||||
|
|
||||||
cmd="ssh -p 2201 fabricer@163.172.94.54 mkdir -p /tmp/toto"
|
# cmd="ssh -p 2201 fabricer@163.172.94.54 mkdir -p /tmp/toto"
|
||||||
try:
|
# try:
|
||||||
output = subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT)
|
# output = subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT)
|
||||||
return "ok",200
|
# return "ok",200
|
||||||
|
#
|
||||||
except subprocess.CalledProcessError as e:
|
# except subprocess.CalledProcessError as e:
|
||||||
return e.output.decode("utf-8"), 400
|
# return e.output.decode("utf-8"), 400
|
||||||
|
|
||||||
#********************************************************************************************
|
#********************************************************************************************
|
||||||
# #***** test suppression de toutes les équipes de MM sauf KAZ
|
# #***** test suppression de toutes les équipes de MM sauf KAZ
|
||||||
|
Loading…
Reference in New Issue
Block a user