Browse Source

add support for passing through the ssh pub key...

main
John-Mark Gurney 4 years ago
parent
commit
091ab57575
1 changed files with 17 additions and 5 deletions
  1. +17
    -5
      bitelab/__init__.py

+ 17
- 5
bitelab/__init__.py View File

@@ -31,7 +31,7 @@ from dataclasses import dataclass
from functools import lru_cache, wraps
from io import StringIO

from fastapi import APIRouter, Depends, FastAPI, HTTPException, Request
from fastapi import APIRouter, Body, Depends, FastAPI, HTTPException, Request
from fastapi.security import OAuth2PasswordBearer
from httpx import AsyncClient, Auth
from starlette.responses import JSONResponse
@@ -309,10 +309,16 @@ async def get_board_info(board_id, user: str = Depends(lookup_user),
return brd

@router.post('/board/{board_id_or_class}/reserve', response_model=Union[Board, Error])
async def reserve_board(board_id_or_class, user: str = Depends(lookup_user),
async def reserve_board(board_id_or_class,
req: Request,
user: str = Depends(lookup_user),
brdmgr: BoardManager = Depends(get_boardmanager),
settings: config.Settings = Depends(get_settings),
sshpubkey: str = Body(embed=True, default=None,
title='Default public ssh key to install.'),
data: data.DataWrapper = Depends(get_data)):

#print('reserve:', repr(sshpubkey), repr(await req.body()))
board_id = board_id_or_class
brd = brdmgr.boards[board_id]

@@ -338,8 +344,11 @@ async def reserve_board(board_id_or_class, user: str = Depends(lookup_user),

# Initialize board
try:
sub = await asyncio.create_subprocess_exec(
settings.setup_script, 'reserve', brd.name, user,
args = ( settings.setup_script, 'reserve',
brd.name, user, )
if sshpubkey is not None:
args += (sshpubkey, )
sub = await asyncio.create_subprocess_exec(*args,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = await sub.communicate()
if sub.returncode:
@@ -650,8 +659,11 @@ class TestBiteLab(unittest.IsolatedAsyncioTestCase):
devfsrule='14',
)).encode('utf-8'))

keydata = 'pubsshkey'

# that reserving the board
res = await self.client.post('/board/cora-1/reserve',
json=dict(sshpubkey=keydata),
auth=BiteAuth('thisisanapikey'))

# that it is successful
@@ -671,7 +683,7 @@ class TestBiteLab(unittest.IsolatedAsyncioTestCase):

# and that it called the start script
cse.assert_called_with(self.settings.setup_script, 'reserve',
'cora-1', 'foo', stdout=subprocess.PIPE, stderr=subprocess.PIPE)
'cora-1', 'foo', 'pubsshkey', stdout=subprocess.PIPE, stderr=subprocess.PIPE)

# that another user reserving the board
res = await self.client.post('/board/cora-1/reserve',


Loading…
Cancel
Save