-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
37 changed files
with
2,336 additions
and
852 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
MONGODB_URL="mongodb://localhost:27017" | ||
MONGODB_USER=None | ||
MONGODB_PASSWORD=None | ||
|
||
MONGODB_GLOBAL_DATABASE_URL=None | ||
MONGODB_GLOBAL_DATABASE_USER=None | ||
MONGODB_GLOBAL_DATABASE_PASSWORD=None | ||
|
||
EMAIL_VERIFICATION_REQUIRED=False | ||
|
||
MAIL_USERNAME="[email protected]" | ||
MAIL_PASSWORD="" | ||
MAIL_PORT=587 | ||
MAIL_SMTP_SERVER="" | ||
MAIL_STARTTLS=True | ||
MAIL_SSL_TLS=False | ||
|
||
PASSWORD_RESET_URL="" | ||
EMAIL_VERIFY_URL="" | ||
SECRET="totally secret" | ||
|
||
REGISTRATION_ENABLED=True | ||
REGISTRATION_ADMIN_APPROVAL=False | ||
|
||
CREATE_INDEXES_WITH_PROJECT=True | ||
|
||
DEBUG=False | ||
PANDAHUB_SERVER_URL="0.0.0.0" | ||
PANDAHUB_SERVER_PORT=8002 | ||
WORKERS=2 |
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 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 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 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 file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,19 @@ | ||
FROM python:3.9 as dev | ||
FROM python:3.10 as dev | ||
|
||
ENV PYTHONUNBUFFERED 1 | ||
ENV PYTHONPATH /code/ | ||
WORKDIR /code | ||
COPY ./requirements.txt . | ||
RUN pip install -r requirements.txt | ||
RUN pip install watchdog pyyaml | ||
CMD uvicorn --host "0.0.0.0" --port "8002" "pandahub.api.main:app" --reload | ||
ENV PYTHONPATH /code/pandahub | ||
|
||
ENV DEBUG False | ||
ENV PANDAHUB_SERVER_URL 0.0.0.0 | ||
ENV PANDAHUB_SERVER_PORT 8002 | ||
ENV WORKERS 2 | ||
|
||
COPY ./ /code/pandahub/ | ||
WORKDIR /code/pandahub | ||
|
||
RUN python -m pip install --upgrade pip | ||
RUN python -m pip install .["all"] | ||
RUN python -m pip install watchdog pyyaml | ||
|
||
# CMD uvicorn --host "0.0.0.0" --port "8002" "pandahub.api.main:app" --reload | ||
ENTRYPOINT ["python", "pandahub/api/main.py"] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,34 @@ | ||
version: '3.7' | ||
version: '3' | ||
|
||
networks: | ||
test: | ||
external: false | ||
|
||
services: | ||
pandahub: | ||
image: dev/pandahub | ||
build: . | ||
db: | ||
user: ${CURRENT_UID} | ||
image: mongo:latest | ||
container_name: mongodb | ||
restart: always | ||
networks: | ||
- test | ||
ports: | ||
- "27017:27017" | ||
|
||
pandahub_server: | ||
user: ${CURRENT_UID} | ||
container_name: pandahub | ||
build: | ||
context: . | ||
dockerfile: Dockerfile | ||
environment: | ||
- SECRET=devonly! | ||
- MONGODB_URL=${MONGODB_URL:-mongodb://db:27017} | ||
ports: | ||
- "8002:8002" | ||
volumes: | ||
- ./pandahub:/code/pandahub | ||
|
||
|
||
|
||
# volumes: | ||
# - ./:/code/pandahub | ||
networks: | ||
- test | ||
depends_on: | ||
- db |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
__version__ = "0.2.8" | ||
import importlib.metadata | ||
|
||
__version__ = importlib.metadata.version("pandahub") | ||
|
||
from pandahub.lib.PandaHub import PandaHub, PandaHubError | ||
from pandahub.client.PandaHubClient import PandaHubClient | ||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
from fastapi import Depends | ||
|
||
from pandahub import PandaHub | ||
from .internal.models import UserDB | ||
from .internal.db import User | ||
from .internal.users import fastapi_users | ||
|
||
current_active_user = fastapi_users.current_user(active=True) | ||
|
||
|
||
def pandahub(user: UserDB = Depends(current_active_user)): | ||
def pandahub(user: User = Depends(current_active_user)): | ||
return PandaHub(user_id=str(user.id)) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,40 @@ | ||
import asyncio | ||
import uuid | ||
|
||
import motor.motor_asyncio | ||
from fastapi_users.db import MongoDBUserDatabase | ||
from fastapi_users_db_mongodb.access_token import MongoDBAccessTokenDatabase | ||
|
||
from beanie import Document | ||
from fastapi_users.db import BeanieBaseUser, BeanieUserDatabase | ||
from fastapi_users_db_beanie.access_token import ( | ||
BeanieAccessTokenDatabase, | ||
BeanieBaseAccessToken, | ||
) | ||
|
||
from pandahub.api.internal.settings import REGISTRATION_ADMIN_APPROVAL | ||
from pandahub.api.internal import settings | ||
from pandahub.api.internal.models import AccessToken, UserDB | ||
from pydantic import Field | ||
|
||
mongo_client_args = {"host": settings.MONGODB_URL, "uuidRepresentation": "standard", "connect": False} | ||
if settings.MONGODB_USER: | ||
mongo_client_args |= {"username": settings.MONGODB_USER, "password": settings.MONGODB_PASSWORD} | ||
|
||
client = motor.motor_asyncio.AsyncIOMotorClient(**mongo_client_args) | ||
|
||
client.get_io_loop = asyncio.get_event_loop | ||
|
||
db = client["user_management"] | ||
collection = db["users"] | ||
access_tokens_collection = db["access_tokens"] | ||
|
||
class User(BeanieBaseUser, Document): | ||
id: uuid.UUID = Field(default_factory=uuid.uuid4) | ||
is_active: bool = not REGISTRATION_ADMIN_APPROVAL | ||
class Settings(BeanieBaseUser.Settings): | ||
name = "users" | ||
|
||
async def get_user_db(): | ||
if settings.COSMOSDB_COMPAT: | ||
yield MongoDBUserDatabaseCosmos(UserDB, collection) | ||
else: | ||
yield MongoDBUserDatabase(UserDB, collection) | ||
|
||
class AccessToken(BeanieBaseAccessToken, Document): | ||
user_id: uuid.UUID = Field(default_factory=uuid.uuid4) | ||
class Settings(BeanieBaseAccessToken.Settings): | ||
name = "access_tokens" | ||
|
||
async def get_user_db(): | ||
yield BeanieUserDatabase(User) | ||
|
||
async def get_access_token_db(): | ||
yield MongoDBAccessTokenDatabase(AccessToken, access_tokens_collection) | ||
|
||
class MongoDBUserDatabaseCosmos(MongoDBUserDatabase): | ||
from typing import Optional | ||
from fastapi_users.models import UD | ||
async def get_by_email(self, email: str) -> Optional[UD]: | ||
await self._initialize() | ||
|
||
user = await self.collection.find_one( | ||
{"email": email} | ||
) | ||
return self.user_db_model(**user) if user else None | ||
|
||
async def _initialize(self): | ||
if not self.initialized: | ||
if "email_1" not in await self.collection.index_information(): | ||
await self.collection.create_index("id", unique=True) | ||
await self.collection.create_index("email", unique=True) | ||
self.initialized = True | ||
yield BeanieAccessTokenDatabase(AccessToken) |
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import uuid | ||
|
||
from fastapi_users import schemas | ||
from pandahub.api.internal.settings import REGISTRATION_ADMIN_APPROVAL | ||
|
||
|
||
class UserRead(schemas.BaseUser[uuid.UUID]): | ||
pass | ||
|
||
|
||
class UserCreate(schemas.BaseUserCreate): | ||
is_active: bool = not REGISTRATION_ADMIN_APPROVAL | ||
|
||
|
||
class UserUpdate(schemas.BaseUserUpdate): | ||
pass |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,14 +31,14 @@ def get_secret(key, default=None): | |
if not MONGODB_GLOBAL_DATABASE_URL: | ||
MONGODB_GLOBAL_DATABASE_URL = os.getenv("MONGODB_URL_GLOBAL_DATABASE") or None | ||
|
||
EMAIL_VERIFICATION_REQUIRED = settings_bool("EMAIL_VERIFICATION_REQUIRED") | ||
EMAIL_VERIFICATION_REQUIRED = settings_bool("EMAIL_VERIFICATION_REQUIRED", default=False) | ||
|
||
MAIL_USERNAME = os.getenv("MAIL_USERNAME") or "[email protected]" | ||
MAIL_PASSWORD = os.getenv("MAIL_PASSWORD") or "" | ||
MAIL_PORT = os.getenv("MAIL_PORT") or 587 | ||
MAIL_SMTP_SERVER = os.getenv("MAIL_SMTP_SERVER") or "" | ||
MAIL_TLS = os.getenv("MAIL_TLS") or True | ||
MAIL_SSL = os.getenv("MAIL_SSL") or False | ||
MAIL_STARTTLS = settings_bool("MAIL_STARTTLS", default=True) | ||
MAIL_SSL_TLS = settings_bool("MAIL_SSL_TLS", default=False) | ||
|
||
PASSWORD_RESET_URL = os.getenv("PASSWORD_RESET_URL") or "" | ||
EMAIL_VERIFY_URL = os.getenv("EMAIL_VERIFY_URL") or "" | ||
|
@@ -47,5 +47,9 @@ def get_secret(key, default=None): | |
REGISTRATION_ENABLED = settings_bool("REGISTRATION_ENABLED", default=True) | ||
REGISTRATION_ADMIN_APPROVAL = settings_bool("REGISTRATION_ADMIN_APPROVAL", default=False) | ||
|
||
DATATYPES_MODULE = os.getenv("DATATYPES_MODULE") or "pandahub.lib.datatypes" | ||
COSMOSDB_COMPAT = settings_bool("COSMOSDB_COMPAT", default=False) | ||
CREATE_INDEXES_WITH_PROJECT = settings_bool("CREATE_INDEXES_WITH_PROJECT", default=True) | ||
|
||
DEBUG = settings_bool("DEBUG", default=False) | ||
PANDAHUB_SERVER_URL = os.getenv("PANDAHUB_SERVER_URL", "0.0.0.0") | ||
PANDAHUB_SERVER_PORT = int(os.getenv('PANDAHUB_SERVER_PORT', 8002)) | ||
WORKERS = int(os.getenv('WORKER', 2)) |
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
Oops, something went wrong.