2022-03-06 15:29:00 +01:00
|
|
|
import logging
|
|
|
|
import structlog
|
|
|
|
from unicodedata import name
|
|
|
|
from urllib.error import HTTPError
|
2022-04-22 18:34:48 +02:00
|
|
|
from fastapi import Depends, FastAPI, Request, BackgroundTasks
|
2022-03-06 15:29:00 +01:00
|
|
|
from pydantic import BaseModel
|
|
|
|
from app.authentik.api import Authentik
|
|
|
|
from app.authentik.models import User
|
2022-04-22 18:34:48 +02:00
|
|
|
from app.event_controller import Authentik_Hook_Model, Event_Controller, Http_request
|
2022-03-03 16:36:08 +01:00
|
|
|
from .wekan.api import Wekan
|
|
|
|
import json
|
2022-03-02 16:10:17 +01:00
|
|
|
|
2022-03-06 15:29:00 +01:00
|
|
|
logging = structlog.get_logger()
|
|
|
|
|
2022-03-02 16:10:17 +01:00
|
|
|
app = FastAPI()
|
|
|
|
|
|
|
|
@app.get("/")
|
|
|
|
async def root():
|
2022-03-03 16:36:08 +01:00
|
|
|
return {'message': 'Hello World'}
|
|
|
|
|
2022-03-06 15:29:00 +01:00
|
|
|
@app.post("/authentik/hook/")
|
2022-03-06 15:51:27 +01:00
|
|
|
async def hook(model: Authentik_Hook_Model,
|
|
|
|
http_request: Http_request,
|
2022-04-22 18:34:48 +02:00
|
|
|
event_controller: Event_Controller = Depends()):
|
2022-03-06 15:29:00 +01:00
|
|
|
logging.info(model)
|
|
|
|
logging.info(http_request)
|
2022-03-06 15:51:27 +01:00
|
|
|
if http_request.path == "/api/v3/core/users/":
|
|
|
|
event_controller.handle_model_created_event(model)
|
2022-03-06 15:29:00 +01:00
|
|
|
return 200
|
2022-03-06 15:51:27 +01:00
|
|
|
|
2022-04-22 18:34:48 +02:00
|
|
|
# @app.get("/authentik/create_hook/")
|
|
|
|
# async def hook(request: Request):
|
|
|
|
# a = Authentik(base="http://localhost:9000/", token="foobar123")
|
|
|
|
# res = a.create_web_hook()
|
|
|
|
# logging.info(res)
|
|
|
|
|
|
|
|
# @app.get("/authentik/users/create_demo_user/")
|
|
|
|
# async def create_demo_user(request: Request):
|
|
|
|
# a = Authentik(base="http://localhost:9000/", token="foobar123")
|
|
|
|
# try:
|
|
|
|
# user = a.create_user(
|
|
|
|
# User(username="demo", name="dmeo", email="foo@example.org"))
|
|
|
|
# except Exception as e: # TODO
|
|
|
|
# return e
|
|
|
|
# logging.info(user)
|
|
|
|
# return user.dict
|