|
6 | 6 |
|
7 | 7 | import copy |
8 | 8 | import dbus |
| 9 | +import dbus.service |
9 | 10 | import os |
10 | 11 | import six |
11 | 12 | import socket |
@@ -413,11 +414,36 @@ class IP6Config(TransientNMDbusInterface): pass |
413 | 414 | class DHCP4Config(TransientNMDbusInterface): pass |
414 | 415 | class DHCP6Config(TransientNMDbusInterface): pass |
415 | 416 |
|
416 | | -# These three are interfaces that must be provided to NetworkManager. Keep them |
| 417 | +# Evil hack to work around not being able to specify a method name in the |
| 418 | +# dbus.service.method decorator. |
| 419 | +class SecretAgentType(type(dbus.service.Object)): |
| 420 | + def __new__(type_, name, bases, attrs): |
| 421 | + if bases != (dbus.service.Object,): |
| 422 | + attrs['GetSecretsImpl'] = attrs.pop('GetSecrets') |
| 423 | + return super(SecretAgentType, type_).__new__(type_, name, bases, attrs) |
| 424 | + |
| 425 | +@six.add_metaclass(SecretAgentType) |
| 426 | +class SecretAgent(dbus.service.Object): |
| 427 | + object_path = '/org/freedesktop/NetworkManager/SecretAgent' |
| 428 | + interface_name = 'org.freedesktop.NetworkManager.SecretAgent' |
| 429 | + |
| 430 | + def __init__(self, identifier): |
| 431 | + self.identifier = identifier |
| 432 | + dbus.service.Object.__init__(self, dbus.SystemBus(), self.object_path) |
| 433 | + AgentManager.Register(self.identifier) |
| 434 | + |
| 435 | + @dbus.service.method(dbus_interface=interface_name, in_signature='a{sa{sv}}osasu', out_signature='a{sa{sv}}') |
| 436 | + def GetSecrets(self, connection, connection_path, setting_name, hints, flags): |
| 437 | + settings = fixups.to_python('SecretAgent', 'GetSecrets', 'connection', connection, 'a{sa{sv}}') |
| 438 | + connection = fixups.to_python('SecretAgent', 'GetSecrets', 'connection_path', connection_path, 'o') |
| 439 | + setting_name = fixups.to_python('SecretAgent', 'GetSecrets', 'setting_name', setting_name, 's') |
| 440 | + hints = fixups.to_python('SecretAgent', 'GetSecrets', 'hints', hints, 'as') |
| 441 | + return self.GetSecretsImpl(settings, connection, setting_name, hints, flags) |
| 442 | + |
| 443 | +# These two are interfaces that must be provided to NetworkManager. Keep them |
417 | 444 | # as comments for documentation purposes. |
418 | 445 | # |
419 | 446 | # class PPP(NMDbusInterface): pass |
420 | | -# class SecretAgent(NMDbusInterface): pass |
421 | 447 | # class VPNPlugin(NMDbusInterface): |
422 | 448 | # interface_names = ['org.freedesktop.NetworkManager.VPN.Plugin'] |
423 | 449 |
|
|
0 commit comments