diff --git a/framework/python/src/api/api.py b/framework/python/src/api/api.py index f97e564d3..f3a778e13 100644 --- a/framework/python/src/api/api.py +++ b/framework/python/src/api/api.py @@ -103,6 +103,10 @@ def __init__(self, test_run): self.edit_device, methods=["POST"]) + # Load modules + self._router.add_api_route("/system/modules", + self.get_test_modules) + self._router.add_api_route("/system/config/certs", self.get_certs) self._router.add_api_route("/system/config/certs", @@ -112,6 +116,10 @@ def __init__(self, test_run): self.delete_cert, methods=["DELETE"]) + # Profiles + self._router.add_api_route("/profiles/format", + self._get_profiles_format) + # Allow all origins to access the API origins = ["*"] @@ -143,6 +151,9 @@ def _start(self): def stop(self): LOGGER.info("Stopping API") + def get_session(self): + return self._session + async def get_sys_interfaces(self): addrs = psutil.net_if_addrs() ifaces = {} @@ -597,6 +608,22 @@ def _validate_device_json(self, json_obj): return True + def _get_test_run(self): + return self._test_run + + # Profiles + def _get_profiles_format(self, response: Response): + + # Check if Testrun was able to load the format originally + if self.get_session().get_profiles_format() is None: + response.status_code = status.HTTP_500_INTERNAL_SERVER_ERROR + return self._generate_msg( + False, + "Testrun could not load the risk assessment format") + + return self.get_session().get_profiles_format() + + # Certificates def get_certs(self): LOGGER.debug("Received certs list request") @@ -687,3 +714,10 @@ async def delete_cert(self, request: Request, response: Response): except Exception as e: LOGGER.error("An error occurred whilst deleting a certificate") LOGGER.debug(e) + + def get_test_modules(self): + modules = [] + for module in self._test_run.get_test_orc().get_test_modules(): + if module.enabled and module.enable_container: + modules.append(module.display_name) + return modules diff --git a/framework/python/src/common/session.py b/framework/python/src/common/session.py index bce74754e..c762df03c 100644 --- a/framework/python/src/common/session.py +++ b/framework/python/src/common/session.py @@ -39,12 +39,15 @@ PROFILE_FORMAT_PATH = 'resources/risk_assessment.json' PROFILES_DIR = 'local/profiles' +PROFILE_FORMAT_PATH = 'resources/risk_assessment.json' +PROFILES_DIR = 'local/profiles' + LOGGER = logger.get_logger('session') class TestrunSession(): """Represents the current session of Test Run.""" - def __init__(self, root_dir, version): + def __init__(self, root_dir): self._root_dir = root_dir self._status = 'Idle' @@ -83,7 +86,7 @@ def __init__(self, root_dir, version): self._config = self._get_default_config() # Loading methods - self._load_version(default_version=version) + self._load_version() self._load_config() self._load_profiles() @@ -179,7 +182,7 @@ def _load_config(self): LOGGER.debug(self._config) - def _load_version(self, default_version): + def _load_version(self): version_cmd = util.run_command( 'dpkg-query --showformat=\'${Version}\' --show testrun') # index 1 of response is the stderr byte stream so if @@ -189,7 +192,7 @@ def _load_version(self, default_version): version = version_cmd[0] self._version = version else: - self._version = default_version + self._version = 'Unknown' LOGGER.info(f'Running Testrun version {self._version}') def get_version(self): diff --git a/framework/python/src/core/testrun.py b/framework/python/src/core/testrun.py index c8973fc6a..cba479517 100644 --- a/framework/python/src/core/testrun.py +++ b/framework/python/src/core/testrun.py @@ -89,8 +89,7 @@ def __init__(self, self._register_exits() # Create session - self._session = TestrunSession(root_dir=root_dir, - version=self.get_version()) + self._session = TestrunSession(root_dir=root_dir) # Register runtime parameters if single_intf: diff --git a/resources/risk_assessment.json b/resources/risk_assessment.json index 25f0f6888..e341dd904 100644 --- a/resources/risk_assessment.json +++ b/resources/risk_assessment.json @@ -14,7 +14,7 @@ }, { "question": "How will this device be used at Google?", - "type": "text", + "type": "text-long", "validation": { "max": "128", "required": true @@ -22,7 +22,7 @@ }, { "question": "What is the email of the device owner(s)?", - "type": "text", + "type": "email-multiple", "validation": { "required": true, "max": "128"