General update on Carling tools, device creation on IoT Hub and I-Sight Configuration Tool

This commit is contained in:
Quentin WEPHRE
2025-09-19 08:54:59 +02:00
parent 56fceb7542
commit 4d01717779
7 changed files with 251 additions and 67 deletions

View File

@@ -1,14 +1,23 @@
import requests
import json
import argparse
import sys
import os
import urllib3
from dotenv import load_dotenv
import io
import time
import sys
load_dotenv(override=True)
def resource_path(relative_path):
""" Get absolute path to resource, works for dev and for PyInstaller """
try:
# PyInstaller creates a temp folder and stores path in _MEIPASS
base_path = sys._MEIPASS
except Exception:
base_path = os.path.abspath(".")
return os.path.join(base_path, relative_path)
dotenv_path = resource_path('.env')
load_dotenv(dotenv_path=dotenv_path)
def authenticate(base_url):
"""
@@ -17,9 +26,17 @@ def authenticate(base_url):
"""
auth_url = f"{base_url}/api/auth"
username = os.getenv("DEFAULT_CUBE_WEB_ADMIN_USER")
password = os.getenv("DEFAULT_CUBE_WEB_ADMIN_PASSWORD")
certificate = os.getenv("DEFAULT_CERTIFICATE").encode("utf-8")
ENV_WEB = {
"DEFAULT_CUBE_WEB_ADMIN_USER": os.getenv("DEFAULT_CUBE_WEB_ADMIN_USER"),
"DEFAULT_CUBE_WEB_ADMIN_PASSWORD": os.getenv("DEFAULT_CUBE_WEB_ADMIN_PASSWORD"),
"DEFAULT_CERTIFICATE": os.getenv("DEFAULT_CERTIFICATE")
}
username = ENV_WEB["DEFAULT_CUBE_WEB_ADMIN_USER"]
password = ENV_WEB["DEFAULT_CUBE_WEB_ADMIN_PASSWORD"]
certificate = ENV_WEB["DEFAULT_CERTIFICATE"].encode("utf-8")
#print(f"{username} {password} {certificate}")
# Prepare the multipart form data
auth_params = {
@@ -30,7 +47,7 @@ def authenticate(base_url):
"params": (None, json.dumps(auth_params), "application/json"),
"certificate": ("certificate.pem", certificate, "application/octet-stream")
}
print(f"Authenticating against {auth_url} with {username} {password} {certificate}")
print(f"Authenticating against {auth_url}")
try:
response = requests.post(auth_url, files=files, verify=False, timeout=10)
response.raise_for_status() # Raise exception for 4XX/5XX responses