Skip to content

Commit b2c6764

Browse files
Minor improvements (#197)
* Low resolution icons improved * Removed unneeded validation at configure web interfacedialog initialization * Introduced basic check to verify pem key and certificate file content * improved camera to actuator association tree view * addressed PR comments * version increased
1 parent c8875f0 commit b2c6764

File tree

8 files changed

+67
-3
lines changed

8 files changed

+67
-3
lines changed

wadas/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@
1717
# Date: 2024-08-14
1818
# Description: module to keep track of WADAS version
1919

20-
__version__ = "v1.0.0.a4"
20+
__version__ = "v1.0.0.a5"
2121
__dbversion__ = __version__

wadas/domain/utils.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
import uuid
2727
from logging.handlers import RotatingFileHandler
2828

29+
from cryptography import x509
30+
from cryptography.hazmat.backends import default_backend
31+
from cryptography.hazmat.primitives import serialization
32+
2933

3034
def get_timestamp():
3135
"""Method to prepare timestamp string to apply to images naming"""
@@ -120,3 +124,35 @@ def send_data_on_local_socket(port, command):
120124
return data
121125
finally:
122126
client_socket.close()
127+
128+
129+
def is_pem_key(
130+
pem_key_file: str,
131+
password: bytes | None = None,
132+
) -> bool:
133+
"""Method to validate pem key file content."""
134+
135+
try:
136+
with open(pem_key_file, "rb") as f:
137+
serialization.load_pem_private_key(
138+
f.read(),
139+
password=password,
140+
backend=default_backend(),
141+
)
142+
return True
143+
except Exception:
144+
return False
145+
146+
147+
def is_pem_certificate(pem_certificate_file) -> bool:
148+
"""Method to validate pem certificate file content."""
149+
150+
try:
151+
with open(pem_certificate_file, "rb") as f:
152+
x509.load_pem_x509_certificate(
153+
f.read(),
154+
backend=default_backend(),
155+
)
156+
return True
157+
except Exception:
158+
return False

wadas/icons/icon-actuator-24.png

18.4 KB
Loading

wadas/icons/icon-ai-24.png

9.94 KB
Loading

wadas/ui/configure_actuators_dialog.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
from wadas.domain.fastapi_actuator_server import FastAPIActuatorServer, initialize_fastapi_logger
2727
from wadas.domain.feeder_actuator import FeederActuator
2828
from wadas.domain.roadsign_actuator import RoadSignActuator
29+
from wadas.domain.utils import is_pem_certificate, is_pem_key
30+
from wadas.ui.error_message_dialog import WADASErrorMessage
2931
from wadas.ui.qt.ui_configure_actuators import Ui_DialogConfigureActuators
3032
from wadas.ui.qtextedit_logger import QTextEditLogger
3133

@@ -254,6 +256,12 @@ def select_key_file(self):
254256
self, "Open SSL key file", os.getcwd(), "Pem File (*.pem)"
255257
)
256258
self.ui.label_key_file.setText(str(file_name[0]))
259+
260+
# Verify key file
261+
if not is_pem_key(file_name[0]):
262+
WADASErrorMessage("Invalid key file provided",
263+
f"Error while loading key file. Please make sure selected file is a valid one.").exec()
264+
257265
self.validate()
258266

259267
def select_certificate_file(self):
@@ -263,6 +271,11 @@ def select_certificate_file(self):
263271
self, "Open SSL certificate file", os.getcwd(), "Pem File (*.pem)"
264272
)
265273
self.ui.label_cert_file.setText(str(file_name[0]))
274+
275+
if not is_pem_certificate(file_name[0]):
276+
WADASErrorMessage("Invalid certificate file provided",
277+
f"Error while loading certificate file. Please make sure selected file is a valid one").exec()
278+
266279
self.validate()
267280

268281
def get_actuator_id(self, row):

wadas/ui/configure_camera_actuator_associations_dialog.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ def __init__(self):
5252
# Set the model to the QTreeView
5353
self.ui.treeView.setModel(self.model)
5454

55+
# Expand all items by default
56+
self.ui.treeView.expandAll()
57+
5558
# Signal
5659
self.ui.treeView.doubleClicked.connect(self.handle_double_click)
5760
self.ui.pushButton_close.clicked.connect(self.accept_and_close)
@@ -72,6 +75,7 @@ def handle_double_click(self, index):
7275
dialog.exec()
7376
# Refresh the camera item in the tree view after editing actuators
7477
self.populate_model()
78+
self.ui.treeView.expandAll()
7579

7680
def populate_model(self):
7781

wadas/ui/configure_ftp_cameras_dialog.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
from wadas.domain.database import DataBase
4343
from wadas.domain.ftp_camera import FTPCamera
4444
from wadas.domain.ftps_server import FTPsServer
45+
from wadas.domain.utils import is_pem_certificate, is_pem_key
46+
from wadas.ui.error_message_dialog import WADASErrorMessage
4547
from wadas.ui.qt.ui_configure_ftp_cameras import Ui_DialogFTPCameras
4648
from wadas.ui.qtextedit_logger import QTextEditLogger
4749

@@ -328,6 +330,12 @@ def select_key_file(self):
328330
self, "Open SSL key file", os.getcwd(), "Pem File (*.pem)"
329331
)
330332
self.ui.label_key_file_path.setText(str(file_name[0]))
333+
334+
# Verify key file
335+
if not is_pem_key(file_name[0]):
336+
WADASErrorMessage("Invalid key file provided",
337+
f"Error while loading key file. Please make sure selected file is a valid one.").exec()
338+
331339
self.validate()
332340

333341
def select_certificate_file(self):
@@ -337,6 +345,11 @@ def select_certificate_file(self):
337345
self, "Open SSL certificate file", os.getcwd(), "Pem File (*.pem)"
338346
)
339347
self.ui.label_certificate_file_path.setText(str(file_name[0]))
348+
349+
if not is_pem_certificate(file_name[0]):
350+
WADASErrorMessage("Invalid certificate file provided",
351+
f"Error while loading certificate file. Please make sure selected file is a valid one").exec()
352+
340353
self.validate()
341354

342355
def select_ftp_folder(self):

wadas/ui/configure_web_interface.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,6 @@ def initialize_dialog(self):
163163
role_cb = self.findChild(QComboBox, f"comboBox_role_{i}")
164164
role_txt = role if role in self.roles else "Viewer"
165165
role_cb.setCurrentText(role_txt)
166-
167-
self.validate()
168166
else:
169167
self.findChild(QLineEdit, "lineEdit_user_0").setEnabled(False)
170168
self.findChild(QLineEdit, "lineEdit_password_0").setEnabled(False)

0 commit comments

Comments
 (0)