Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions framework/python/src/api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
DEVICE_FOLDER_PATH = "devices"
DEVICE_TYPES_FILE_NAME = "types.json"
DEVICE_TECHS_FILE_NAME = "technologies.json"
DEVICE_QUESTIONS_FILE_NAME = "device_profile.json"

LATEST_RELEASE_CHECK = ("https://api.github.com/repos/google/" +
"testrun/releases/latest")
Expand All @@ -68,6 +69,9 @@ def __init__(self, testrun):
# Load device technologies list
self._device_techs = self._load_json(device_resources,
DEVICE_TECHS_FILE_NAME)
# Load device profile questions
self._device_profile = self._load_json(device_resources,
DEVICE_QUESTIONS_FILE_NAME)

# Fetch Testrun session
self._session = self._testrun.get_session()
Expand Down Expand Up @@ -111,10 +115,7 @@ def __init__(self, testrun):
self._router.add_api_route("/device/edit",
self.edit_device,
methods=["POST"])
self._router.add_api_route("/devices/types",
self.get_device_types)
self._router.add_api_route("/devices/technology",
self.get_device_technologies)
self._router.add_api_route("/devices/format", self.get_devices_profile)

# Certificate endpoints
self._router.add_api_route("/system/config/certs", self.get_certs)
Expand Down Expand Up @@ -686,6 +687,25 @@ async def get_device_types(self):
async def get_device_technologies(self):
return self._device_techs

async def get_devices_profile(self,
request: Request,
response: Response,
step: int = 1):
"""Device profile questions"""

all_steps = len(self._device_profile)

try:
questions = self._device_profile[step-1]
if step < all_steps:
questions["next_step"] = f"{request.url.path}?step={step + 1}"
return questions

except IndexError:
response.status_code = status.HTTP_404_NOT_FOUND
return self._generate_msg(
False, f"Step {step} does not exist.")

def _validate_device_json(self, json_obj):

# Check all required properties are present
Expand Down
Loading