integrate/app/main.py

50 lines
1.5 KiB
Python
Raw Normal View History

2022-03-06 15:29:00 +01:00
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
2022-04-29 14:56:51 +02:00
from app.consumer.baseConsumer import BaseUser, Consumer
2022-03-06 15:29:00 +01:00
from app.authentik.api import Authentik
from app.authentik.models import User
2022-04-23 18:49:28 +02:00
from app.event_controller import Authentik_Hook_Model, EventController, Http_request
2022-04-29 14:13:54 +02:00
from app.authentik.settings import AuthentikSettings
2022-04-29 14:56:51 +02:00
from .consumer.wekan.api import WekanApi
2022-04-29 14:13:54 +02:00
from .routers import identityProvider
2022-03-03 16:36:08 +01:00
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()
2022-04-29 14:13:54 +02:00
app.include_router(identityProvider.router)
2022-03-02 16:10:17 +01:00
@app.get("/")
async def root():
2022-03-03 16:36:08 +01:00
return {'message': 'Hello World'}
2022-04-29 14:56:51 +02:00
@app.get("/consumer/")
async def get_consumer():
l = []
for sc in Consumer.__subclasses__():
l.append(sc.__name__)
return l
2022-03-06 15:51:27 +01:00
2022-04-29 14:56:51 +02:00
2022-04-29 14:13:54 +02:00
### for testing purposes
2022-04-23 18:49:28 +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(hook_endpoint="http://172.17.0.1:8000/authentik/hook/") # docker localhost
logging.info(res)
2022-04-22 18:34:48 +02:00
2022-04-23 18:49:28 +02:00
@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