Last active
June 2, 2023 10:13
-
-
Save apollo13/f4fc8f33a2700dffb9e11c1b056c53ba to your computer and use it in GitHub Desktop.
OwnCloud/NextCloud emulator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[tool.poetry] | |
name = "owncloudemulator" | |
version = "0.1.0" | |
description = "" | |
authors = ["Florian Apolloner <[email protected]>"] | |
[tool.poetry.dependencies] | |
python = "^3.7" | |
starlette = "^0.13.0" | |
uvicorn = "^0.10.8" | |
[tool.poetry.dev-dependencies] | |
[build-system] | |
requires = ["poetry>=0.12"] | |
build-backend = "poetry.masonry.api" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This simple server emulates a owncloud server for gnome-online-accounts. | |
# It just redirects the DAV discovery to fastmail :D | |
from starlette.applications import Starlette | |
from starlette.routing import Route, Mount | |
from starlette.requests import Request | |
from starlette.responses import Response, RedirectResponse | |
async def homepage(request: Request): | |
return Response() | |
async def dav(request: Request): | |
mapping = { | |
"caldav": "https://caldav.fastmail.com/dav/calendars", | |
"carddav": "https://carddav.fastmail.com/dav/addressbooks", | |
} | |
return RedirectResponse(mapping[request.path_params["type"]]) | |
app = Starlette( | |
debug=False, | |
routes=[ | |
Route("/.well-known/{type}", dav, methods=["PROPFIND"]), | |
Mount( | |
"/remote.php", | |
routes=[ | |
Route("/webdav/", homepage), | |
Route("/{type}/", dav, methods=["PROPFIND"]), | |
], | |
), | |
], | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nope, go for it. And thanks for putting that together!