Skip to content

Commit 195ac4e

Browse files
authored
Merge pull request #7 from bernhardkaindl/type-alias-connection-props
Add and use type alias for connection properties
2 parents 46a7d54 + 8ba31e3 commit 195ac4e

File tree

6 files changed

+120
-34
lines changed

6 files changed

+120
-34
lines changed

sdbus_async/networkmanager/__init__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,11 @@
193193
NmVpnPluginInvalidConnectionError,
194194
NmVpnPluginInteractiveNotSupportedError,
195195
)
196+
from .types import (
197+
NetworkManagerSetting,
198+
NetworkManagerSettingsDomain,
199+
NetworkManagerConnectionProperties,
200+
)
196201

197202
DEVICE_TYPE_TO_CLASS = {
198203
DeviceType.ETHERNET: NetworkDeviceWired,
@@ -364,4 +369,8 @@
364369
'NmVpnPluginLaunchFailedError',
365370
'NmVpnPluginInvalidConnectionError',
366371
'NmVpnPluginInteractiveNotSupportedError',
372+
373+
'NetworkManagerSetting',
374+
'NetworkManagerSettingsDomain',
375+
'NetworkManagerConnectionProperties',
367376
)

sdbus_async/networkmanager/interfaces_other.py

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
from sdbus import (DbusInterfaceCommonAsync, dbus_method_async,
2525
dbus_property_async, dbus_signal_async)
2626

27+
from .types import NetworkManagerConnectionProperties
28+
2729

2830
class NetworkManagerAccessPointInterfaceAsync(
2931
DbusInterfaceCommonAsync,
@@ -464,7 +466,7 @@ class NetworkManagerSecretAgentInterfaceAsync(
464466
)
465467
async def get_secrets(
466468
self,
467-
connection: Dict[str, Dict[str, Tuple[str, Any]]],
469+
connection: NetworkManagerConnectionProperties,
468470
connection_path: str,
469471
setting_name: str,
470472
hints: List[str],
@@ -485,7 +487,7 @@ async def cancel_get_secrets(
485487
@dbus_method_async('a{sa{sv}}o')
486488
async def save_secrets(
487489
self,
488-
connection: Dict[str, Dict[str, Tuple[str, Any]]],
490+
connection: NetworkManagerConnectionProperties,
489491
connection_path: str,
490492
) -> None:
491493
"""Save given secrets"""
@@ -494,7 +496,7 @@ async def save_secrets(
494496
@dbus_method_async('a{sa{sv}}o')
495497
async def delete_secrets(
496498
self,
497-
connection: Dict[str, Dict[str, Tuple[str, Any]]],
499+
connection: NetworkManagerConnectionProperties,
498500
connection_path: str,
499501
) -> None:
500502
"""Delete secrets"""
@@ -509,7 +511,7 @@ class NetworkManagerSettingsConnectionInterfaceAsync(
509511
@dbus_method_async('a{sa{sv}}')
510512
async def update(
511513
self,
512-
properties: Dict[str, Dict[str, Tuple[str, Any]]],
514+
properties: NetworkManagerConnectionProperties,
513515
) -> None:
514516
"""Update connection settings.
515517
@@ -520,7 +522,7 @@ async def update(
520522
@dbus_method_async('a{sa{sv}}')
521523
async def update_unsaved(
522524
self,
523-
properties: Dict[str, Dict[str, Tuple[str, Any]]],
525+
properties: NetworkManagerConnectionProperties,
524526
) -> None:
525527
"""Update connection settings but do not save to disk"""
526528
raise NotImplementedError
@@ -537,7 +539,7 @@ async def delete(
537539
)
538540
async def get_settings(
539541
self,
540-
) -> Dict[str, Dict[str, Tuple[str, Any]]]:
542+
) -> NetworkManagerConnectionProperties:
541543
"""Get connection settings"""
542544
raise NotImplementedError
543545

@@ -572,7 +574,7 @@ async def save(
572574
)
573575
async def update2(
574576
self,
575-
settings: Dict[str, Dict[str, Tuple[str, Any]]],
577+
settings: NetworkManagerConnectionProperties,
576578
flags: int,
577579
args: Dict[str, Tuple[str, Any]],
578580
) -> Dict[str, Tuple[str, Any]]:
@@ -639,7 +641,7 @@ async def get_connection_by_uuid(
639641
)
640642
async def add_connection(
641643
self,
642-
connection: Dict[str, Dict[str, Tuple[str, Any]]],
644+
connection: NetworkManagerConnectionProperties,
643645
) -> str:
644646
"""Add connection and save to disk"""
645647
raise NotImplementedError
@@ -650,7 +652,7 @@ async def add_connection(
650652
)
651653
async def add_connection_unsaved(
652654
self,
653-
connection: Dict[str, Dict[str, Tuple[str, Any]]],
655+
connection: NetworkManagerConnectionProperties,
654656
) -> str:
655657
"""Add connection and do not save"""
656658
raise NotImplementedError
@@ -661,7 +663,7 @@ async def add_connection_unsaved(
661663
)
662664
async def add_connection2(
663665
self,
664-
settings: Dict[str, Dict[str, Tuple[str, Any]]],
666+
settings: NetworkManagerConnectionProperties,
665667
flags: int,
666668
args: Dict[str, Tuple[str, Any]],
667669
) -> Tuple[str, Dict[str, Tuple[str, Any]]]:
@@ -736,7 +738,7 @@ class NetworkManagerVPNPluginInterfaceAsync(
736738
@dbus_method_async('a{sa{sv}}')
737739
async def connect(
738740
self,
739-
connection: Dict[str, Dict[str, Tuple[str, Any]]],
741+
connection: NetworkManagerConnectionProperties,
740742
) -> None:
741743
"""Connect to described connection
742744
@@ -747,7 +749,7 @@ async def connect(
747749
@dbus_method_async('a{sa{sv}}a{sv}')
748750
async def connect_interactive(
749751
self,
750-
connection: Dict[str, Dict[str, Tuple[str, Any]]],
752+
connection: NetworkManagerConnectionProperties,
751753
details: Dict[str, Tuple[str, Any]],
752754
) -> None:
753755
"""Connect to described connection
@@ -763,7 +765,7 @@ async def connect_interactive(
763765
)
764766
async def need_secrets(
765767
self,
766-
settings: Dict[str, Dict[str, Tuple[str, Any]]],
768+
settings: NetworkManagerConnectionProperties,
767769
) -> str:
768770
"""Asks plugin if connection will require secrets
769771
@@ -813,9 +815,12 @@ async def set_failure(
813815
@dbus_method_async('a{sa{sv}}')
814816
async def new_secrets(
815817
self,
816-
connection: Dict[str, Dict[str, Tuple[str, Any]]],
818+
connection: NetworkManagerConnectionProperties,
817819
) -> None:
818-
"""Called in response to secrets_required signal"""
820+
"""Called in response to secrets_required signal
821+
822+
param: Describes the connection including the new secrets.
823+
"""
819824
raise NotImplementedError
820825

821826
@dbus_property_async('u')
@@ -999,7 +1004,7 @@ async def activate_connection(
9991004
)
10001005
async def add_and_activate_connection(
10011006
self,
1002-
connection: Dict[str, Dict[str, Tuple[str, Any]]],
1007+
connection: NetworkManagerConnectionProperties,
10031008
device: str,
10041009
specific_object: str,
10051010
) -> Tuple[str, str]:
@@ -1012,7 +1017,7 @@ async def add_and_activate_connection(
10121017
)
10131018
async def add_and_activate_connection2(
10141019
self,
1015-
connection: Dict[str, Dict[str, Tuple[str, Any]]],
1020+
connection: NetworkManagerConnectionProperties,
10161021
device: str,
10171022
specific_object: str,
10181023
options: Dict[str, Tuple[str, Any]],
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Copyright (C) 2022 igo95862, bernhardkaindl
2+
3+
# This file is part of python-sdbus
4+
5+
# This library is free software; you can redistribute it and/or
6+
# modify it under the terms of the GNU Lesser General Public
7+
# License as published by the Free Software Foundation; either
8+
# version 2.1 of the License, or (at your option) any later version.
9+
10+
# This library is distributed in the hope that it will be useful,
11+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
# Lesser General Public License for more details.
14+
15+
# You should have received a copy of the GNU Lesser General Public
16+
# License along with this library; if not, write to the Free Software
17+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18+
from typing import Any, Dict, Tuple
19+
20+
# Type aliases for network connection settings and properties
21+
22+
# "Any" might be str, int, bool (e.g. autoconnect), List[Ip] and maybe others
23+
NetworkManagerSetting = Tuple[str, Any]
24+
25+
# A settings domain, e.g. ipv4.*, ipv6.*, 802-11-wireless-security.*, etc:
26+
NetworkManagerSettingsDomain = Dict[str, NetworkManagerSetting]
27+
28+
# All settings and properites of a connection, e.g. returned by get_settings()
29+
NetworkManagerConnectionProperties = Dict[str, NetworkManagerSettingsDomain]

sdbus_block/networkmanager/__init__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,11 @@
151151
NmVpnPluginInvalidConnectionError,
152152
NmVpnPluginInteractiveNotSupportedError,
153153
)
154+
from .types import (
155+
NetworkManagerSetting,
156+
NetworkManagerSettingsDomain,
157+
NetworkManagerConnectionProperties,
158+
)
154159

155160
DEVICE_TYPE_TO_CLASS = {
156161
DeviceType.ETHERNET: NetworkDeviceWired,
@@ -322,4 +327,8 @@
322327
'NmVpnPluginLaunchFailedError',
323328
'NmVpnPluginInvalidConnectionError',
324329
'NmVpnPluginInteractiveNotSupportedError',
330+
331+
'NetworkManagerSetting',
332+
'NetworkManagerSettingsDomain',
333+
'NetworkManagerConnectionProperties',
325334
)

sdbus_block/networkmanager/interfaces_other.py

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
from sdbus import DbusInterfaceCommon, dbus_method, dbus_property
2525

26+
from .types import NetworkManagerConnectionProperties
27+
2628

2729
class NetworkManagerAccessPointInterface(
2830
DbusInterfaceCommon,
@@ -446,7 +448,7 @@ class NetworkManagerSecretAgentInterface(
446448
)
447449
def get_secrets(
448450
self,
449-
connection: Dict[str, Dict[str, Tuple[str, Any]]],
451+
connection: NetworkManagerConnectionProperties,
450452
connection_path: str,
451453
setting_name: str,
452454
hints: List[str],
@@ -467,7 +469,7 @@ def cancel_get_secrets(
467469
@dbus_method('a{sa{sv}}o')
468470
def save_secrets(
469471
self,
470-
connection: Dict[str, Dict[str, Tuple[str, Any]]],
472+
connection: NetworkManagerConnectionProperties,
471473
connection_path: str,
472474
) -> None:
473475
"""Save given secrets"""
@@ -476,7 +478,7 @@ def save_secrets(
476478
@dbus_method('a{sa{sv}}o')
477479
def delete_secrets(
478480
self,
479-
connection: Dict[str, Dict[str, Tuple[str, Any]]],
481+
connection: NetworkManagerConnectionProperties,
480482
connection_path: str,
481483
) -> None:
482484
"""Delete secrets"""
@@ -491,7 +493,7 @@ class NetworkManagerSettingsConnectionInterface(
491493
@dbus_method('a{sa{sv}}')
492494
def update(
493495
self,
494-
properties: Dict[str, Dict[str, Tuple[str, Any]]],
496+
properties: NetworkManagerConnectionProperties,
495497
) -> None:
496498
"""Update connection settings.
497499
@@ -502,7 +504,7 @@ def update(
502504
@dbus_method('a{sa{sv}}')
503505
def update_unsaved(
504506
self,
505-
properties: Dict[str, Dict[str, Tuple[str, Any]]],
507+
properties: NetworkManagerConnectionProperties,
506508
) -> None:
507509
"""Update connection settings but do not save to disk"""
508510
raise NotImplementedError
@@ -519,7 +521,7 @@ def delete(
519521
)
520522
def get_settings(
521523
self,
522-
) -> Dict[str, Dict[str, Tuple[str, Any]]]:
524+
) -> NetworkManagerConnectionProperties:
523525
"""Get connection settings"""
524526
raise NotImplementedError
525527

@@ -554,7 +556,7 @@ def save(
554556
)
555557
def update2(
556558
self,
557-
settings: Dict[str, Dict[str, Tuple[str, Any]]],
559+
settings: NetworkManagerConnectionProperties,
558560
flags: int,
559561
args: Dict[str, Tuple[str, Any]],
560562
) -> Dict[str, Tuple[str, Any]]:
@@ -611,7 +613,7 @@ def get_connection_by_uuid(
611613
)
612614
def add_connection(
613615
self,
614-
connection: Dict[str, Dict[str, Tuple[str, Any]]],
616+
connection: NetworkManagerConnectionProperties,
615617
) -> str:
616618
"""Add connection and save to disk"""
617619
raise NotImplementedError
@@ -622,7 +624,7 @@ def add_connection(
622624
)
623625
def add_connection_unsaved(
624626
self,
625-
connection: Dict[str, Dict[str, Tuple[str, Any]]],
627+
connection: NetworkManagerConnectionProperties,
626628
) -> str:
627629
"""Add connection and do not save"""
628630
raise NotImplementedError
@@ -633,7 +635,7 @@ def add_connection_unsaved(
633635
)
634636
def add_connection2(
635637
self,
636-
settings: Dict[str, Dict[str, Tuple[str, Any]]],
638+
settings: NetworkManagerConnectionProperties,
637639
flags: int,
638640
args: Dict[str, Tuple[str, Any]],
639641
) -> Tuple[str, Dict[str, Tuple[str, Any]]]:
@@ -698,7 +700,7 @@ class NetworkManagerVPNPluginInterface(
698700
@dbus_method('a{sa{sv}}')
699701
def connect(
700702
self,
701-
connection: Dict[str, Dict[str, Tuple[str, Any]]],
703+
connection: NetworkManagerConnectionProperties,
702704
) -> None:
703705
"""Connect to described connection
704706
@@ -709,7 +711,7 @@ def connect(
709711
@dbus_method('a{sa{sv}}a{sv}')
710712
def connect_interactive(
711713
self,
712-
connection: Dict[str, Dict[str, Tuple[str, Any]]],
714+
connection: NetworkManagerConnectionProperties,
713715
details: Dict[str, Tuple[str, Any]],
714716
) -> None:
715717
"""Connect to described connection
@@ -725,7 +727,7 @@ def connect_interactive(
725727
)
726728
def need_secrets(
727729
self,
728-
settings: Dict[str, Dict[str, Tuple[str, Any]]],
730+
settings: NetworkManagerConnectionProperties,
729731
) -> str:
730732
"""Asks plugin if connection will require secrets
731733
@@ -775,9 +777,12 @@ def set_failure(
775777
@dbus_method('a{sa{sv}}')
776778
def new_secrets(
777779
self,
778-
connection: Dict[str, Dict[str, Tuple[str, Any]]],
780+
connection: NetworkManagerConnectionProperties,
779781
) -> None:
780-
"""Called in response to secrets_required signal"""
782+
"""Called in response to secrets_required signal
783+
784+
param: Describes the connection including the new secrets
785+
"""
781786
raise NotImplementedError
782787

783788
@dbus_property('u')
@@ -920,7 +925,7 @@ def activate_connection(
920925
)
921926
def add_and_activate_connection(
922927
self,
923-
connection: Dict[str, Dict[str, Tuple[str, Any]]],
928+
connection: NetworkManagerConnectionProperties,
924929
device: str,
925930
specific_object: str,
926931
) -> Tuple[str, str]:
@@ -933,7 +938,7 @@ def add_and_activate_connection(
933938
)
934939
def add_and_activate_connection2(
935940
self,
936-
connection: Dict[str, Dict[str, Tuple[str, Any]]],
941+
connection: NetworkManagerConnectionProperties,
937942
device: str,
938943
specific_object: str,
939944
options: Dict[str, Tuple[str, Any]],

0 commit comments

Comments
 (0)