|
28 | 28 | dbus_signal_async, |
29 | 29 | ) |
30 | 30 |
|
| 31 | +from .settings import ConnectionProfile |
31 | 32 | from .types import NetworkManagerConnectionProperties |
32 | 33 |
|
33 | 34 |
|
@@ -613,6 +614,51 @@ def removed(self) -> None: |
613 | 614 | """Signal when connection is removed""" |
614 | 615 | raise NotImplementedError |
615 | 616 |
|
| 617 | + async def update_profile(self, |
| 618 | + profile: ConnectionProfile, |
| 619 | + save_to_disk: bool = True) -> None: |
| 620 | + """Update connection using the profile dataclass. |
| 621 | +
|
| 622 | + :param ConnectionProfile profile: Connection profile to update |
| 623 | + with. |
| 624 | +
|
| 625 | + :param bool save_to_disk: Make changes permanent by saving |
| 626 | + updated values to disk. |
| 627 | +
|
| 628 | + By default changes are temporary. (saved only to RAM) |
| 629 | + """ |
| 630 | + flags = 0 |
| 631 | + |
| 632 | + if save_to_disk: |
| 633 | + flags |= 0x1 |
| 634 | + else: |
| 635 | + flags |= 0x2 |
| 636 | + |
| 637 | + await self.update2(profile.to_dbus(), flags, {}) |
| 638 | + |
| 639 | + async def get_profile(self, |
| 640 | + fetch_secrets: bool = True) -> ConnectionProfile: |
| 641 | + """Get the connection settings as the profile object. |
| 642 | +
|
| 643 | + :param bool fetch_secrets: Retrieve secret values. (like VPN passwords) |
| 644 | + Makes additional calls to NetworkManager. |
| 645 | + """ |
| 646 | + profile = ConnectionProfile.from_dbus(await self.get_settings()) |
| 647 | + |
| 648 | + if fetch_secrets: |
| 649 | + secrets_name_generator = profile.update_secrets_generator() |
| 650 | + try: |
| 651 | + secrets_name = next(secrets_name_generator) |
| 652 | + while True: |
| 653 | + secret_profile = ConnectionProfile.from_dbus( |
| 654 | + await self.get_secrets(secrets_name)) |
| 655 | + |
| 656 | + secrets_name = secrets_name_generator.send(secret_profile) |
| 657 | + except StopIteration: |
| 658 | + ... |
| 659 | + |
| 660 | + return profile |
| 661 | + |
616 | 662 |
|
617 | 663 | class NetworkManagerSettingsInterfaceAsync( |
618 | 664 | DbusInterfaceCommonAsync, |
|
0 commit comments