Skip to content

Commit

Permalink
Merge branch 'release/v0.3.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
vogt31337 committed Jul 3, 2024
2 parents 61bbf43 + 13262f7 commit 4304e62
Show file tree
Hide file tree
Showing 37 changed files with 2,336 additions and 852 deletions.
30 changes: 30 additions & 0 deletions .env.example
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
17 changes: 9 additions & 8 deletions .github/workflows/github_test_action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,27 @@ jobs:
- 27017:27017

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4.7.0
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install -U pytest
pip install -r requirements.txt
pip install -r requirements_dev.txt
pip install .["all"]
python -m pip install .["all"]
- name: List of installed packages
run: |
pip list
- name: Test with pytest and Codecov
run: |
pytest --cov=./ --cov-report=xml
python -m pip install pytest-cov pytest-xdist nbmake
python -m pytest -n=auto --cov=./ --cov-report=xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v2
if: ${{ github.ref == 'refs/heads/develop' || github.ref != 'refs/heads/master' }}
uses: codecov/codecov-action@v4
with:
fail_ci_if_error: true
file: ./coverage.xml
token: ${{ secrets.CODECOV_TOKEN }}
verbose: true
12 changes: 6 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ jobs:
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3
- uses: actions/checkout@v4

# Sets up python3
- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: '3.10'
# Installs and upgrades pip, installs other dependencies and installs the package from setup.py
Expand Down Expand Up @@ -80,7 +80,7 @@ jobs:
os: [ ubuntu-latest, windows-latest ]
steps:
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
Expand All @@ -94,10 +94,10 @@ jobs:
- name: Install pandahub from PyPI
if: ${{ inputs.upload_server == 'pypi'}}
run: |
pip install pandahub
python -m pip install pandahub
- name: List all installed packages
run: |
pip list
python -m pip list
- name: Test with pytest
run: |
pytest --pyargs pandahub.test
python -m pytest --pyargs pandahub.test
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

language: python
python:
- 3.8
- 3.10

# Command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors
install: pip install -U tox-travis
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Change Log

## [0.2.4]
- BREAKING drops index argument from create_variant() function

- BREAKING drops index argument from create_variant() function

## [0.2.3]- 2022-08-04

Expand Down
23 changes: 0 additions & 23 deletions CHANGELOG.rst

This file was deleted.

25 changes: 18 additions & 7 deletions Dockerfile
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"]
37 changes: 28 additions & 9 deletions docker-compose.yml
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
6 changes: 3 additions & 3 deletions pandahub/__init__.py
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


4 changes: 2 additions & 2 deletions pandahub/api/dependencies.py
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))
55 changes: 23 additions & 32 deletions pandahub/api/internal/db.py
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)
24 changes: 0 additions & 24 deletions pandahub/api/internal/models.py

This file was deleted.

16 changes: 16 additions & 0 deletions pandahub/api/internal/schemas.py
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
14 changes: 9 additions & 5 deletions pandahub/api/internal/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
Expand All @@ -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))
4 changes: 2 additions & 2 deletions pandahub/api/internal/toolbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
MAIL_FROM=settings.MAIL_USERNAME,
MAIL_PORT=settings.MAIL_PORT,
MAIL_SERVER=settings.MAIL_SMTP_SERVER,
MAIL_TLS=settings.MAIL_TLS,
MAIL_SSL=settings.MAIL_SSL
MAIL_SSL_TLS=settings.MAIL_SSL_TLS,
MAIL_STARTTLS=settings.MAIL_STARTTLS,
)

fast_mail = FastMail(email_conf)
Expand Down
Loading

0 comments on commit 4304e62

Please sign in to comment.