Refactor ip APIs
This commit is contained in:
@ -10,6 +10,15 @@ router = APIRouter()
|
|||||||
|
|
||||||
@router.get('/add')
|
@router.get('/add')
|
||||||
async def add_ip_api():
|
async def add_ip_api():
|
||||||
|
"""
|
||||||
|
Adds the auto-detected IP addresses to the .configs.env file.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
A DetailResponse with a message indicating the IP addresses were added successfully.
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
HTTPException: if an error occurs while adding the IP addresses.
|
||||||
|
"""
|
||||||
try:
|
try:
|
||||||
cli_api.add_ip_address()
|
cli_api.add_ip_address()
|
||||||
return DetailResponse(detail='IP addresses added successfully.')
|
return DetailResponse(detail='IP addresses added successfully.')
|
||||||
@ -19,6 +28,18 @@ async def add_ip_api():
|
|||||||
|
|
||||||
@router.post('/edit', response_model=DetailResponse)
|
@router.post('/edit', response_model=DetailResponse)
|
||||||
async def edit_ip_api(body: EditInputBody):
|
async def edit_ip_api(body: EditInputBody):
|
||||||
|
"""
|
||||||
|
Edits the IP addresses in the .configs.env file.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
body: An instance of EditInputBody containing the new IPv4 and/or IPv6 addresses.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
A DetailResponse with a message indicating the IP addresses were edited successfully.
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
HTTPException: if an error occurs while editing the IP addresses.
|
||||||
|
"""
|
||||||
try:
|
try:
|
||||||
if not body.ipv4 and not body.ipv6:
|
if not body.ipv4 and not body.ipv6:
|
||||||
raise HTTPException(status_code=400, detail='Error: You must specify either ipv4 or ipv6')
|
raise HTTPException(status_code=400, detail='Error: You must specify either ipv4 or ipv6')
|
||||||
|
|||||||
Reference in New Issue
Block a user