Compare commits
No commits in common. "6f998a3c584a59511c55cce305775fff7ed6d441" and "7780f247fb6519976baa8d9840b59d1f15cb3395" have entirely different histories.
6f998a3c58
...
7780f247fb
|
@ -24,7 +24,7 @@ async def call(
|
|||
) -> Coroutine[Any, Any, Any | None]:
|
||||
try:
|
||||
cp = __active_connections[chargepoint_id]
|
||||
return await cp.call(payload, suppress, unique_id)
|
||||
return cp.call(payload, suppress, unique_id)
|
||||
except KeyError as e:
|
||||
raise e
|
||||
|
||||
|
|
|
@ -5,19 +5,9 @@ from fastapi import APIRouter, HTTPException, Security
|
|||
from fastapi.params import Depends
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from ocpp.v201.call import ResetPayload
|
||||
|
||||
from app.database import get_db
|
||||
from app.ocpp_proto import chargepoint_manager
|
||||
from app.schemas.chargepoint import (
|
||||
ChargePoint,
|
||||
ChargePointCreate,
|
||||
ChargePointUpdate,
|
||||
ChargePointPassword,
|
||||
ChargePointConnectionInfo,
|
||||
ChargePointResetRequest,
|
||||
ChargePointResetResponse
|
||||
)
|
||||
from app.schemas.chargepoint import ChargePoint, ChargePointCreate, ChargePointUpdate, ChargePointPassword, ChargePointConnectionInfo
|
||||
from app.models.chargepoint import ChargePoint as DbChargePoint
|
||||
from app.security import get_api_key
|
||||
|
||||
|
@ -122,17 +112,3 @@ async def get_chargepoint_status(
|
|||
return ChargePointConnectionInfo(
|
||||
connected=chargepoint_manager.is_connected(chargepoint_id)
|
||||
)
|
||||
|
||||
@router.post(path="/{chargepoint_id}/reset", response_model=ChargePointResetResponse)
|
||||
async def reset_chargepoint(
|
||||
chargepoint_id: UUID,
|
||||
reset_request: ChargePointResetRequest,
|
||||
api_key: str = Security(get_api_key)
|
||||
):
|
||||
if chargepoint_manager.is_connected(chargepoint_id) == False:
|
||||
raise HTTPException(status_code=423, detail="Chargepoint not connected")
|
||||
response = await chargepoint_manager.call(
|
||||
chargepoint_id,
|
||||
payload=ResetPayload(type=reset_request.type, evse_id=reset_request.evse_id)
|
||||
)
|
||||
return ChargePointResetResponse(status=response.status)
|
||||
|
|
|
@ -5,8 +5,6 @@ from pydantic import BaseModel
|
|||
|
||||
from app.schemas.connector import Connector
|
||||
|
||||
from ocpp.v201.enums import ResetType, ResetStatusType
|
||||
|
||||
class ChargePointBase(BaseModel):
|
||||
friendly_name: str
|
||||
is_active: bool
|
||||
|
@ -35,10 +33,3 @@ class ChargePointPassword(BaseModel):
|
|||
|
||||
class ChargePointConnectionInfo(BaseModel):
|
||||
connected: bool
|
||||
|
||||
class ChargePointResetRequest(BaseModel):
|
||||
type: ResetType
|
||||
evse_id: Optional[int] = None
|
||||
|
||||
class ChargePointResetResponse(BaseModel):
|
||||
status: ResetStatusType
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import base64
|
||||
import binascii
|
||||
from uuid import UUID
|
||||
from starlette.authentication import (
|
||||
AuthCredentials, AuthenticationBackend, AuthenticationError, SimpleUser
|
||||
)
|
||||
|
@ -22,9 +23,13 @@ class BasicAuthBackend(AuthenticationBackend):
|
|||
raise AuthenticationError('Invalid basic auth credentials')
|
||||
|
||||
username, _, password = decoded.partition(":")
|
||||
try:
|
||||
id = UUID(username)
|
||||
except (ValueError) as exc:
|
||||
raise AuthenticationError('Invalid basic auth credentials')
|
||||
|
||||
with SessionLocal() as db:
|
||||
chargepoint = db.query(ChargePoint).filter(ChargePoint.friendly_name == username).first()
|
||||
chargepoint = db.query(ChargePoint).filter(ChargePoint.id == id).first()
|
||||
if chargepoint is None:
|
||||
raise AuthenticationError('Invalid basic auth credentials')
|
||||
if chargepoint.password != password:
|
||||
|
|
Loading…
Reference in a new issue