2021-11-11 18:31:28 +00:00
|
|
|
#!/usr/bin/env python3
|
2021-11-16 16:14:01 +00:00
|
|
|
"""SelfPrivacy server management API"""
|
|
|
|
import os
|
2022-08-10 23:36:36 +00:00
|
|
|
from fastapi import FastAPI, Depends, Request, WebSocket, BackgroundTasks
|
|
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
from strawberry.fastapi import BaseContext, GraphQLRouter
|
2022-01-14 05:38:53 +00:00
|
|
|
|
2022-08-12 13:43:04 +00:00
|
|
|
import uvicorn
|
|
|
|
|
2022-08-10 23:36:36 +00:00
|
|
|
from selfprivacy_api.dependencies import get_api_version, get_graphql_context
|
2022-06-24 17:12:32 +00:00
|
|
|
from selfprivacy_api.graphql.schema import schema
|
2022-08-10 23:36:36 +00:00
|
|
|
from selfprivacy_api.migrations import run_migrations
|
|
|
|
from selfprivacy_api.restic_controller.tasks import init_restic
|
2022-06-24 13:05:18 +00:00
|
|
|
|
2022-08-10 23:36:36 +00:00
|
|
|
from selfprivacy_api.rest import (
|
|
|
|
system,
|
|
|
|
users,
|
|
|
|
api_auth,
|
|
|
|
services,
|
2021-11-16 16:14:01 +00:00
|
|
|
)
|
2021-11-11 18:31:28 +00:00
|
|
|
|
2022-08-10 23:36:36 +00:00
|
|
|
app = FastAPI()
|
|
|
|
graphql_app = GraphQLRouter(
|
|
|
|
schema,
|
|
|
|
context_getter=get_graphql_context,
|
|
|
|
)
|
2021-11-11 18:31:28 +00:00
|
|
|
|
2022-08-10 23:36:36 +00:00
|
|
|
app.add_middleware(
|
|
|
|
CORSMiddleware,
|
|
|
|
allow_origins=["*"],
|
|
|
|
allow_credentials=True,
|
|
|
|
allow_methods=["*"],
|
|
|
|
allow_headers=["*"],
|
|
|
|
)
|
2021-11-16 16:14:01 +00:00
|
|
|
|
|
|
|
|
2022-08-10 23:36:36 +00:00
|
|
|
app.include_router(system.router)
|
|
|
|
app.include_router(users.router)
|
|
|
|
app.include_router(api_auth.router)
|
|
|
|
app.include_router(services.router)
|
|
|
|
app.include_router(graphql_app, prefix="/graphql")
|
2022-06-24 13:05:18 +00:00
|
|
|
|
2021-11-16 16:14:01 +00:00
|
|
|
|
2022-08-10 23:36:36 +00:00
|
|
|
@app.get("/api/version")
|
|
|
|
async def get_version():
|
|
|
|
"""Get the version of the server"""
|
|
|
|
return {"version": get_api_version()}
|
2021-11-11 18:31:28 +00:00
|
|
|
|
|
|
|
|
2022-08-10 23:36:36 +00:00
|
|
|
@app.on_event("startup")
|
|
|
|
async def startup():
|
2022-01-11 05:36:11 +00:00
|
|
|
run_migrations()
|
2021-12-06 06:48:29 +00:00
|
|
|
init_restic()
|
2022-08-12 13:43:04 +00:00
|
|
|
|
2022-08-12 21:29:18 +00:00
|
|
|
|
2022-08-12 13:43:04 +00:00
|
|
|
if __name__ == "__main__":
|
2022-08-12 18:04:20 +00:00
|
|
|
uvicorn.run("selfprivacy_api.app:app", host="0.0.0.0", port=5050, log_level="info")
|