From deef85cf800364281ee7bb15b838d3c0c4756e91 Mon Sep 17 00:00:00 2001 From: John Sommerville Date: Wed, 9 Feb 2022 15:15:25 -0700 Subject: [PATCH 1/5] syncsettings: change these properties to public --- services/settings/syncsettings.go | 44 +++++++++++++++---------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/services/settings/syncsettings.go b/services/settings/syncsettings.go index d672dd64..16251350 100644 --- a/services/settings/syncsettings.go +++ b/services/settings/syncsettings.go @@ -14,26 +14,26 @@ import ( // SyncSettings is the struct holding sync-settings information type SyncSettings struct { - settingsFile string - defaultsFile string - currentFile string - osForSyncSettings string - tmpSettingsFile string - syncSettingsExecutable string - uidFile string + SettingsFile string + DefaultsFile string + CurrentFile string + OsForSyncSettings string + TmpSettingsFile string + SyncSettingsExecutable string + UidFile string } // NewSyncSettings creates a new settings object func NewSyncSettings(settingsfile string, defaultsfile string, currentfile string, osforsyncsettings string, tmpsettingsfile string, syncsettingsexecutable string, uidfile string) *SyncSettings { s := new(SyncSettings) - s.settingsFile = settingsfile - s.defaultsFile = defaultsfile - s.currentFile = currentfile - s.osForSyncSettings = osforsyncsettings - s.tmpSettingsFile = tmpsettingsfile - s.syncSettingsExecutable = syncsettingsexecutable - s.uidFile = uidfile + s.SettingsFile = settingsfile + s.DefaultsFile = defaultsfile + s.CurrentFile = currentfile + s.OsForSyncSettings = osforsyncsettings + s.TmpSettingsFile = tmpsettingsfile + s.SyncSettingsExecutable = syncsettingsexecutable + s.UidFile = uidfile return s @@ -42,7 +42,7 @@ func NewSyncSettings(settingsfile string, defaultsfile string, currentfile strin // CreateDefaults creates the settings defauls.json file func (s *SyncSettings) CreateDefaults() error { // sync the defaults - cmdArgs := []string{"-o", s.osForSyncSettings, "-c", "-s", "-f", s.tmpSettingsFile} + cmdArgs := []string{"-o", s.OsForSyncSettings, "-c", "-s", "-f", s.TmpSettingsFile} err := s.runSyncSettings(cmdArgs) if err != nil { logger.Warn("Error creating defaults: %s\n", err.Error()) @@ -50,19 +50,19 @@ func (s *SyncSettings) CreateDefaults() error { } // move the defaults. Have to read/write file to avoid docker copy errors - defaultsBytes, readErr := ioutil.ReadFile(s.tmpSettingsFile) + defaultsBytes, readErr := ioutil.ReadFile(s.TmpSettingsFile) if readErr != nil { logger.Warn("Failure copying defaults over: %s\n", readErr.Error()) return readErr } - writeErr := ioutil.WriteFile(s.defaultsFile, defaultsBytes, 0660) + writeErr := ioutil.WriteFile(s.DefaultsFile, defaultsBytes, 0660) if writeErr != nil { logger.Warn("Failure copying defaults over: %s\n", writeErr.Error()) return writeErr } - removeErr := os.Remove(s.tmpSettingsFile) + removeErr := os.Remove(s.TmpSettingsFile) if removeErr != nil { logger.Warn("Could not remove default tmp file: %s. Continueing\n", removeErr.Error()) } @@ -72,7 +72,7 @@ func (s *SyncSettings) CreateDefaults() error { // NormalSync runs sync settings with OS and filename specified func (s *SyncSettings) NormalSync() error { - cmdArgs := []string{"-o", s.osForSyncSettings, "-f", s.settingsFile} + cmdArgs := []string{"-o", s.OsForSyncSettings, "-f", s.SettingsFile} err := s.runSyncSettings(cmdArgs) if err != nil { logger.Warn("Error running sync-settings: %s\n", err.Error()) @@ -83,10 +83,10 @@ func (s *SyncSettings) NormalSync() error { // FirstSyncSettingsRun will create the settings file if it doesn't exist, or rerun sync-settings for good measure func (s *SyncSettings) FirstSyncSettingsRun() error { - cmdArgs := []string{"-o", s.osForSyncSettings, "-n"} + cmdArgs := []string{"-o", s.OsForSyncSettings, "-n"} // check if settings.json exists, if not create it - info, checkErr := os.Stat(s.settingsFile) + info, checkErr := os.Stat(s.SettingsFile) if os.IsNotExist(checkErr) { cmdArgs = append(cmdArgs, "-c") } else if info.IsDir() { @@ -107,7 +107,7 @@ func (s *SyncSettings) FirstSyncSettingsRun() error { // runSyncSettings runs sync settings with given cmd args func (s *SyncSettings) runSyncSettings(cmdArgs []string) error { - cmd := exec.Command(s.syncSettingsExecutable, cmdArgs...) + cmd := exec.Command(s.SyncSettingsExecutable, cmdArgs...) outbytes, err := cmd.CombinedOutput() output := string(outbytes) var runErr error From a9c11a6181782cda8202248123ef15574ff0068e Mon Sep 17 00:00:00 2001 From: John Sommerville Date: Wed, 9 Feb 2022 15:15:36 -0700 Subject: [PATCH 2/5] sync-settings: add SimulateSync function --- services/settings/syncsettings.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/services/settings/syncsettings.go b/services/settings/syncsettings.go index 16251350..bea17a5b 100644 --- a/services/settings/syncsettings.go +++ b/services/settings/syncsettings.go @@ -81,6 +81,20 @@ func (s *SyncSettings) NormalSync() error { return nil } +// Simulate will run sync-settings with simulation flag on the given filePath +// This will not write any files out or restart any services +// but will get the return result as if the file was run properly +func (s *SyncSettings) SimulateSync(filePath string) error { + cmdArgs := []string{"-o", s.OsForSyncSettings, "-s", "-f", filePath} + err := s.runSyncSettings(cmdArgs) + if err != nil { + logger.Warn("Error running sync-settings with simulate flag : %s\n", err.Error()) + return err + } + + return nil +} + // FirstSyncSettingsRun will create the settings file if it doesn't exist, or rerun sync-settings for good measure func (s *SyncSettings) FirstSyncSettingsRun() error { cmdArgs := []string{"-o", s.OsForSyncSettings, "-n"} From 890cb15828fe510fa6f5e931261b945b66f07f73 Mon Sep 17 00:00:00 2001 From: John Sommerville Date: Wed, 9 Feb 2022 15:19:57 -0700 Subject: [PATCH 3/5] syncsettings: simplify "osforsyncsettings" property --- services/settings/syncsettings.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/services/settings/syncsettings.go b/services/settings/syncsettings.go index bea17a5b..0fc37ae1 100644 --- a/services/settings/syncsettings.go +++ b/services/settings/syncsettings.go @@ -17,20 +17,20 @@ type SyncSettings struct { SettingsFile string DefaultsFile string CurrentFile string - OsForSyncSettings string + OS string TmpSettingsFile string SyncSettingsExecutable string UidFile string } // NewSyncSettings creates a new settings object -func NewSyncSettings(settingsfile string, defaultsfile string, currentfile string, osforsyncsettings string, tmpsettingsfile string, syncsettingsexecutable string, uidfile string) *SyncSettings { +func NewSyncSettings(settingsfile string, defaultsfile string, currentfile string, os string, tmpsettingsfile string, syncsettingsexecutable string, uidfile string) *SyncSettings { s := new(SyncSettings) s.SettingsFile = settingsfile s.DefaultsFile = defaultsfile s.CurrentFile = currentfile - s.OsForSyncSettings = osforsyncsettings + s.OS = os s.TmpSettingsFile = tmpsettingsfile s.SyncSettingsExecutable = syncsettingsexecutable s.UidFile = uidfile @@ -42,7 +42,7 @@ func NewSyncSettings(settingsfile string, defaultsfile string, currentfile strin // CreateDefaults creates the settings defauls.json file func (s *SyncSettings) CreateDefaults() error { // sync the defaults - cmdArgs := []string{"-o", s.OsForSyncSettings, "-c", "-s", "-f", s.TmpSettingsFile} + cmdArgs := []string{"-o", s.OS, "-c", "-s", "-f", s.TmpSettingsFile} err := s.runSyncSettings(cmdArgs) if err != nil { logger.Warn("Error creating defaults: %s\n", err.Error()) @@ -72,7 +72,7 @@ func (s *SyncSettings) CreateDefaults() error { // NormalSync runs sync settings with OS and filename specified func (s *SyncSettings) NormalSync() error { - cmdArgs := []string{"-o", s.OsForSyncSettings, "-f", s.SettingsFile} + cmdArgs := []string{"-o", s.OS, "-f", s.SettingsFile} err := s.runSyncSettings(cmdArgs) if err != nil { logger.Warn("Error running sync-settings: %s\n", err.Error()) @@ -85,7 +85,7 @@ func (s *SyncSettings) NormalSync() error { // This will not write any files out or restart any services // but will get the return result as if the file was run properly func (s *SyncSettings) SimulateSync(filePath string) error { - cmdArgs := []string{"-o", s.OsForSyncSettings, "-s", "-f", filePath} + cmdArgs := []string{"-o", s.OS, "-s", "-f", filePath} err := s.runSyncSettings(cmdArgs) if err != nil { logger.Warn("Error running sync-settings with simulate flag : %s\n", err.Error()) @@ -97,7 +97,7 @@ func (s *SyncSettings) SimulateSync(filePath string) error { // FirstSyncSettingsRun will create the settings file if it doesn't exist, or rerun sync-settings for good measure func (s *SyncSettings) FirstSyncSettingsRun() error { - cmdArgs := []string{"-o", s.OsForSyncSettings, "-n"} + cmdArgs := []string{"-o", s.OS, "-n"} // check if settings.json exists, if not create it info, checkErr := os.Stat(s.SettingsFile) From 3ff64626dc7abe976bc329d566dc949b21d7f312 Mon Sep 17 00:00:00 2001 From: John Sommerville Date: Thu, 10 Feb 2022 14:19:36 -0700 Subject: [PATCH 4/5] SimulateSync: fix doc --- services/settings/syncsettings.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/settings/syncsettings.go b/services/settings/syncsettings.go index 0fc37ae1..9c0f3aa0 100644 --- a/services/settings/syncsettings.go +++ b/services/settings/syncsettings.go @@ -81,7 +81,7 @@ func (s *SyncSettings) NormalSync() error { return nil } -// Simulate will run sync-settings with simulation flag on the given filePath +// SimulateSync will run sync-settings with simulation flag on the given filePath // This will not write any files out or restart any services // but will get the return result as if the file was run properly func (s *SyncSettings) SimulateSync(filePath string) error { From 0ca38a680f21e53e25798ad159c22171a081cd04 Mon Sep 17 00:00:00 2001 From: John Sommerville Date: Thu, 10 Feb 2022 14:24:38 -0700 Subject: [PATCH 5/5] SyncSettings: fix struct naming --- services/settings/syncsettings.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/settings/syncsettings.go b/services/settings/syncsettings.go index 9c0f3aa0..7f2c3d63 100644 --- a/services/settings/syncsettings.go +++ b/services/settings/syncsettings.go @@ -20,7 +20,7 @@ type SyncSettings struct { OS string TmpSettingsFile string SyncSettingsExecutable string - UidFile string + UIDFile string } // NewSyncSettings creates a new settings object @@ -33,7 +33,7 @@ func NewSyncSettings(settingsfile string, defaultsfile string, currentfile strin s.OS = os s.TmpSettingsFile = tmpsettingsfile s.SyncSettingsExecutable = syncsettingsexecutable - s.UidFile = uidfile + s.UIDFile = uidfile return s