From 3357c9d4b130722562e1ad3e774dda13b1736f56 Mon Sep 17 00:00:00 2001 From: Sebastian Serfling Date: Fri, 13 Oct 2023 12:37:31 +0200 Subject: [PATCH] Remove API key From Console --- Classes/main_classes.py | 13 +++++++++++++ main.py | 24 ++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/Classes/main_classes.py b/Classes/main_classes.py index 498178d..dbc3855 100644 --- a/Classes/main_classes.py +++ b/Classes/main_classes.py @@ -119,6 +119,19 @@ class CL_SET_HOST(BaseModel): hddtotal: str ipadresse: str +class CL_GET_CPU(BaseModel): + hostname: str + cputype: str + cpuname: str + dbname: str + +class CL_SET_CPU(BaseModel): + hostname: str + cputype: str + ghz: str + cpuname: str + dbname: str + class CL_UPDATE_HOST(BaseModel): hostname: str dbname: str diff --git a/main.py b/main.py index e7786c8..b4a1019 100644 --- a/main.py +++ b/main.py @@ -94,6 +94,16 @@ async def gethost(get: CL.CL_GET_HOST,api_key: APIKey = Depends(auth.get_api_key else: return result[0][0] +@app.post("/host/get/cpu") +async def getcpu(get: CL.CL_GET_CPU,api_key: APIKey = Depends(auth.get_api_key)): + result = database( + f"SELECT id FROM `{get.dbname}`.cpulist WHERE cpuname = '{get.cpuname} AND cputyp = {get.cputype}')", + "", "") + if not result: + return False + else: + return result[0][0] + @app.post("/host/get/database") async def getdatabase(get: CL.CL_GET_DATABASE,api_key: APIKey = Depends(auth.get_api_key)): result = database(f"SELECT Datenbank FROM `Kunden` where `Subnetz` = '{get.ip}'","Stines-GmbH","") @@ -113,6 +123,20 @@ async def sethost(get: CL.CL_SET_HOST,api_key: APIKey = Depends(auth.get_api_key else: return result[0][0] +@app.post("/host/set/cpu") +async def setcpu(get: CL.CL_SET_CPU,api_key: APIKey = Depends(auth.get_api_key)): + database(f"INSERT INTO `{get.dbname}`.cpulist (cpuname,ghz,cputyp) VALUES ('{get.cpuname}','{get.ghz}','{get.cputyp}')","","") + result = database( + f"SELECT id FROM `{get.dbname}`.cpulist WHERE cpuname = '{get.cpuname} AND cputyp = {get.cputyp}')", + "", "") + database( + f"INSERT INTO `{get.dbname}`.cpu_to_client (hardwareID,cpulistID) VALUES ('{get.hardwareID}','{result[0][0]}',)", + "", "") + if not result: + return False + else: + return result[0][0] + @app.post("/host/update") async def updatehost(get: CL.CL_UPDATE_HOST,api_key: APIKey = Depends(auth.get_api_key)): database(f"UPDATE `{get.dbname}`.hardware SET ipadresse = '{get.ipadresse}', ram = '{get.ram}', hddused = '{get.hddused}' ,hddfree = '{get.hddfree}',hddtotal = '{get.hddtotal}' WHERE hostname = '{get.hostname}'","","")