Move models to apimodels
This commit is contained in:
parent
6594278509
commit
86d0700884
@ -1,4 +1,3 @@
|
||||
from freqtrade.rpc.api_server2.models import AccessAndRefreshToken, AccessToken
|
||||
import secrets
|
||||
from typing import Optional
|
||||
|
||||
@ -8,6 +7,8 @@ from fastapi.security.utils import get_authorization_scheme_param
|
||||
from fastapi_jwt_auth import AuthJWT
|
||||
from pydantic import BaseModel
|
||||
|
||||
from freqtrade.rpc.api_server2.api_models import AccessAndRefreshToken, AccessToken
|
||||
|
||||
from .deps import get_config
|
||||
|
||||
|
||||
@ -41,7 +42,7 @@ class HTTPBasicOrJWTToken(HTTPBasic):
|
||||
header_authorization: str = request.headers.get("Authorization")
|
||||
header_scheme, header_param = get_authorization_scheme_param(header_authorization)
|
||||
if header_scheme.lower() == 'bearer':
|
||||
AuthJWT.jwt_required()
|
||||
AuthJWT(request).jwt_required()
|
||||
elif header_scheme.lower() == 'basic':
|
||||
credentials: Optional[HTTPBasicCredentials] = await HTTPBasic()(request)
|
||||
if credentials and verify_auth(config, credentials.username, credentials.password):
|
||||
@ -49,7 +50,6 @@ class HTTPBasicOrJWTToken(HTTPBasic):
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
detail="Incorrect username or password",
|
||||
headers={"WWW-Authenticate": "Basic"},
|
||||
)
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
from typing import List
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
@ -18,6 +19,10 @@ class Version(BaseModel):
|
||||
version: str
|
||||
|
||||
|
||||
class StatusMsg(BaseModel):
|
||||
status: str
|
||||
|
||||
|
||||
class Balance(BaseModel):
|
||||
currency: str
|
||||
free: float
|
@ -1,9 +1,10 @@
|
||||
from freqtrade.rpc import RPC
|
||||
from fastapi import APIRouter, Depends
|
||||
|
||||
from freqtrade import __version__
|
||||
|
||||
from .api_models import Balances, Ping, StatusMsg, Version
|
||||
from .deps import get_config, get_rpc
|
||||
from .models import Balances, Ping, Version
|
||||
|
||||
|
||||
# Public API, requires no auth.
|
||||
@ -18,13 +19,21 @@ def ping():
|
||||
return {"status": "pong"}
|
||||
|
||||
|
||||
@router.get('/version', response_model=Version)
|
||||
@router.get('/version', response_model=Version, tags=['info'])
|
||||
def version():
|
||||
return {"version": __version__}
|
||||
|
||||
|
||||
@router.get('/balance', response_model=Balances)
|
||||
def balance(rpc=Depends(get_rpc), config=Depends(get_config)):
|
||||
@router.get('/balance', response_model=Balances, tags=['info'])
|
||||
def balance(rpc: RPC = Depends(get_rpc), config=Depends(get_config)):
|
||||
return rpc._rpc_balance(config['stake_currency'], config.get('fiat_display_currency', ''),)
|
||||
|
||||
|
||||
@router.post('/start', response_model=StatusMsg, tags=['botcontrol'])
|
||||
def start(rpc: RPC = Depends(get_rpc)):
|
||||
return rpc._rpc_start()
|
||||
|
||||
|
||||
@router.post('/stop', response_model=StatusMsg, tags=['botcontrol'])
|
||||
def stop(rpc: RPC = Depends(get_rpc)):
|
||||
return rpc._rpc_stop()
|
||||
|
@ -1,6 +1,7 @@
|
||||
import contextlib
|
||||
import time
|
||||
import threading
|
||||
import time
|
||||
|
||||
import uvicorn
|
||||
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
from typing import Any, Dict, Optional
|
||||
|
||||
import uvicorn
|
||||
from fastapi import Depends, FastAPI
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
@ -36,7 +37,7 @@ class ApiServer(RPCHandler):
|
||||
def configure_app(self, app: FastAPI, config):
|
||||
from .api_v1 import router as api_v1
|
||||
from .api_v1 import router_public as api_v1_public
|
||||
from .auth import router_login, HTTPBasicOrJWTToken
|
||||
from .api_auth import HTTPBasicOrJWTToken, router_login
|
||||
app.include_router(api_v1_public, prefix="/api/v1")
|
||||
|
||||
app.include_router(api_v1, prefix="/api/v1",
|
||||
|
Loading…
Reference in New Issue
Block a user