From f0dbb640f1b56333271e046447bccc65f68f8c9b Mon Sep 17 00:00:00 2001 From: kompotkot Date: Wed, 21 Jul 2021 16:51:28 +0000 Subject: [PATCH] Fixed issues, todos, added comments --- backend/moonstream/actions.py | 2 -- backend/moonstream/api.py | 3 +-- backend/moonstream/data.py | 13 ++++++++++--- backend/moonstream/middleware.py | 1 + backend/moonstream/routes/subscriptions.py | 9 ++++----- backend/moonstream/routes/users.py | 4 ++-- backend/moonstream/settings.py | 3 +-- backend/sample.env | 2 +- 8 files changed, 20 insertions(+), 17 deletions(-) delete mode 100644 backend/moonstream/actions.py diff --git a/backend/moonstream/actions.py b/backend/moonstream/actions.py deleted file mode 100644 index 139597f9..00000000 --- a/backend/moonstream/actions.py +++ /dev/null @@ -1,2 +0,0 @@ - - diff --git a/backend/moonstream/api.py b/backend/moonstream/api.py index ea80f55e..9160b086 100644 --- a/backend/moonstream/api.py +++ b/backend/moonstream/api.py @@ -3,14 +3,13 @@ The Moonstream HTTP API """ import logging -from bugout.data import BugoutUser from fastapi import FastAPI, Form from fastapi.middleware.cors import CORSMiddleware from . import data from .routes.subscriptions import app as subscriptions_api from .routes.users import app as users_api -from .settings import ORIGINS, bugout_client as bc, MOONSTREAM_APPLICATION_ID +from .settings import ORIGINS from .version import MOONSTREAM_VERSION logging.basicConfig(level=logging.INFO) diff --git a/backend/moonstream/data.py b/backend/moonstream/data.py index f548f5bb..aba1ca8b 100644 --- a/backend/moonstream/data.py +++ b/backend/moonstream/data.py @@ -1,10 +1,9 @@ """ Pydantic schemas for the Moonstream HTTP API """ -import uuid from typing import List -from pydantic import BaseModel +from pydantic import BaseModel, Field class PingResponse(BaseModel): @@ -24,13 +23,21 @@ class VersionResponse(BaseModel): class SubscriptionRequest(BaseModel): + """ + Schema for data retrieving from frontend about subscription. + """ + blockchain: str class SubscriptionResponse(BaseModel): + """ + User subscription storing in Bugout resources. + """ + user_id: str blockchain: str class SubscriptionsListResponse(BaseModel): - subscriptions: List[SubscriptionResponse] + subscriptions: List[SubscriptionResponse] = Field(default_factory=list) diff --git a/backend/moonstream/middleware.py b/backend/moonstream/middleware.py index 22454daf..e2a15175 100644 --- a/backend/moonstream/middleware.py +++ b/backend/moonstream/middleware.py @@ -27,6 +27,7 @@ class BroodAuthMiddleware(BaseHTTPMiddleware): async def dispatch( self, request: Request, call_next: Callable[[Request], Awaitable[Response]] ): + # Filter out endpoints with proper method to work without Bearer token (as create_user, login, etc) path = request.url.path.rstrip("/") method = request.method if path in self.whitelist.keys() and self.whitelist[path] == method: diff --git a/backend/moonstream/routes/subscriptions.py b/backend/moonstream/routes/subscriptions.py index bc38e416..22ea4b34 100644 --- a/backend/moonstream/routes/subscriptions.py +++ b/backend/moonstream/routes/subscriptions.py @@ -2,12 +2,11 @@ The Moonstream subscriptions HTTP API """ import logging -from typing import Any, Dict -import uuid +from typing import Dict from bugout.data import BugoutResource, BugoutResources from bugout.exceptions import BugoutResponseException -from fastapi import Body, FastAPI, Form, HTTPException, Request, Query +from fastapi import Body, FastAPI, HTTPException, Request from fastapi.middleware.cors import CORSMiddleware from .. import data @@ -28,8 +27,8 @@ tags_metadata = [ ] app = FastAPI( - title=f"Moonstream API.", - description="The Bugout blockchain inspector API.", + title=f"Moonstream subscriptions API.", + description="User subscriptions endpoints.", version=MOONSTREAM_VERSION, openapi_tags=tags_metadata, openapi_url="/openapi.json", diff --git a/backend/moonstream/routes/users.py b/backend/moonstream/routes/users.py index 63249213..276fcbb1 100644 --- a/backend/moonstream/routes/users.py +++ b/backend/moonstream/routes/users.py @@ -33,8 +33,8 @@ tags_metadata = [ ] app = FastAPI( - title=f"Moonstream API.", - description="The Bugout blockchain inspector API.", + title=f"Moonstream users API.", + description="User, token and password handlers.", version=MOONSTREAM_VERSION, openapi_tags=tags_metadata, openapi_url="/openapi.json", diff --git a/backend/moonstream/settings.py b/backend/moonstream/settings.py index d94a0f31..5d6dfd46 100644 --- a/backend/moonstream/settings.py +++ b/backend/moonstream/settings.py @@ -3,8 +3,7 @@ import os from bugout.app import Bugout # Bugout -# TODO(kompotkot): CHANGE TO PROD!!!!!!! -bugout_client = Bugout("http://127.0.0.1:7474", "http://127.0.0.1:7475") +bugout_client = Bugout() MOONSTREAM_APPLICATION_ID = os.environ.get("MOONSTREAM_APPLICATION_ID") if MOONSTREAM_APPLICATION_ID is None: diff --git a/backend/sample.env b/backend/sample.env index 9b631c8b..8fa5f798 100644 --- a/backend/sample.env +++ b/backend/sample.env @@ -1,4 +1,4 @@ export MOONSTREAM_CORS_ALLOWED_ORIGINS="http://localhost:3000,https://moonstream.to" -export MOONSTREAM_OPENAPI_LIST="subscriptions" +export MOONSTREAM_OPENAPI_LIST="users,subscriptions" export MOONSTREAM_APPLICATION_ID="" export MOONSTREAM_DATA_JOURNAL_ID=""