-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'PLAT-276-add-oem-mode-endpoint' into oem-mode-integration
- Loading branch information
Showing
10 changed files
with
156 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
"""system_server.settings: Provides an interface to get server settings.""" | ||
|
||
from .settings import get_settings, SystemServerSettings | ||
from .settings import ( | ||
save_settings, | ||
get_settings, | ||
SystemServerSettings, | ||
) | ||
|
||
|
||
__all__ = ["get_settings", "SystemServerSettings"] | ||
__all__ = ["save_settings", "get_settings", "SystemServerSettings"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
"""OEM Mode endpoint.""" | ||
|
||
from .router import oem_mode_router | ||
|
||
__all__ = ["oem_mode_router"] |
21 changes: 21 additions & 0 deletions
21
system-server/system_server/system/oem_mode/dependencies.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
"""Dependencies for /system/register endpoints.""" | ||
from system_server.jwt import Registrant | ||
from fastapi import Query | ||
|
||
|
||
def create_registrant( | ||
subject: str = Query( | ||
..., description="Identifies the human intending to register with the robot" | ||
), | ||
agent: str = Query(..., description="Identifies the app type making the request"), | ||
agentId: str = Query( | ||
..., description="A unique identifier for the instance of the agent" | ||
), | ||
) -> Registrant: | ||
"""Define a unique Registrant to create a registration token for. | ||
A registrant is defined by a set of unique identifiers that remain | ||
persistent indefinitely for the same person using the same method of | ||
access to the system. | ||
""" | ||
return Registrant(subject=subject, agent=agent, agent_id=agentId) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
"""Models for /system/oem_mode.""" | ||
|
||
from pydantic import BaseModel, Field | ||
|
||
|
||
class EnableOEMMode(BaseModel): | ||
"""Enable OEM Mode model.""" | ||
|
||
enable: bool = Field(..., description="Enable or Disable OEM Mode.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
"""Router for /system/register endpoint.""" | ||
|
||
from fastapi import APIRouter, Depends, status, Response | ||
from .models import EnableOEMMode | ||
from ...settings import SystemServerSettings, get_settings, save_settings | ||
|
||
|
||
oem_mode_router = APIRouter() | ||
|
||
|
||
@oem_mode_router.put( | ||
"/system/oem_mode/enable", | ||
summary="Enable or Disable OEM Mode for this robot.", | ||
responses={ | ||
status.HTTP_200_OK: {"message": "OEM Mode changed successfully."}, | ||
status.HTTP_400_BAD_REQUEST: {"message": "OEM Mode did not changed."}, | ||
status.HTTP_500_INTERNAL_SERVER_ERROR: { | ||
"message": "OEM Mode unhandled exception." | ||
}, | ||
}, | ||
) | ||
async def enable_oem_mode_endpoint( | ||
response: Response, | ||
enableRequest: EnableOEMMode, | ||
settings: SystemServerSettings = Depends(get_settings), | ||
) -> Response: | ||
"""Router for /system/oem_mode/enable endpoint.""" | ||
|
||
enable = enableRequest.enable | ||
try: | ||
settings.oem_mode_enabled = enable | ||
success = save_settings(settings) | ||
response.status_code = ( | ||
status.HTTP_200_OK if success else status.HTTP_400_BAD_REQUEST | ||
) | ||
except Exception: | ||
response.status_code = status.HTTP_500_INTERNAL_SERVER_ERROR | ||
return response |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters