Skip to content

Instantly share code, notes, and snippets.

@apollo13

apollo13/pyproject.toml

Last active Sep 27, 2020
Embed
What would you like to do?
OwnCloud/NextCloud emulator
[tool.poetry]
name = "owncloudemulator"
version = "0.1.0"
description = ""
authors = ["Florian Apolloner <florian@apolloner.eu>"]
[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 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"]),
],
),
],
)
@Schroedi

This comment has been minimized.

Copy link

@Schroedi Schroedi commented Dec 5, 2019

Thanks a lot for this snippet!
Just for future reference, this snipped helps in addressing this feature request: https://bugzilla.gnome.org/show_bug.cgi?id=720519

What does this do?

This script makes it easy to use fastmail calendars in gnome-accounts.
It emulates a simple Owncloud instance that redirects caldav urls to fastmail.

Running the script locally

poetry install
poetry run uvicorn --reload server:app

Now use localhost:8000 as the server address in the Owncloud plugin in gnome-accounts. The username and password are your fastmail username and an app-password with CalDav access.

@jmcclelland

This comment has been minimized.

Copy link

@jmcclelland jmcclelland commented Feb 14, 2020

This is brilliant and so simple. Worked perfectly for me - thank you!

I used it for zimbra - which has the following URL:

        "caldav": "https://$SERVER/dav/$USER/Calendar",
@duckwork

This comment has been minimized.

Copy link

@duckwork duckwork commented Apr 25, 2020

Hey! This works great; I'm curious about adding webdav (files) support as well. I'm guessing it's in the dav() function mapping .. would something like this work:

"webdav": "https://myfiles.fastmail.com"

? Thanks again for the great little tool!

@apollo13

This comment has been minimized.

Copy link
Owner Author

@apollo13 apollo13 commented Apr 25, 2020

@duckwork I don't think that works since you cannot generate app passwords in fastmail (I just tried) which provide access to CardDav/CalDav & Files :( But if you are just using your normal password you might try adding the mapping and remove the Route in line 29.

@apollo13

This comment has been minimized.

Copy link
Owner Author

@apollo13 apollo13 commented Apr 25, 2020

FWIW I have asked the fastmail CEO if this could be added https://twitter.com/fapolloner/status/1254138648238448640

@apollo13

This comment has been minimized.

Copy link
Owner Author

@apollo13 apollo13 commented Apr 25, 2020

And even then it won't work because gvfs cannot follow redirects: https://gitlab.gnome.org/GNOME/gvfs/-/issues/177 :(

@duckwork

This comment has been minimized.

Copy link

@duckwork duckwork commented Apr 26, 2020

hmm.. thanks for the reply! I realized that for now, I can just add fastmail's files in Nautilus with davfs://
so that works well enough.
Thanks for the reply! AND for the message to Fastmail -- it should be an option, I think.

@apollo13

This comment has been minimized.

Copy link
Owner Author

@apollo13 apollo13 commented Apr 26, 2020

Yes, file integration from goa doesn't much more than that by itself anyways I think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment