kopia lustrzana https://github.com/bugout-dev/moonstream
Fixed issues, todos, added comments
rodzic
15aae10874
commit
f0dbb640f1
|
@ -1,2 +0,0 @@
|
|||
|
||||
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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="<issued_bugout_application_id>"
|
||||
export MOONSTREAM_DATA_JOURNAL_ID="<bugout_journal_id_to_store_blockchain_data>"
|
||||
|
|
Ładowanie…
Reference in New Issue