Merge: Create python package #140

This is quite a big one, so it probably makes sense to review it commit-by-commit (there shouldn't be any overlap).

Summarized:
- The `etebase_fastapi` module was moved to `etebase_server.fastapi`
- The `myauth` module was moved to `etebase_server.myauth`
- The `django_etebase` module was moved to `etebase_server.django`
- The `templates/` directory was moved into `etebase_server/`
- A `setup.py` was added to allow packaging the `etebase_server` module as a python package.
master
Tom Hacohen 3 years ago committed by GitHub
commit c7d1de31a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

4
.gitignore vendored

@ -14,3 +14,7 @@ __pycache__
/etebase_server_settings.py
/secret.txt
/build
/dist
/*.egg-info

@ -151,7 +151,7 @@ Instead of having to create Django users manually when signup up Etebase users,
For example, this makes sense when putting an Etebase server in production.
However, this does come with the added risk that everybody with access to your server will be able to sign up.
In order to set it up, comment out the line `ETEBASE_CREATE_USER_FUNC = "django_etebase.utils.create_user_blocked"` in `server/settings.py` and restart your Etebase server.
In order to set it up, comment out the line `ETEBASE_CREATE_USER_FUNC = "etebase_server.django.utils.create_user_blocked"` in `server/settings.py` and restart your Etebase server.
# License

@ -7,7 +7,7 @@ django_application = get_asgi_application()
def create_application():
from etebase_fastapi.main import create_application
from etebase_server.fastapi.main import create_application
app = create_application()

@ -2,4 +2,5 @@ from django.apps import AppConfig
class DjangoEtebaseConfig(AppConfig):
name = "django_etebase"
name = "etebase_server.django"
label = "django_etebase"

@ -4,7 +4,7 @@ from django.conf import settings
import django.core.validators
from django.db import migrations, models
import django.db.models.deletion
import django_etebase.models
from etebase_server.django.models import chunk_directory_path
class Migration(migrations.Migration):
@ -85,7 +85,7 @@ class Migration(migrations.Migration):
),
(
"chunkFile",
models.FileField(max_length=150, unique=True, upload_to=django_etebase.models.chunk_directory_path),
models.FileField(max_length=150, unique=True, upload_to=chunk_directory_path),
),
(
"item",

@ -3,7 +3,7 @@
import django.core.validators
from django.db import migrations, models
import django.db.models.deletion
import django_etebase.models
from etebase_server.django.models import generate_stoken_uid
class Migration(migrations.Migration):
@ -21,7 +21,7 @@ class Migration(migrations.Migration):
"uid",
models.CharField(
db_index=True,
default=django_etebase.models.generate_stoken_uid,
default=generate_stoken_uid,
max_length=43,
unique=True,
validators=[

@ -2,7 +2,7 @@
import django.core.validators
from django.db import migrations, models
import django_etebase.models
from etebase_server.django.models import generate_stoken_uid
class Migration(migrations.Migration):
@ -62,7 +62,7 @@ class Migration(migrations.Migration):
name="uid",
field=models.CharField(
db_index=True,
default=django_etebase.models.generate_stoken_uid,
default=generate_stoken_uid,
max_length=43,
unique=True,
validators=[

@ -2,7 +2,7 @@
from django.db import migrations
from django_etebase.models import AccessLevels
from etebase_server.django.models import AccessLevels
def change_access_level_to_int(apps, schema_editor):

@ -2,4 +2,4 @@ from django.apps import AppConfig
class TokenAuthConfig(AppConfig):
name = "django_etebase.token_auth"
name = "etebase_server.django.token_auth"

@ -3,7 +3,7 @@
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
from django_etebase.token_auth import models as token_auth_models
from etebase_server.django.token_auth import models as token_auth_models
class Migration(migrations.Migration):

@ -1,7 +1,7 @@
from django.db import models
from django.utils import timezone
from django.utils.crypto import get_random_string
from myauth.models import get_typed_user_model
from etebase_server.myauth.models import get_typed_user_model
User = get_typed_user_model()

@ -3,7 +3,7 @@ from dataclasses import dataclass
from django.db.models import QuerySet
from django.core.exceptions import PermissionDenied
from myauth.models import UserType, get_typed_user_model
from etebase_server.myauth.models import UserType, get_typed_user_model
from . import app_settings

@ -6,9 +6,9 @@ from fastapi.security import APIKeyHeader
from django.utils import timezone
from django.db.models import QuerySet
from django_etebase import models
from django_etebase.token_auth.models import AuthToken, get_default_expiry
from myauth.models import UserType, get_typed_user_model
from etebase_server.django import models
from etebase_server.django.token_auth.models import AuthToken, get_default_expiry
from etebase_server.myauth.models import UserType, get_typed_user_model
from .exceptions import AuthenticationFailed
from .utils import get_object_or_404
from .db_hack import django_db_cleanup_decorator

@ -6,7 +6,7 @@ from fastapi.middleware.cors import CORSMiddleware
from fastapi.middleware.trustedhost import TrustedHostMiddleware
from fastapi.staticfiles import StaticFiles
from django_etebase import app_settings
from etebase_server.django import app_settings
from .exceptions import CustomHttpException
from .msgpack import MsgpackResponse
@ -43,7 +43,7 @@ def create_application(prefix="", middlewares=[]):
app.include_router(websocket_router, prefix=f"{BASE_PATH}/ws", tags=["websocket"])
if settings.DEBUG:
from etebase_fastapi.routers.test_reset_view import test_reset_view_router
from .routers.test_reset_view import test_reset_view_router
app.include_router(test_reset_view_router, prefix=f"{BASE_PATH}/test/authentication")

@ -1,7 +1,7 @@
import typing as t
import aioredis
from django_etebase import app_settings
from etebase_server.django import app_settings
class RedisWrapper:

@ -14,12 +14,12 @@ from django.db import transaction
from django.utils.functional import cached_property
from fastapi import APIRouter, Depends, status, Request
from django_etebase import app_settings, models
from django_etebase.token_auth.models import AuthToken
from django_etebase.models import UserInfo
from django_etebase.signals import user_signed_up
from django_etebase.utils import create_user, get_user_queryset, CallbackContext
from myauth.models import UserType, get_typed_user_model
from etebase_server.django import app_settings, models
from etebase_server.django.token_auth.models import AuthToken
from etebase_server.django.models import UserInfo
from etebase_server.django.signals import user_signed_up
from etebase_server.django.utils import create_user, get_user_queryset, CallbackContext
from etebase_server.myauth.models import UserType, get_typed_user_model
from ..exceptions import AuthenticationFailed, transform_validation_error, HttpError
from ..msgpack import MsgpackRoute
from ..utils import BaseModel, permission_responses, msgpack_encode, msgpack_decode, get_user_username_email_kwargs

@ -7,8 +7,8 @@ from django.db import transaction, IntegrityError
from django.db.models import Q, QuerySet
from fastapi import APIRouter, Depends, status, Request, BackgroundTasks
from django_etebase import models
from myauth.models import UserType
from etebase_server.django import models
from etebase_server.myauth.models import UserType
from .authentication import get_authenticated_user
from .websocket import get_ticket, TicketRequest, TicketOut
from ..exceptions import HttpError, transform_validation_error, PermissionDenied, ValidationError

@ -4,9 +4,9 @@ from django.db import transaction, IntegrityError
from django.db.models import QuerySet
from fastapi import APIRouter, Depends, status, Request
from django_etebase import models
from django_etebase.utils import get_user_queryset, CallbackContext
from myauth.models import UserType, get_typed_user_model
from etebase_server.django import models
from etebase_server.django.utils import get_user_queryset, CallbackContext
from etebase_server.myauth.models import UserType, get_typed_user_model
from .authentication import get_authenticated_user
from ..exceptions import HttpError, PermissionDenied
from ..msgpack import MsgpackRoute

@ -4,8 +4,8 @@ from django.db import transaction
from django.db.models import QuerySet
from fastapi import APIRouter, Depends, status
from django_etebase import models
from myauth.models import UserType, get_typed_user_model
from etebase_server.django import models
from etebase_server.myauth.models import UserType, get_typed_user_model
from .authentication import get_authenticated_user
from ..msgpack import MsgpackRoute
from ..utils import get_object_or_404, BaseModel, permission_responses, PERMISSIONS_READ, PERMISSIONS_READWRITE

@ -3,11 +3,11 @@ from django.db import transaction
from django.shortcuts import get_object_or_404
from fastapi import APIRouter, Request, status
from django_etebase.utils import get_user_queryset, CallbackContext
from etebase_server.django.utils import get_user_queryset, CallbackContext
from .authentication import SignupIn, signup_save
from ..msgpack import MsgpackRoute
from ..exceptions import HttpError
from myauth.models import get_typed_user_model
from etebase_server.myauth.models import get_typed_user_model
test_reset_view_router = APIRouter(route_class=MsgpackRoute, tags=["test helpers"])
User = get_typed_user_model()

@ -8,9 +8,9 @@ from fastapi import APIRouter, Depends, WebSocket, WebSocketDisconnect, status
import nacl.encoding
import nacl.utils
from django_etebase import models
from django_etebase.utils import CallbackContext, get_user_queryset
from myauth.models import UserType, get_typed_user_model
from etebase_server.django import models
from etebase_server.django.utils import CallbackContext, get_user_queryset
from etebase_server.myauth.models import UserType, get_typed_user_model
from ..dependencies import get_collection_queryset, get_item_queryset
from ..exceptions import NotSupported

@ -3,7 +3,7 @@ import typing as t
from django.db.models import QuerySet
from fastapi import status
from django_etebase.models import Stoken
from etebase_server.django.models import Stoken
from .exceptions import HttpError

@ -10,9 +10,9 @@ from pydantic import BaseModel as PyBaseModel
from django.db.models import Model, QuerySet
from django.core.exceptions import ObjectDoesNotExist
from django_etebase import app_settings
from django_etebase.models import AccessLevels
from myauth.models import UserType, get_typed_user_model
from etebase_server.django import app_settings
from etebase_server.django.models import AccessLevels
from etebase_server.myauth.models import UserType, get_typed_user_model
from .exceptions import HttpError, HttpErrorOut

@ -2,4 +2,5 @@ from django.apps import AppConfig
class MyauthConfig(AppConfig):
name = "myauth"
name = "etebase_server.myauth"
label = "myauth"

@ -1,6 +1,6 @@
from django import forms
from django.contrib.auth.forms import UsernameField
from myauth.models import get_typed_user_model
from etebase_server.myauth.models import get_typed_user_model
User = get_typed_user_model()

@ -1,7 +1,7 @@
# Generated by Django 3.0.3 on 2020-05-15 08:01
from django.db import migrations, models
import myauth.models
import etebase_server.myauth.models as myauth_models
class Migration(migrations.Migration):
@ -19,7 +19,7 @@ class Migration(migrations.Migration):
help_text="Required. 150 characters or fewer. Letters, digits and ./+/-/_ only.",
max_length=150,
unique=True,
validators=[myauth.models.UnicodeUsernameValidator()],
validators=[myauth_models.UnicodeUsernameValidator()],
verbose_name="username",
),
),

@ -1,7 +1,7 @@
# Generated by Django 3.1.1 on 2020-11-19 08:10
from django.db import migrations, models
import myauth.models
import etebase_server.myauth.models as myauth_models
class Migration(migrations.Migration):
@ -14,7 +14,7 @@ class Migration(migrations.Migration):
migrations.AlterModelManagers(
name="user",
managers=[
("objects", myauth.models.UserManager()),
("objects", myauth_models.UserManager()),
],
),
migrations.AlterField(
@ -30,7 +30,7 @@ class Migration(migrations.Migration):
help_text="Required. 150 characters or fewer. Letters, digits and ./-/_ only.",
max_length=150,
unique=True,
validators=[myauth.models.UnicodeUsernameValidator()],
validators=[myauth_models.UnicodeUsernameValidator()],
verbose_name="username",
),
),

@ -15,7 +15,8 @@ import configparser
from .utils import get_secret_from_file
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
SOURCE_DIR = os.path.dirname(os.path.abspath(__file__))
BASE_DIR = os.path.dirname(SOURCE_DIR)
AUTH_USER_MODEL = "myauth.User"
@ -54,9 +55,9 @@ INSTALLED_APPS = [
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"myauth.apps.MyauthConfig",
"django_etebase.apps.DjangoEtebaseConfig",
"django_etebase.token_auth.apps.TokenAuthConfig",
"etebase_server.myauth.apps.MyauthConfig",
"etebase_server.django.apps.DjangoEtebaseConfig",
"etebase_server.django.token_auth.apps.TokenAuthConfig",
]
MIDDLEWARE = [
@ -74,7 +75,7 @@ ROOT_URLCONF = "etebase_server.urls"
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [os.path.join(BASE_DIR, "templates")],
"DIRS": [os.path.join(SOURCE_DIR, "templates")],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
@ -167,7 +168,7 @@ if any(os.path.isfile(x) for x in config_locations):
if "database-options" in config:
DATABASES["default"]["OPTIONS"] = config["database-options"]
ETEBASE_CREATE_USER_FUNC = "django_etebase.utils.create_user_blocked"
ETEBASE_CREATE_USER_FUNC = "etebase_server.django.utils.create_user_blocked"
# Efficient file streaming (for large files)
SENDFILE_BACKEND = "etebase_fastapi.sendfile.backends.simple"

@ -1,2 +1,6 @@
[tool.black]
line-length = 120
line-length = 120
[build-system]
requires = ["setuptools>=42"]
build-backend = "setuptools.build_meta"

@ -0,0 +1,20 @@
from setuptools import find_packages, setup
setup(
name='etebase_server',
version='0.8.3',
description='An Etebase (EteSync 2.0) server',
url='https://www.etebase.com/',
classifiers=[
'Development Status :: 5 - Production/Stable',
'Framework :: Django',
'Framework :: FastAPI',
'Intended Audience :: System Administrators',
'License :: OSI Approved :: GNU Affero General Public License v3',
],
packages=find_packages(include=['etebase_server', 'etebase_server.*']),
install_requires=list(open('requirements.in/base.txt')),
package_data={
'etebase_server': ['templates/*'],
}
)
Loading…
Cancel
Save