Remplacement endpoint evidence CISO Assistant par evidence-revision
Permet de garder un historique des preuves poussées sur CISO Assistant.
This commit is contained in:
@@ -25,7 +25,10 @@ GRAPH_OUTPUT_DIR = "tmp/graphs_"+PASSERELLE
|
|||||||
# CISO Assistant
|
# CISO Assistant
|
||||||
CISO_URL = "https://<CISO_ASSISTANT_ADDRESS>"
|
CISO_URL = "https://<CISO_ASSISTANT_ADDRESS>"
|
||||||
CISO_TOKEN = "<CISO_ASSISTANT_TOKEN>"
|
CISO_TOKEN = "<CISO_ASSISTANT_TOKEN>"
|
||||||
CISO_EVIDENCE = f"{CISO_URL}/api/evidences/<EVIDENCE_ID>/upload/"
|
CISO_EVIDENCE_PATH = f"{CISO_URL}/api/evidence-revisions/"
|
||||||
|
CISO_FORLDER_ID = "<CISO_FORLDER_ID>"
|
||||||
|
CISO_EVIDENCE_ID = "<CISO_EVIDENCE_ID>"
|
||||||
|
|
||||||
|
|
||||||
def md5sum(path):
|
def md5sum(path):
|
||||||
md5 = hashlib.md5()
|
md5 = hashlib.md5()
|
||||||
@@ -72,20 +75,34 @@ def normalize_ports(port_field):
|
|||||||
return "Any"
|
return "Any"
|
||||||
return re.sub(r'\s+', '', port_field.strip()) or "Any"
|
return re.sub(r'\s+', '', port_field.strip()) or "Any"
|
||||||
|
|
||||||
def export_to_ciso(url,token,fichier):
|
def export_to_ciso(url, token, folder, evidence, fichier):
|
||||||
upload_url = url
|
|
||||||
upload_headers = {
|
upload_headers = {
|
||||||
'Authorization': f'Token {token}',
|
'Authorization': f'Token {token}',
|
||||||
'accept': 'application/json',
|
'Accept': 'application/json',
|
||||||
'Content-Type': 'document',
|
|
||||||
'Content-Disposition': f'attachment; filename={fichier}'
|
|
||||||
}
|
}
|
||||||
file_path = fichier
|
data = {
|
||||||
with open(file_path, 'rb') as file:
|
"is_published": True,
|
||||||
response = requests.post(upload_url, headers=upload_headers, data=file, verify=False)
|
"observation": "Preuve générée automatiquement",
|
||||||
if response.status_code == 200:
|
"folder": folder,
|
||||||
|
"evidence": evidence
|
||||||
|
}
|
||||||
|
# IMPORTANT : "attachment" doit correspondre au champ attendu par l'API
|
||||||
|
with open(fichier, 'rb') as file:
|
||||||
|
files = {
|
||||||
|
"attachment": (fichier.split("/")[-1], file, "application/pdf")
|
||||||
|
}
|
||||||
|
response = requests.post(
|
||||||
|
url,
|
||||||
|
headers=upload_headers,
|
||||||
|
data=data,
|
||||||
|
files=files,
|
||||||
|
verify=False
|
||||||
|
)
|
||||||
|
if response.status_code in (200, 201):
|
||||||
|
logging.info("Export vers Ciso réussi.")
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
|
logging.error(f"Échec : {response.status_code} -> {response.text}")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def parse_csv_and_generate(csv_path, output_dir):
|
def parse_csv_and_generate(csv_path, output_dir):
|
||||||
@@ -251,7 +268,7 @@ def parse_csv_and_generate(csv_path, output_dir):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"⚠️ Erreur lors de la génération du PDF : {e}")
|
print(f"⚠️ Erreur lors de la génération du PDF : {e}")
|
||||||
|
|
||||||
if not export_to_ciso(CISO_EVIDENCE, CISO_TOKEN, pdf_path):
|
if not export_to_ciso(CISO_EVIDENCE_PATH, CISO_TOKEN, CISO_FORLDER_ID, CISO_EVIDENCE_ID, pdf_path):
|
||||||
logging.error("Échec de l'exportation dans Ciso.")
|
logging.error("Échec de l'exportation dans Ciso.")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user