Complete Connection interface

This commit is contained in:
Christian Müller 2019-05-28 17:43:33 +02:00
parent 3f7449c467
commit abedd499b3

View file

@ -31,12 +31,36 @@ type ConnectionSettings map[string]map[string]interface{}
type Connection interface { type Connection interface {
GetPath() dbus.ObjectPath GetPath() dbus.ObjectPath
// Update the connection with new settings and properties (replacing all previous settings and properties) and save the connection to disk. Secrets may be part of the update request, and will be either stored in persistent storage or sent to a Secret Agent for storage, depending on the flags associated with each secret.
Update(settings ConnectionSettings) error
// Update the connection with new settings and properties (replacing all previous settings and properties) but do not immediately save the connection to disk. Secrets may be part of the update request and may sent to a Secret Agent for storage, depending on the flags associated with each secret. Use the 'Save' method to save these changes to disk. Note that unsaved changes will be lost if the connection is reloaded from disk (either automatically on file change or due to an explicit ReloadConnections call).
UpdateUnsaved(settings ConnectionSettings) error
// Delete the connection.
Delete() error
// GetSettings gets the settings maps describing this network configuration. // GetSettings gets the settings maps describing this network configuration.
// This will never include any secrets required for connection to the // This will never include any secrets required for connection to the
// network, as those are often protected. Secrets must be requested // network, as those are often protected. Secrets must be requested
// separately using the GetSecrets() callWithReturnAndPanic. // separately using the GetSecrets() callWithReturnAndPanic.
GetSettings() ConnectionSettings GetSettings() ConnectionSettings
// Clear the secrets belonging to this network connection profile.
ClearSecrets() error
// Saves a "dirty" connection (that had previously been updated with UpdateUnsaved) to persistent storage.
Save() error
// If set, indicates that the in-memory state of the connection does not match the on-disk state. This flag will be set when UpdateUnsaved() is called or when any connection details change, and cleared when the connection is saved to disk via Save() or from internal operations.
GetUnsaved() bool
// Additional flags of the connection profile.
GetFlags() uint32
// File that stores the connection in case the connection is file-backed.
GetFilename() string
MarshalJSON() ([]byte, error) MarshalJSON() ([]byte, error)
} }
@ -53,6 +77,18 @@ func (c *connection) GetPath() dbus.ObjectPath {
return c.obj.Path() return c.obj.Path()
} }
func (c *connection) Update(settings ConnectionSettings) error {
return c.call(ConnectionUpdate, settings)
}
func (c *connection) UpdateUnsaved(settings ConnectionSettings) error {
return c.call(ConnectionUpdateUnsaved, settings)
}
func (c *connection) Delete() error {
return c.call(ConnectionDelete)
}
func (c *connection) GetSettings() ConnectionSettings { func (c *connection) GetSettings() ConnectionSettings {
var settings map[string]map[string]dbus.Variant var settings map[string]map[string]dbus.Variant
c.callWithReturnAndPanic(&settings, ConnectionGetSettings) c.callWithReturnAndPanic(&settings, ConnectionGetSettings)
@ -70,6 +106,26 @@ func (c *connection) GetSettings() ConnectionSettings {
return rv return rv
} }
func (c *connection) ClearSecrets() error {
return c.call(ConnectionClearSecrets)
}
func (c *connection) Save() error {
return c.call(ConnectionSave)
}
func (c *connection) GetUnsaved() bool {
return c.getBoolProperty(ConnectionPropertyUnsaved)
}
func (c *connection) GetFlags() uint32 {
return c.getUint32Property(ConnectionPropertyFlags)
}
func (c *connection) GetFilename() string {
return c.getStringProperty(ConnectionPropertyFilename)
}
func (c *connection) MarshalJSON() ([]byte, error) { func (c *connection) MarshalJSON() ([]byte, error) {
return json.Marshal(c.GetSettings()) return json.Marshal(c.GetSettings())
} }