forked from shaba/openuds
Added test configuration for uds actor & fixed some texts
This commit is contained in:
parent
3e905381ff
commit
7483a6f04f
@ -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)
|
||||
|
||||
|
||||
|
@ -66,11 +66,14 @@
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="contextMenuPolicy">
|
||||
<enum>Qt::DefaultContextMenu</enum>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Click to test the selecter parameters</string>
|
||||
<string>Click to register Actor with UDS Broker</string>
|
||||
</property>
|
||||
<property name="whatsThis">
|
||||
<string><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></string>
|
||||
<string><html><head/><body><p>Click on this button to register Actor with UDS Broker.</p></body></html></string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Register with UDS</string>
|
||||
@ -98,10 +101,10 @@
|
||||
</size>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Cancel all changes and discard them</string>
|
||||
<string>Closes UDS Actor Configuration (discard pending changes if any)</string>
|
||||
</property>
|
||||
<property name="whatsThis">
|
||||
<string>Discards all changes and closes the configuration window</string>
|
||||
<string><html><head/><body><p>Exits the UDS Actor Configuration Tool</p></body></html></string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Close</string>
|
||||
@ -117,7 +120,7 @@
|
||||
</rect>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
<number>1</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="tab_uds">
|
||||
<attribute name="title">
|
||||
@ -170,7 +173,11 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QComboBox" name="authenticators"/>
|
||||
<widget class="QComboBox" name="authenticators">
|
||||
<property name="whatsThis">
|
||||
<string><html><head/><body><p>Select the UDS Broker authenticator for credentials validation</p></body></html></string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_username">
|
||||
@ -185,7 +192,7 @@
|
||||
<string>UDS user with administration rights (Will not be stored on template)</string>
|
||||
</property>
|
||||
<property name="whatsThis">
|
||||
<string><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></string>
|
||||
<string><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></string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -430,6 +437,34 @@
|
||||
</widget>
|
||||
</widget>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="testButton">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>210</x>
|
||||
<y>270</y>
|
||||
<width>181</width>
|
||||
<height>23</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>181</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Click to test existing configuration (disabled if no config found)</string>
|
||||
</property>
|
||||
<property name="whatsThis">
|
||||
<string><html><head/><body><p>Click on this button to test the server host and assigned toen.</p></body></html></string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Test configuration</string>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="uds.qrc"/>
|
||||
@ -595,6 +630,22 @@
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>testButton</sender>
|
||||
<signal>clicked()</signal>
|
||||
<receiver>UdsActorSetupDialog</receiver>
|
||||
<slot>testUDSServer()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>300</x>
|
||||
<y>281</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>294</x>
|
||||
<y>153</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
<slots>
|
||||
<slot>textChanged()</slot>
|
||||
@ -604,5 +655,6 @@
|
||||
<slot>browseRunOnce()</slot>
|
||||
<slot>browsePostConfig()</slot>
|
||||
<slot>updateAuthenticators()</slot>
|
||||
<slot>testUDSServer()</slot>
|
||||
</slots>
|
||||
</ui>
|
||||
|
@ -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
|
||||
)
|
||||
|
@ -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:
|
||||
|
@ -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", "<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>"))
|
||||
self.registerButton.setToolTip(_translate("UdsActorSetupDialog", "Click to register Actor with UDS Broker"))
|
||||
self.registerButton.setWhatsThis(_translate("UdsActorSetupDialog", "<html><head/><body><p>Click on this button to register Actor with UDS Broker.</p></body></html>"))
|
||||
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", "<html><head/><body><p>Exits the UDS Actor Configuration Tool</p></body></html>"))
|
||||
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", "<html><head/><body><p>Select the UDS Broker authenticator for credentials validation</p></body></html>"))
|
||||
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", "<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>"))
|
||||
self.username.setWhatsThis(_translate("UdsActorSetupDialog", "<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>"))
|
||||
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", "<html><head/><body><p>Administrator password for the 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>"))
|
||||
@ -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", "<html><head/><body><p>Click on this button to test the server host and assigned toen.</p></body></html>"))
|
||||
self.testButton.setText(_translate("UdsActorSetupDialog", "Test configuration"))
|
||||
from ui import uds_rc
|
||||
|
@ -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!
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user