diff --git a/pillar_tool/main.py b/pillar_tool/main.py index bf16e30..acbbd31 100644 --- a/pillar_tool/main.py +++ b/pillar_tool/main.py @@ -91,78 +91,3 @@ async def health(): return HealthCheckError(500, f"Database connection error:\n{e}").response() return HealthCheckSuccess().response() - -""" -@app.get("/pillar/{host}") -async def pillar_get(req: Request, host: str): - print(req.headers) - #return JSONResponse(content=collect_pillar_data(host)) - return JSONResponse({}) - -@app.post("/pillar/{host}") -async def pillar_set(request: Request, host: str, value: str): - return JSONResponse({ - "captain.linvogel.internal": { - "states": ["state1", "state2"], - "test": { - "pillar": "value" - } - } - }) - - -# TODO: list, create update and delete hosts -@app.get("/hosts") -async def host_list(request: Request): - all_hosts = list_all_hosts(request.state.db) - return JSONResponse([x.name for x in all_hosts if not x.is_hostgroup]) - - -# TODO: list, create, update and delete hostgroups -@app.get("/hostgroups") -async def hostgroup_list(request: Request): - all_hosts = list_all_hosts(request.state.db) - return JSONResponse([x.name for x in all_hosts if x.is_hostgroup]) - - -# TODO: list, create, update and delete states -# TODO: list, create, update and delete environments - -# TODO: top files generated on a per host basis -@app.get("/top/{fqdn}") -async def host_top(req: Request, fqdn: str): - db: Session = req.state.db - - if not validate_fqdn(fqdn): - return JSONResponse(status_code=400, content={ - 'message': f"Invalid FQDN: {fqdn}" - }) - - environment_stmt = select(Environment) - result = db.execute(environment_stmt).fetchall() - - if len(result) == 0: - return JSONResponse(status_code=400, content={ - 'message': "There are no environments defined" - }) - - environments: list[Environment] = list(map(lambda x: x[0], result)) - - - stmt_host = select(Host).where(Host.name == fqdn) - result = db.execute(stmt_host).fetchall() - if len(result) < 1: - return JSONResponse(status_code=404, content={ - 'message': f"No such Host is known: {fqdn}" - }) - - # this should be enforced by the database - assert len(result) == 1 - - host: Host = result[0][0] - - stmt_top = select(Environment, Host, State).where(Environment).join - # TODO: implement - return JSONResponse({}) - -""" \ No newline at end of file