engine: resources: Remove named return params
Named return params aren't a favourite feature of mine, and they're rarely used in the resource writing. They keep popping up because I once used them and we've been copying and pasting code ever since. Get rid of them all to help prevent the unnecessary spread.
This commit is contained in:
@@ -604,7 +604,7 @@ func (obj *AwsEc2Res) snsWatch() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CheckApply method for AwsEc2 resource.
|
// CheckApply method for AwsEc2 resource.
|
||||||
func (obj *AwsEc2Res) CheckApply(apply bool) (checkOK bool, err error) {
|
func (obj *AwsEc2Res) CheckApply(apply bool) (bool, error) {
|
||||||
obj.init.Logf("CheckApply(%t)", apply)
|
obj.init.Logf("CheckApply(%t)", apply)
|
||||||
|
|
||||||
// find the instance we need to check
|
// find the instance we need to check
|
||||||
|
|||||||
@@ -310,28 +310,29 @@ func (obj *CronRes) Watch() error {
|
|||||||
// CheckApply is run to check the state and, if apply is true, to apply the
|
// CheckApply is run to check the state and, if apply is true, to apply the
|
||||||
// necessary changes to reach the desired state. This is run before Watch and
|
// necessary changes to reach the desired state. This is run before Watch and
|
||||||
// again if Watch finds a change occurring to the state.
|
// again if Watch finds a change occurring to the state.
|
||||||
func (obj *CronRes) CheckApply(apply bool) (checkOK bool, err error) {
|
func (obj *CronRes) CheckApply(apply bool) (bool, error) {
|
||||||
ok := true
|
checkOK := true
|
||||||
// use the embedded file resource to apply the correct state
|
// use the embedded file resource to apply the correct state
|
||||||
if c, err := obj.file.CheckApply(apply); err != nil {
|
if c, err := obj.file.CheckApply(apply); err != nil {
|
||||||
return false, errwrap.Wrapf(err, "nested file failed")
|
return false, errwrap.Wrapf(err, "nested file failed")
|
||||||
} else if !c {
|
} else if !c {
|
||||||
ok = false
|
checkOK = false
|
||||||
}
|
}
|
||||||
// check timer state and apply the defined state if needed
|
// check timer state and apply the defined state if needed
|
||||||
if c, err := obj.unitCheckApply(apply); err != nil {
|
if c, err := obj.unitCheckApply(apply); err != nil {
|
||||||
return false, errwrap.Wrapf(err, "unitCheckApply error")
|
return false, errwrap.Wrapf(err, "unitCheckApply error")
|
||||||
} else if !c {
|
} else if !c {
|
||||||
ok = false
|
checkOK = false
|
||||||
}
|
}
|
||||||
return ok, nil
|
return checkOK, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// unitCheckApply checks the state of the systemd-timer unit and, if apply is
|
// unitCheckApply checks the state of the systemd-timer unit and, if apply is
|
||||||
// true, applies the defined state.
|
// true, applies the defined state.
|
||||||
func (obj *CronRes) unitCheckApply(apply bool) (checkOK bool, err error) {
|
func (obj *CronRes) unitCheckApply(apply bool) (bool, error) {
|
||||||
var conn *sdbus.Conn
|
var conn *sdbus.Conn
|
||||||
var godbusConn *dbus.Conn
|
var godbusConn *dbus.Conn
|
||||||
|
var err error
|
||||||
|
|
||||||
// this resource depends on systemd to ensure that it's running
|
// this resource depends on systemd to ensure that it's running
|
||||||
if !systemdUtil.IsRunningSystemd() {
|
if !systemdUtil.IsRunningSystemd() {
|
||||||
|
|||||||
@@ -201,7 +201,7 @@ func (obj *DockerContainerRes) Watch() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CheckApply method for Docker resource.
|
// CheckApply method for Docker resource.
|
||||||
func (obj *DockerContainerRes) CheckApply(apply bool) (checkOK bool, err error) {
|
func (obj *DockerContainerRes) CheckApply(apply bool) (bool, error) {
|
||||||
var id string
|
var id string
|
||||||
var destroy bool
|
var destroy bool
|
||||||
|
|
||||||
|
|||||||
@@ -118,7 +118,7 @@ func (obj *GroupRes) Watch() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CheckApply method for Group resource.
|
// CheckApply method for Group resource.
|
||||||
func (obj *GroupRes) CheckApply(apply bool) (checkOK bool, err error) {
|
func (obj *GroupRes) CheckApply(apply bool) (bool, error) {
|
||||||
obj.init.Logf("CheckApply(%t)", apply)
|
obj.init.Logf("CheckApply(%t)", apply)
|
||||||
|
|
||||||
// check if the group exists
|
// check if the group exists
|
||||||
|
|||||||
@@ -147,7 +147,7 @@ func (obj *HostnameRes) Watch() error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (obj *HostnameRes) updateHostnameProperty(object dbus.BusObject, expectedValue, property, setterName string, apply bool) (checkOK bool, err error) {
|
func (obj *HostnameRes) updateHostnameProperty(object dbus.BusObject, expectedValue, property, setterName string, apply bool) (bool, error) {
|
||||||
propertyObject, err := object.GetProperty("org.freedesktop.hostname1." + property)
|
propertyObject, err := object.GetProperty("org.freedesktop.hostname1." + property)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, errwrap.Wrapf(err, "failed to get org.freedesktop.hostname1.%s", property)
|
return false, errwrap.Wrapf(err, "failed to get org.freedesktop.hostname1.%s", property)
|
||||||
@@ -182,7 +182,7 @@ func (obj *HostnameRes) updateHostnameProperty(object dbus.BusObject, expectedVa
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CheckApply method for Hostname resource.
|
// CheckApply method for Hostname resource.
|
||||||
func (obj *HostnameRes) CheckApply(apply bool) (checkOK bool, err error) {
|
func (obj *HostnameRes) CheckApply(apply bool) (bool, error) {
|
||||||
conn, err := util.SystemBusPrivateUsable()
|
conn, err := util.SystemBusPrivateUsable()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, errwrap.Wrapf(err, "failed to connect to the private system bus")
|
return false, errwrap.Wrapf(err, "failed to connect to the private system bus")
|
||||||
@@ -191,7 +191,7 @@ func (obj *HostnameRes) CheckApply(apply bool) (checkOK bool, err error) {
|
|||||||
|
|
||||||
hostnameObject := conn.Object(hostname1Iface, hostname1Path)
|
hostnameObject := conn.Object(hostname1Iface, hostname1Path)
|
||||||
|
|
||||||
checkOK = true
|
checkOK := true
|
||||||
if obj.PrettyHostname != "" {
|
if obj.PrettyHostname != "" {
|
||||||
propertyCheckOK, err := obj.updateHostnameProperty(hostnameObject, obj.PrettyHostname, "PrettyHostname", "SetPrettyHostname", apply)
|
propertyCheckOK, err := obj.updateHostnameProperty(hostnameObject, obj.PrettyHostname, "PrettyHostname", "SetPrettyHostname", apply)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -150,7 +150,7 @@ func (obj *KVRes) Watch() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// lessThanCheck checks for less than validity.
|
// lessThanCheck checks for less than validity.
|
||||||
func (obj *KVRes) lessThanCheck(value string) (checkOK bool, err error) {
|
func (obj *KVRes) lessThanCheck(value string) (bool, error) {
|
||||||
v := *obj.Value
|
v := *obj.Value
|
||||||
if value == v { // redundant check for safety
|
if value == v { // redundant check for safety
|
||||||
return true, nil
|
return true, nil
|
||||||
@@ -188,7 +188,7 @@ func (obj *KVRes) lessThanCheck(value string) (checkOK bool, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CheckApply method for Password resource. Does nothing, returns happy!
|
// CheckApply method for Password resource. Does nothing, returns happy!
|
||||||
func (obj *KVRes) CheckApply(apply bool) (checkOK bool, err error) {
|
func (obj *KVRes) CheckApply(apply bool) (bool, error) {
|
||||||
obj.init.Logf("CheckApply(%t)", apply)
|
obj.init.Logf("CheckApply(%t)", apply)
|
||||||
|
|
||||||
if val, exists := obj.init.Recv()["Value"]; exists && val.Changed {
|
if val, exists := obj.init.Recv()["Value"]; exists && val.Changed {
|
||||||
|
|||||||
@@ -275,7 +275,7 @@ func (obj *MountRes) Watch() error {
|
|||||||
|
|
||||||
// fstabCheckApply checks /etc/fstab for entries corresponding to the resource
|
// fstabCheckApply checks /etc/fstab for entries corresponding to the resource
|
||||||
// definition, and adds or deletes the entry as needed.
|
// definition, and adds or deletes the entry as needed.
|
||||||
func (obj *MountRes) fstabCheckApply(apply bool) (checkOK bool, err error) {
|
func (obj *MountRes) fstabCheckApply(apply bool) (bool, error) {
|
||||||
exists, err := fstabEntryExists(fstabPath, obj.mount)
|
exists, err := fstabEntryExists(fstabPath, obj.mount)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, errwrap.Wrapf(err, "error checking if fstab entry exists")
|
return false, errwrap.Wrapf(err, "error checking if fstab entry exists")
|
||||||
@@ -339,8 +339,8 @@ func (obj *MountRes) mountCheckApply(apply bool) (bool, error) {
|
|||||||
// CheckApply is run to check the state and, if apply is true, to apply the
|
// CheckApply is run to check the state and, if apply is true, to apply the
|
||||||
// necessary changes to reach the desired state. This is run before Watch and
|
// necessary changes to reach the desired state. This is run before Watch and
|
||||||
// again if Watch finds a change occurring to the state.
|
// again if Watch finds a change occurring to the state.
|
||||||
func (obj *MountRes) CheckApply(apply bool) (checkOK bool, err error) {
|
func (obj *MountRes) CheckApply(apply bool) (bool, error) {
|
||||||
checkOK = true
|
checkOK := true
|
||||||
|
|
||||||
if c, err := obj.fstabCheckApply(apply); err != nil {
|
if c, err := obj.fstabCheckApply(apply); err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
|
|||||||
@@ -460,8 +460,8 @@ func (obj *NetRes) fileCheckApply(apply bool) (bool, error) {
|
|||||||
// CheckApply is run to check the state and, if apply is true, to apply the
|
// CheckApply is run to check the state and, if apply is true, to apply the
|
||||||
// necessary changes to reach the desired state. This is run before Watch and
|
// necessary changes to reach the desired state. This is run before Watch and
|
||||||
// again if Watch finds a change occurring to the state.
|
// again if Watch finds a change occurring to the state.
|
||||||
func (obj *NetRes) CheckApply(apply bool) (checkOK bool, err error) {
|
func (obj *NetRes) CheckApply(apply bool) (bool, error) {
|
||||||
checkOK = true
|
checkOK := true
|
||||||
|
|
||||||
// check the network device
|
// check the network device
|
||||||
if c, err := obj.ifaceCheckApply(apply); err != nil {
|
if c, err := obj.ifaceCheckApply(apply); err != nil {
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ func (obj *NoopRes) Watch() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CheckApply method for Noop resource. Does nothing, returns happy!
|
// CheckApply method for Noop resource. Does nothing, returns happy!
|
||||||
func (obj *NoopRes) CheckApply(apply bool) (checkOK bool, err error) {
|
func (obj *NoopRes) CheckApply(apply bool) (bool, error) {
|
||||||
if obj.init.Refresh() {
|
if obj.init.Refresh() {
|
||||||
obj.init.Logf("received a notification!")
|
obj.init.Logf("received a notification!")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -201,7 +201,7 @@ func (obj *NspawnRes) Watch() error {
|
|||||||
// CheckApply is run to check the state and, if apply is true, to apply the
|
// CheckApply is run to check the state and, if apply is true, to apply the
|
||||||
// necessary changes to reach the desired state. This is run before Watch and
|
// necessary changes to reach the desired state. This is run before Watch and
|
||||||
// again if Watch finds a change occurring to the state.
|
// again if Watch finds a change occurring to the state.
|
||||||
func (obj *NspawnRes) CheckApply(apply bool) (checkOK bool, err error) {
|
func (obj *NspawnRes) CheckApply(apply bool) (bool, error) {
|
||||||
// this resource depends on systemd to ensure that it's running
|
// this resource depends on systemd to ensure that it's running
|
||||||
if !systemdUtil.IsRunningSystemd() {
|
if !systemdUtil.IsRunningSystemd() {
|
||||||
return false, errors.New("systemd is not running")
|
return false, errors.New("systemd is not running")
|
||||||
|
|||||||
@@ -209,7 +209,7 @@ func (obj *PasswordRes) Watch() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CheckApply method for Password resource. Does nothing, returns happy!
|
// CheckApply method for Password resource. Does nothing, returns happy!
|
||||||
func (obj *PasswordRes) CheckApply(apply bool) (checkOK bool, err error) {
|
func (obj *PasswordRes) CheckApply(apply bool) (bool, error) {
|
||||||
var refresh = obj.init.Refresh() // do we have a pending reload to apply?
|
var refresh = obj.init.Refresh() // do we have a pending reload to apply?
|
||||||
var exists = true // does the file (aka the token) exist?
|
var exists = true // does the file (aka the token) exist?
|
||||||
var generate bool // do we need to generate a new password?
|
var generate bool // do we need to generate a new password?
|
||||||
|
|||||||
@@ -262,7 +262,7 @@ func (obj *PkgRes) populateFileList() error {
|
|||||||
|
|
||||||
// CheckApply checks the resource state and applies the resource if the bool
|
// CheckApply checks the resource state and applies the resource if the bool
|
||||||
// input is true. It returns error info and if the state check passed or not.
|
// input is true. It returns error info and if the state check passed or not.
|
||||||
func (obj *PkgRes) CheckApply(apply bool) (checkOK bool, err error) {
|
func (obj *PkgRes) CheckApply(apply bool) (bool, error) {
|
||||||
obj.init.Logf("Check: %s", obj.fmtNames(obj.getNames()))
|
obj.init.Logf("Check: %s", obj.fmtNames(obj.getNames()))
|
||||||
|
|
||||||
bus := packagekit.NewBus()
|
bus := packagekit.NewBus()
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ func (obj *PrintRes) Watch() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CheckApply method for Print resource. Does nothing, returns happy!
|
// CheckApply method for Print resource. Does nothing, returns happy!
|
||||||
func (obj *PrintRes) CheckApply(apply bool) (checkOK bool, err error) {
|
func (obj *PrintRes) CheckApply(apply bool) (bool, error) {
|
||||||
obj.init.Logf("CheckApply: %t", apply)
|
obj.init.Logf("CheckApply: %t", apply)
|
||||||
if val, exists := obj.init.Recv()["Msg"]; exists && val.Changed {
|
if val, exists := obj.init.Recv()["Msg"]; exists && val.Changed {
|
||||||
// if we received on Msg, and it changed, log message
|
// if we received on Msg, and it changed, log message
|
||||||
|
|||||||
@@ -229,12 +229,13 @@ func (obj *SvcRes) Watch() error {
|
|||||||
|
|
||||||
// CheckApply checks the resource state and applies the resource if the bool
|
// CheckApply checks the resource state and applies the resource if the bool
|
||||||
// input is true. It returns error info and if the state check passed or not.
|
// input is true. It returns error info and if the state check passed or not.
|
||||||
func (obj *SvcRes) CheckApply(apply bool) (checkOK bool, err error) {
|
func (obj *SvcRes) CheckApply(apply bool) (bool, error) {
|
||||||
if !systemdUtil.IsRunningSystemd() {
|
if !systemdUtil.IsRunningSystemd() {
|
||||||
return false, fmt.Errorf("systemd is not running")
|
return false, fmt.Errorf("systemd is not running")
|
||||||
}
|
}
|
||||||
|
|
||||||
var conn *systemd.Conn
|
var conn *systemd.Conn
|
||||||
|
var err error
|
||||||
if obj.Session {
|
if obj.Session {
|
||||||
conn, err = systemd.NewUserConnection() // user session
|
conn, err = systemd.NewUserConnection() // user session
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ func (obj *TestRes) Watch() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CheckApply method for Test resource. Does nothing, returns happy!
|
// CheckApply method for Test resource. Does nothing, returns happy!
|
||||||
func (obj *TestRes) CheckApply(apply bool) (checkOK bool, err error) {
|
func (obj *TestRes) CheckApply(apply bool) (bool, error) {
|
||||||
for key, val := range obj.init.Recv() {
|
for key, val := range obj.init.Recv() {
|
||||||
obj.init.Logf("CheckApply: Received `%s`, changed: %t", key, val.Changed)
|
obj.init.Logf("CheckApply: Received `%s`, changed: %t", key, val.Changed)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -152,7 +152,7 @@ func (obj *UserRes) Watch() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CheckApply method for User resource.
|
// CheckApply method for User resource.
|
||||||
func (obj *UserRes) CheckApply(apply bool) (checkOK bool, err error) {
|
func (obj *UserRes) CheckApply(apply bool) (bool, error) {
|
||||||
obj.init.Logf("CheckApply(%t)", apply)
|
obj.init.Logf("CheckApply(%t)", apply)
|
||||||
|
|
||||||
var exists = true
|
var exists = true
|
||||||
|
|||||||
Reference in New Issue
Block a user