diff --git a/actor/src/actor_config.py b/actor/src/actor_config.py index 04f570cbe..fad203fc7 100755 --- a/actor/src/actor_config.py +++ b/actor/src/actor_config.py @@ -70,6 +70,8 @@ class UDSConfigDialog(QDialog): self.ui.username.setText('') self.ui.password.setText('') + self.ui.testButton.setEnabled(bool(config.master_token and config.host)) + @property def api(self) -> udsactor.rest.UDSServerApi: return udsactor.rest.UDSServerApi(self.ui.host.text(), self.ui.validateCertificate.currentIndex() == 1) @@ -105,10 +107,40 @@ class UDSConfigDialog(QDialog): def textChanged(self): enableButtons = bool(self.ui.host.text() and self.ui.username.text() and self.ui.password.text() and self.ui.authenticators.currentText()) self.ui.registerButton.setEnabled(enableButtons) + self.ui.testButton.setEnabled(False) # Only registered information can be checked def finish(self): self.close() + def testUDSServer(self): + config: udsactor.types.ActorConfigurationType = udsactor.platform.store.readConfig() + if not config.master_token: + self.ui.testButton.setEnabled(False) + return + try: + api = udsactor.rest.UDSServerApi(config.host, config.validateCertificate) + if not api.test(config.master_token): + QMessageBox.information( + self, + 'UDS Test', + 'Current configured token seems to be invalid for {}. Please, request e new one.'.format(config.host), + QMessageBox.Ok + ) + else: + QMessageBox.information( + self, + 'UDS Test', + 'Configuration for {} seems to be correct.'.format(config.host), + QMessageBox.Ok + ) + except Exception: + QMessageBox.information( + self, + 'UDS Test', + 'Configured host {} seems to be inaccesible.'.format(config.host), + QMessageBox.Ok + ) + def registerWithUDS(self): # Get network card. Will fail if no network card is available, but don't mind (not contempled) data: udsactor.types.InterfaceInfoType = next(udsactor.platform.operations.getNetworkInfo()) @@ -137,9 +169,12 @@ class UDSConfigDialog(QDialog): log_level=self.ui.logLevelComboBox.currentIndex() ) ) - # Inform the user + # Enables test button + self.ui.testButton.setEnabled(True) + # Informs the user QMessageBox.information(self, 'UDS Registration', 'Registration with UDS completed.', QMessageBox.Ok) except udsactor.rest.RESTError as e: + self.ui.testButton.setEnabled(False) QMessageBox.critical(self, 'UDS Registration', 'UDS Registration error: {}'.format(e), QMessageBox.Ok) diff --git a/actor/src/designer/setup-dialog.ui b/actor/src/designer/setup-dialog.ui index e9ce36644..181fef22a 100644 --- a/actor/src/designer/setup-dialog.ui +++ b/actor/src/designer/setup-dialog.ui @@ -66,11 +66,14 @@ 0 + + Qt::DefaultContextMenu + - Click to test the selecter parameters + Click to register Actor with UDS Broker - <html><head/><body><p>Click on this button to test the server host and master key parameters.</p><p>A window will be displayed with results after the test is executed.</p><p><br/></p><p>This button will only be active if all parameters are filled.</p></body></html> + <html><head/><body><p>Click on this button to register Actor with UDS Broker.</p></body></html> Register with UDS @@ -98,10 +101,10 @@ - Cancel all changes and discard them + Closes UDS Actor Configuration (discard pending changes if any) - Discards all changes and closes the configuration window + <html><head/><body><p>Exits the UDS Actor Configuration Tool</p></body></html> Close @@ -117,7 +120,7 @@ - 0 + 1 @@ -170,7 +173,11 @@ - + + + <html><head/><body><p>Select the UDS Broker authenticator for credentials validation</p></body></html> + + @@ -185,7 +192,7 @@ UDS user with administration rights (Will not be stored on template) - <html><head/><body><p>Administrator user on UDS Server.</p><p>Note: This credential will not be stored on client. Will be used to obtain an unique key for this image.</p></body></html> + <html><head/><body><p>Administrator user on UDS Server.</p><p>Note: This credential will not be stored on client. Will be used to obtain an unique token for this image.</p></body></html> @@ -430,6 +437,34 @@ + + + false + + + + 210 + 270 + 181 + 23 + + + + + 181 + 0 + + + + Click to test existing configuration (disabled if no config found) + + + <html><head/><body><p>Click on this button to test the server host and assigned toen.</p></body></html> + + + Test configuration + + @@ -595,6 +630,22 @@ + + testButton + clicked() + UdsActorSetupDialog + testUDSServer() + + + 300 + 281 + + + 294 + 153 + + + textChanged() @@ -604,5 +655,6 @@ browseRunOnce() browsePostConfig() updateAuthenticators() + testUDSServer() diff --git a/actor/src/udsactor/linux/store.py b/actor/src/udsactor/linux/store.py index b7ae8be7e..65a61db8b 100644 --- a/actor/src/udsactor/linux/store.py +++ b/actor/src/udsactor/linux/store.py @@ -58,7 +58,7 @@ def readConfig() -> types.ActorConfigurationType: pre_command=uds.get('pre_command', None), runonce_command=uds.get('runonce_command', None), post_command=uds.get('post_command', None), - log_level=int(uds.get('log_level', '1')), + log_level=int(uds.get('log_level', '3')), config=config, data=data ) diff --git a/actor/src/udsactor/rest.py b/actor/src/udsactor/rest.py index dcbe89a97..b91f6da19 100644 --- a/actor/src/udsactor/rest.py +++ b/actor/src/udsactor/rest.py @@ -101,7 +101,9 @@ class UDSApi: # pylint: disable=too-few-public-methods try: result = requests.post(self._apiURL(method), data=json.dumps(payLoad), headers=headers, verify=self._validateCert) if result.ok: - return result.json()['result'] + j = result.json() + if 'error' not in j: + return j['result'] except requests.ConnectionError as e: raise RESTConnectionError(str(e)) except Exception as e: @@ -114,7 +116,6 @@ class UDSApi: # pylint: disable=too-few-public-methods raise RESTError(data) - # # UDS Broker API access # @@ -270,6 +271,12 @@ class UDSServerApi(UDSApi): } self._doPost('log', payLoad) # Ignores result... + def test(self, master_token: str) -> bool: + payLoad = { + 'token': master_token, + } + return self._doPost('test', payLoad) == 'ok' + class UDSClientApi(UDSApi): def __init__(self) -> None: diff --git a/actor/src/ui/setup_dialog_ui.py b/actor/src/ui/setup_dialog_ui.py index 29c564947..ae8be2ec9 100644 --- a/actor/src/ui/setup_dialog_ui.py +++ b/actor/src/ui/setup_dialog_ui.py @@ -2,12 +2,14 @@ # Form implementation generated from reading ui file 'setup-dialog.ui' # -# Created by: PyQt5 UI code generator 5.11.3 +# Created by: PyQt5 UI code generator 5.13.2 # # WARNING! All changes made in this file will be lost! + from PyQt5 import QtCore, QtGui, QtWidgets + class Ui_UdsActorSetupDialog(object): def setupUi(self, UdsActorSetupDialog): UdsActorSetupDialog.setObjectName("UdsActorSetupDialog") @@ -34,6 +36,7 @@ class Ui_UdsActorSetupDialog(object): self.registerButton.setEnabled(False) self.registerButton.setGeometry(QtCore.QRect(10, 270, 181, 23)) self.registerButton.setMinimumSize(QtCore.QSize(181, 0)) + self.registerButton.setContextMenuPolicy(QtCore.Qt.DefaultContextMenu) self.registerButton.setObjectName("registerButton") self.closeButton = QtWidgets.QPushButton(UdsActorSetupDialog) self.closeButton.setGeometry(QtCore.QRect(410, 270, 171, 23)) @@ -180,9 +183,14 @@ class Ui_UdsActorSetupDialog(object): self.logLevelComboBox.setItemText(3, "FATAL") self.formLayout_2.setWidget(3, QtWidgets.QFormLayout.FieldRole, self.logLevelComboBox) self.tabWidget.addTab(self.tab_advanced, "") + self.testButton = QtWidgets.QPushButton(UdsActorSetupDialog) + self.testButton.setEnabled(False) + self.testButton.setGeometry(QtCore.QRect(210, 270, 181, 23)) + self.testButton.setMinimumSize(QtCore.QSize(181, 0)) + self.testButton.setObjectName("testButton") self.retranslateUi(UdsActorSetupDialog) - self.tabWidget.setCurrentIndex(0) + self.tabWidget.setCurrentIndex(1) self.logLevelComboBox.setCurrentIndex(1) self.closeButton.clicked.connect(UdsActorSetupDialog.finish) self.registerButton.clicked.connect(UdsActorSetupDialog.registerWithUDS) @@ -194,24 +202,26 @@ class Ui_UdsActorSetupDialog(object): self.browseRunOnceButton.clicked.connect(UdsActorSetupDialog.browseRunOnce) self.host.editingFinished.connect(UdsActorSetupDialog.updateAuthenticators) self.authenticators.currentTextChanged['QString'].connect(UdsActorSetupDialog.textChanged) + self.testButton.clicked.connect(UdsActorSetupDialog.testUDSServer) QtCore.QMetaObject.connectSlotsByName(UdsActorSetupDialog) def retranslateUi(self, UdsActorSetupDialog): _translate = QtCore.QCoreApplication.translate UdsActorSetupDialog.setWindowTitle(_translate("UdsActorSetupDialog", "UDS Actor Configuration Tool")) - self.registerButton.setToolTip(_translate("UdsActorSetupDialog", "Click to test the selecter parameters")) - self.registerButton.setWhatsThis(_translate("UdsActorSetupDialog", "

Click on this button to test the server host and master key parameters.

A window will be displayed with results after the test is executed.


This button will only be active if all parameters are filled.

")) + self.registerButton.setToolTip(_translate("UdsActorSetupDialog", "Click to register Actor with UDS Broker")) + self.registerButton.setWhatsThis(_translate("UdsActorSetupDialog", "

Click on this button to register Actor with UDS Broker.

")) self.registerButton.setText(_translate("UdsActorSetupDialog", "Register with UDS")) - self.closeButton.setToolTip(_translate("UdsActorSetupDialog", "Cancel all changes and discard them")) - self.closeButton.setWhatsThis(_translate("UdsActorSetupDialog", "Discards all changes and closes the configuration window")) + self.closeButton.setToolTip(_translate("UdsActorSetupDialog", "Closes UDS Actor Configuration (discard pending changes if any)")) + self.closeButton.setWhatsThis(_translate("UdsActorSetupDialog", "

Exits the UDS Actor Configuration Tool

")) self.closeButton.setText(_translate("UdsActorSetupDialog", "Close")) self.label_host.setText(_translate("UdsActorSetupDialog", "UDS Server")) self.host.setToolTip(_translate("UdsActorSetupDialog", "Uds Broker Server Addres. Use IP or FQDN")) self.host.setWhatsThis(_translate("UdsActorSetupDialog", "Enter here the UDS Broker Addres using either its IP address or its FQDN address")) self.label_auth.setText(_translate("UdsActorSetupDialog", "Authenticator")) + self.authenticators.setWhatsThis(_translate("UdsActorSetupDialog", "

Select the UDS Broker authenticator for credentials validation

")) self.label_username.setText(_translate("UdsActorSetupDialog", "Username")) self.username.setToolTip(_translate("UdsActorSetupDialog", "UDS user with administration rights (Will not be stored on template)")) - self.username.setWhatsThis(_translate("UdsActorSetupDialog", "

Administrator user on UDS Server.

Note: This credential will not be stored on client. Will be used to obtain an unique key for this image.

")) + self.username.setWhatsThis(_translate("UdsActorSetupDialog", "

Administrator user on UDS Server.

Note: This credential will not be stored on client. Will be used to obtain an unique token for this image.

")) self.label_password.setText(_translate("UdsActorSetupDialog", "Password")) self.password.setToolTip(_translate("UdsActorSetupDialog", "Password for user (Will not be stored on template)")) self.password.setWhatsThis(_translate("UdsActorSetupDialog", "

Administrator password for the user on UDS Server.

Note: This credential will not be stored on client. Will be used to obtain an unique key for this image.

")) @@ -232,5 +242,7 @@ class Ui_UdsActorSetupDialog(object): self.browsePostConfigButton.setText(_translate("UdsActorSetupDialog", "Browse")) self.label_loglevel.setText(_translate("UdsActorSetupDialog", "Log Level")) self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_advanced), _translate("UdsActorSetupDialog", "Advanced")) - + self.testButton.setToolTip(_translate("UdsActorSetupDialog", "Click to test existing configuration (disabled if no config found)")) + self.testButton.setWhatsThis(_translate("UdsActorSetupDialog", "

Click on this button to test the server host and assigned toen.

")) + self.testButton.setText(_translate("UdsActorSetupDialog", "Test configuration")) from ui import uds_rc diff --git a/actor/src/ui/uds_rc.py b/actor/src/ui/uds_rc.py index f6679c9fb..26d1f8e74 100644 --- a/actor/src/ui/uds_rc.py +++ b/actor/src/ui/uds_rc.py @@ -2,7 +2,7 @@ # Resource object code # -# Created by: The Resource Compiler for PyQt5 (Qt v5.11.3) +# Created by: The Resource Compiler for PyQt5 (Qt v5.13.2) # # WARNING! All changes made in this file will be lost!