Skip to content

Commit 552279a

Browse files
committed
worflow fix
Signed-off-by: PritamP20 <pripritam7@gmail.com>
1 parent 4cdb8fb commit 552279a

File tree

4 files changed

+39
-31
lines changed

4 files changed

+39
-31
lines changed

ardupilot_methodic_configurator/backend_flightcontroller.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
"""
1010

1111
from argparse import ArgumentParser
12+
from logging import debug as logging_debug
13+
from logging import error as logging_error
1214
from logging import info as logging_info
1315
from logging import warning as logging_warning
1416
from os import path as os_path
@@ -528,7 +530,8 @@ def setup_signing(
528530
try:
529531
# Set up the signing state on the MAVLink connection
530532
# pymavlink's mavlink_connection supports signing setup
531-
self.master.setup_signing(
533+
# Type ignore needed because MavlinkConnection is a Union including object fallback
534+
self.master.setup_signing( # type: ignore[union-attr]
532535
key,
533536
sign_outgoing=sign_outgoing,
534537
allow_unsigned_callback=self._unsigned_callback if allow_unsigned_in else None,
@@ -597,7 +600,8 @@ def disable_signing(self) -> tuple[bool, str]:
597600

598601
try:
599602
# Disable signing by passing None as key
600-
self.master.setup_signing(None, sign_outgoing=False, allow_unsigned_callback=None)
603+
# Type ignore needed because MavlinkConnection is a Union including object fallback
604+
self.master.setup_signing(None, sign_outgoing=False, allow_unsigned_callback=None) # type: ignore[union-attr]
601605
logging_info(_("MAVLink signing disabled"))
602606
return True, ""
603607
except AttributeError:
@@ -635,7 +639,8 @@ def get_signing_status(self) -> dict[str, object]:
635639

636640
try:
637641
# Check if signing is set up on the MAVLink connection
638-
mav = self.master.mav
642+
# Type ignore needed because MavlinkConnection is a Union including object fallback
643+
mav = self.master.mav # type: ignore[union-attr]
639644
if hasattr(mav, "signing") and mav.signing is not None:
640645
signing = mav.signing
641646
status["enabled"] = True

ardupilot_methodic_configurator/backend_signing_keystore.py

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/usr/bin/env python3
2-
31
"""
42
MAVLink 2.0 signing keystore for secure key management.
53
@@ -133,7 +131,7 @@ def fallback_path(self) -> Path:
133131
def _check_keyring_available(self) -> bool:
134132
"""Check if OS keyring is available and functional."""
135133
try:
136-
import keyring # pylint: disable=import-outside-toplevel
134+
import keyring # noqa: PLC0415 # pylint: disable=import-outside-toplevel
137135

138136
# Try to get the default keyring
139137
backend = keyring.get_keyring()
@@ -191,7 +189,7 @@ def store_key(self, vehicle_id: str, key: bytes, description: str = "") -> bool:
191189
# Try keyring first
192190
if self._keyring_available:
193191
try:
194-
import keyring # pylint: disable=import-outside-toplevel
192+
import keyring # noqa: PLC0415 # pylint: disable=import-outside-toplevel
195193

196194
# Store key as base64 encoded string
197195
key_b64 = base64.b64encode(key).decode("ascii")
@@ -207,9 +205,11 @@ def store_key(self, vehicle_id: str, key: bytes, description: str = "") -> bool:
207205
def _store_key_in_file(self, vehicle_id: str, key: bytes, description: str = "") -> bool:
208206
"""Store key in encrypted file."""
209207
try:
210-
from cryptography.fernet import Fernet # pylint: disable=import-outside-toplevel
211-
from cryptography.hazmat.primitives import hashes # pylint: disable=import-outside-toplevel
212-
from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC # pylint: disable=import-outside-toplevel
208+
from cryptography.fernet import Fernet # noqa: PLC0415 # pylint: disable=import-outside-toplevel
209+
from cryptography.hazmat.primitives import hashes # noqa: PLC0415 # pylint: disable=import-outside-toplevel
210+
from cryptography.hazmat.primitives.kdf.pbkdf2 import ( # noqa: PLC0415
211+
PBKDF2HMAC, # pylint: disable=import-outside-toplevel
212+
)
213213

214214
# Load existing keystore or create new
215215
keystore = self._load_keystore_file()
@@ -270,7 +270,7 @@ def retrieve_key(self, vehicle_id: str) -> Optional[bytes]:
270270
# Try keyring first
271271
if self._keyring_available:
272272
try:
273-
import keyring # pylint: disable=import-outside-toplevel
273+
import keyring # noqa: PLC0415 # pylint: disable=import-outside-toplevel
274274

275275
key_b64 = keyring.get_password(self._keyring_service, vehicle_id)
276276
if key_b64:
@@ -284,9 +284,11 @@ def retrieve_key(self, vehicle_id: str) -> Optional[bytes]:
284284
def _retrieve_key_from_file(self, vehicle_id: str) -> Optional[bytes]:
285285
"""Retrieve key from encrypted file."""
286286
try:
287-
from cryptography.fernet import Fernet # pylint: disable=import-outside-toplevel
288-
from cryptography.hazmat.primitives import hashes # pylint: disable=import-outside-toplevel
289-
from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC # pylint: disable=import-outside-toplevel
287+
from cryptography.fernet import Fernet # noqa: PLC0415 # pylint: disable=import-outside-toplevel
288+
from cryptography.hazmat.primitives import hashes # noqa: PLC0415 # pylint: disable=import-outside-toplevel
289+
from cryptography.hazmat.primitives.kdf.pbkdf2 import ( # noqa: PLC0415
290+
PBKDF2HMAC, # pylint: disable=import-outside-toplevel
291+
)
290292

291293
keystore = self._load_keystore_file()
292294

@@ -333,7 +335,7 @@ def delete_key(self, vehicle_id: str) -> bool:
333335
# Try keyring first
334336
if self._keyring_available:
335337
try:
336-
import keyring # pylint: disable=import-outside-toplevel
338+
import keyring # noqa: PLC0415 # pylint: disable=import-outside-toplevel
337339

338340
keyring.delete_password(self._keyring_service, vehicle_id)
339341
deleted = True
@@ -393,9 +395,11 @@ def export_key(self, vehicle_id: str, password: str) -> Optional[str]:
393395
return None
394396

395397
try:
396-
from cryptography.fernet import Fernet # pylint: disable=import-outside-toplevel
397-
from cryptography.hazmat.primitives import hashes # pylint: disable=import-outside-toplevel
398-
from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC # pylint: disable=import-outside-toplevel
398+
from cryptography.fernet import Fernet # noqa: PLC0415 # pylint: disable=import-outside-toplevel
399+
from cryptography.hazmat.primitives import hashes # noqa: PLC0415 # pylint: disable=import-outside-toplevel
400+
from cryptography.hazmat.primitives.kdf.pbkdf2 import ( # noqa: PLC0415
401+
PBKDF2HMAC, # pylint: disable=import-outside-toplevel
402+
)
399403

400404
# Generate salt
401405
salt = secrets.token_bytes(16)
@@ -442,9 +446,11 @@ def import_key(self, export_data: str, password: str) -> Optional[str]:
442446
443447
"""
444448
try:
445-
from cryptography.fernet import Fernet, InvalidToken # pylint: disable=import-outside-toplevel
446-
from cryptography.hazmat.primitives import hashes # pylint: disable=import-outside-toplevel
447-
from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC # pylint: disable=import-outside-toplevel
449+
from cryptography.fernet import Fernet, InvalidToken # noqa: PLC0415 # pylint: disable=import-outside-toplevel
450+
from cryptography.hazmat.primitives import hashes # noqa: PLC0415 # pylint: disable=import-outside-toplevel
451+
from cryptography.hazmat.primitives.kdf.pbkdf2 import ( # noqa: PLC0415
452+
PBKDF2HMAC, # pylint: disable=import-outside-toplevel
453+
)
448454

449455
# Decode export package
450456
data = json.loads(base64.b64decode(export_data).decode())

tests/test_signing_config.py

100644100755
File mode changed.

tests/test_signing_keystore.py

100644100755
Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ def temp_keystore(self, tmp_path) -> SigningKeystore:
5353
"""Create a keystore using temporary storage."""
5454
with patch("ardupilot_methodic_configurator.backend_signing_keystore.user_data_dir") as mock_dir:
5555
mock_dir.return_value = str(tmp_path)
56-
keystore = SigningKeystore(use_keyring=False)
57-
return keystore
56+
return SigningKeystore(use_keyring=False)
5857

5958
def test_user_can_store_key_for_vehicle(self, temp_keystore) -> None:
6059
"""
@@ -157,8 +156,7 @@ def temp_keystore(self, tmp_path) -> SigningKeystore:
157156
"""Create a keystore using temporary storage."""
158157
with patch("ardupilot_methodic_configurator.backend_signing_keystore.user_data_dir") as mock_dir:
159158
mock_dir.return_value = str(tmp_path)
160-
keystore = SigningKeystore(use_keyring=False)
161-
return keystore
159+
return SigningKeystore(use_keyring=False)
162160

163161
def test_user_can_export_key_with_password(self, temp_keystore) -> None:
164162
"""
@@ -172,7 +170,7 @@ def test_user_can_export_key_with_password(self, temp_keystore) -> None:
172170
key = temp_keystore.generate_key()
173171
vehicle_id = "EXPORT-VEHICLE"
174172
temp_keystore.store_key(vehicle_id, key)
175-
password = "secure-password-123"
173+
password = "secure-password-123" # noqa: S105
176174
export_data = temp_keystore.export_key(vehicle_id, password)
177175

178176
assert export_data is not None
@@ -190,7 +188,7 @@ def test_user_can_import_key_with_password(self, temp_keystore) -> None:
190188
original_key = temp_keystore.generate_key()
191189
vehicle_id = "IMPORT-VEHICLE"
192190
temp_keystore.store_key(vehicle_id, original_key)
193-
password = "import-password-456"
191+
password = "import-password-456" # noqa: S105
194192
export_data = temp_keystore.export_key(vehicle_id, password)
195193

196194
temp_keystore.delete_key(vehicle_id)
@@ -213,8 +211,8 @@ def test_invalid_password_fails_import(self, temp_keystore) -> None:
213211
key = temp_keystore.generate_key()
214212
vehicle_id = "WRONG-PASSWORD-VEHICLE"
215213
temp_keystore.store_key(vehicle_id, key)
216-
correct_password = "correct-password"
217-
wrong_password = "wrong-password"
214+
correct_password = "correct-password" # noqa: S105
215+
wrong_password = "wrong-password" # noqa: S105
218216
export_data = temp_keystore.export_key(vehicle_id, correct_password)
219217

220218
temp_keystore.delete_key(vehicle_id)
@@ -262,8 +260,7 @@ def temp_keystore(self, tmp_path) -> SigningKeystore:
262260
"""Create a keystore using temporary storage."""
263261
with patch("ardupilot_methodic_configurator.backend_signing_keystore.user_data_dir") as mock_dir:
264262
mock_dir.return_value = str(tmp_path)
265-
keystore = SigningKeystore(use_keyring=False)
266-
return keystore
263+
return SigningKeystore(use_keyring=False)
267264

268265
def test_invalid_key_length_raises_error(self, temp_keystore) -> None:
269266
"""

0 commit comments

Comments
 (0)