From 2c7e6be27269a864ed99964a0fc1867750ac0a69 Mon Sep 17 00:00:00 2001 From: jkirkwood Date: Wed, 10 Jul 2019 15:37:19 -0400 Subject: [PATCH] Add GetSecrets method to connection --- Connection.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Connection.go b/Connection.go index 6ff802a..fc03603 100644 --- a/Connection.go +++ b/Connection.go @@ -46,6 +46,12 @@ type Connection interface { // separately using the GetSecrets() method. GetSettings() (ConnectionSettings, error) + // Get the secrets belonging to this network configuration. Only secrets from + // persistent storage or a Secret Agent running in the requestor's session + // will be returned. The user will never be prompted for secrets as a result + // of this request. + GetSecrets(settingName string) (ConnectionSettings, error) + // Clear the secrets belonging to this network connection profile. ClearSecrets() error @@ -110,6 +116,27 @@ func (c *connection) GetSettings() (ConnectionSettings, error) { return rv, nil } +func (c *connection) GetSecrets(settingName string) (ConnectionSettings, error) { + var settings map[string]map[string]dbus.Variant + err := c.callWithReturn(&settings, ConnectionGetSecrets, settingName) + + if err != nil { + return nil, err + } + + rv := make(ConnectionSettings) + + for k1, v1 := range settings { + rv[k1] = make(map[string]interface{}) + + for k2, v2 := range v1 { + rv[k1][k2] = v2.Value() + } + } + + return rv, nil +} + func (c *connection) ClearSecrets() error { return c.call(ConnectionClearSecrets) }