diff --git a/engine/resources/aws_ec2.go b/engine/resources/aws_ec2.go index 698090cb..d20cc70c 100644 --- a/engine/resources/aws_ec2.go +++ b/engine/resources/aws_ec2.go @@ -604,7 +604,7 @@ func (obj *AwsEc2Res) snsWatch() error { } // 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) // find the instance we need to check diff --git a/engine/resources/cron.go b/engine/resources/cron.go index a7ea9d39..b7401490 100644 --- a/engine/resources/cron.go +++ b/engine/resources/cron.go @@ -310,28 +310,29 @@ func (obj *CronRes) Watch() error { // 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 // again if Watch finds a change occurring to the state. -func (obj *CronRes) CheckApply(apply bool) (checkOK bool, err error) { - ok := true +func (obj *CronRes) CheckApply(apply bool) (bool, error) { + checkOK := true // use the embedded file resource to apply the correct state if c, err := obj.file.CheckApply(apply); err != nil { return false, errwrap.Wrapf(err, "nested file failed") } else if !c { - ok = false + checkOK = false } // check timer state and apply the defined state if needed if c, err := obj.unitCheckApply(apply); err != nil { return false, errwrap.Wrapf(err, "unitCheckApply error") } 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 // 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 godbusConn *dbus.Conn + var err error // this resource depends on systemd to ensure that it's running if !systemdUtil.IsRunningSystemd() { diff --git a/engine/resources/docker_container.go b/engine/resources/docker_container.go index 30494355..b3f85d92 100644 --- a/engine/resources/docker_container.go +++ b/engine/resources/docker_container.go @@ -201,7 +201,7 @@ func (obj *DockerContainerRes) Watch() error { } // 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 destroy bool diff --git a/engine/resources/group.go b/engine/resources/group.go index 01b104fd..0146c70f 100644 --- a/engine/resources/group.go +++ b/engine/resources/group.go @@ -118,7 +118,7 @@ func (obj *GroupRes) Watch() error { } // 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) // check if the group exists diff --git a/engine/resources/hostname.go b/engine/resources/hostname.go index 51147929..b0c9157a 100644 --- a/engine/resources/hostname.go +++ b/engine/resources/hostname.go @@ -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) if err != nil { 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. -func (obj *HostnameRes) CheckApply(apply bool) (checkOK bool, err error) { +func (obj *HostnameRes) CheckApply(apply bool) (bool, error) { conn, err := util.SystemBusPrivateUsable() if err != nil { 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) - checkOK = true + checkOK := true if obj.PrettyHostname != "" { propertyCheckOK, err := obj.updateHostnameProperty(hostnameObject, obj.PrettyHostname, "PrettyHostname", "SetPrettyHostname", apply) if err != nil { diff --git a/engine/resources/kv.go b/engine/resources/kv.go index b0b7f70c..698d69ac 100644 --- a/engine/resources/kv.go +++ b/engine/resources/kv.go @@ -150,7 +150,7 @@ func (obj *KVRes) Watch() error { } // 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 if value == v { // redundant check for safety 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! -func (obj *KVRes) CheckApply(apply bool) (checkOK bool, err error) { +func (obj *KVRes) CheckApply(apply bool) (bool, error) { obj.init.Logf("CheckApply(%t)", apply) if val, exists := obj.init.Recv()["Value"]; exists && val.Changed { diff --git a/engine/resources/mount.go b/engine/resources/mount.go index f39ea5fa..743751a3 100644 --- a/engine/resources/mount.go +++ b/engine/resources/mount.go @@ -275,7 +275,7 @@ func (obj *MountRes) Watch() error { // fstabCheckApply checks /etc/fstab for entries corresponding to the resource // 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) if err != nil { 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 // necessary changes to reach the desired state. This is run before Watch and // again if Watch finds a change occurring to the state. -func (obj *MountRes) CheckApply(apply bool) (checkOK bool, err error) { - checkOK = true +func (obj *MountRes) CheckApply(apply bool) (bool, error) { + checkOK := true if c, err := obj.fstabCheckApply(apply); err != nil { return false, err diff --git a/engine/resources/net.go b/engine/resources/net.go index 276bdd8e..8227acf5 100644 --- a/engine/resources/net.go +++ b/engine/resources/net.go @@ -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 // necessary changes to reach the desired state. This is run before Watch and // again if Watch finds a change occurring to the state. -func (obj *NetRes) CheckApply(apply bool) (checkOK bool, err error) { - checkOK = true +func (obj *NetRes) CheckApply(apply bool) (bool, error) { + checkOK := true // check the network device if c, err := obj.ifaceCheckApply(apply); err != nil { diff --git a/engine/resources/noop.go b/engine/resources/noop.go index 5c162cde..3873dbc6 100644 --- a/engine/resources/noop.go +++ b/engine/resources/noop.go @@ -75,7 +75,7 @@ func (obj *NoopRes) Watch() error { } // 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() { obj.init.Logf("received a notification!") } diff --git a/engine/resources/nspawn.go b/engine/resources/nspawn.go index fbbfc291..8faa9fc5 100644 --- a/engine/resources/nspawn.go +++ b/engine/resources/nspawn.go @@ -201,7 +201,7 @@ func (obj *NspawnRes) Watch() error { // 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 // 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 if !systemdUtil.IsRunningSystemd() { return false, errors.New("systemd is not running") diff --git a/engine/resources/password.go b/engine/resources/password.go index 552f1301..4a941f25 100644 --- a/engine/resources/password.go +++ b/engine/resources/password.go @@ -209,7 +209,7 @@ func (obj *PasswordRes) Watch() error { } // 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 exists = true // does the file (aka the token) exist? var generate bool // do we need to generate a new password? diff --git a/engine/resources/pkg.go b/engine/resources/pkg.go index 5847f9fd..9c9c5af4 100644 --- a/engine/resources/pkg.go +++ b/engine/resources/pkg.go @@ -262,7 +262,7 @@ func (obj *PkgRes) populateFileList() error { // 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. -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())) bus := packagekit.NewBus() diff --git a/engine/resources/print.go b/engine/resources/print.go index ba8d9d25..6d0f48e4 100644 --- a/engine/resources/print.go +++ b/engine/resources/print.go @@ -82,7 +82,7 @@ func (obj *PrintRes) Watch() error { } // 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) if val, exists := obj.init.Recv()["Msg"]; exists && val.Changed { // if we received on Msg, and it changed, log message diff --git a/engine/resources/svc.go b/engine/resources/svc.go index 172c7a43..5af511a3 100644 --- a/engine/resources/svc.go +++ b/engine/resources/svc.go @@ -229,12 +229,13 @@ func (obj *SvcRes) Watch() error { // 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. -func (obj *SvcRes) CheckApply(apply bool) (checkOK bool, err error) { +func (obj *SvcRes) CheckApply(apply bool) (bool, error) { if !systemdUtil.IsRunningSystemd() { return false, fmt.Errorf("systemd is not running") } var conn *systemd.Conn + var err error if obj.Session { conn, err = systemd.NewUserConnection() // user session } else { diff --git a/engine/resources/test.go b/engine/resources/test.go index 54358fe2..ab26b16e 100644 --- a/engine/resources/test.go +++ b/engine/resources/test.go @@ -137,7 +137,7 @@ func (obj *TestRes) Watch() error { } // 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() { obj.init.Logf("CheckApply: Received `%s`, changed: %t", key, val.Changed) } diff --git a/engine/resources/user.go b/engine/resources/user.go index a3235c35..ccaced67 100644 --- a/engine/resources/user.go +++ b/engine/resources/user.go @@ -152,7 +152,7 @@ func (obj *UserRes) Watch() error { } // 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) var exists = true