From 741a6748fdf24d93f7e84cfe1ad87851d0ac8991 Mon Sep 17 00:00:00 2001 From: "gavrilov.nikita" Date: Sun, 10 Mar 2024 22:07:19 +0300 Subject: [PATCH] Fix deprecation io/ioutil --- cli/setup/setup.go | 3 +-- db/AccessKey.go | 11 +++++------ db_lib/AnsibleApp.go | 5 ++--- services/runners/JobPool.go | 8 ++++---- services/tasks/LobalJob_inventory.go | 4 ++-- 5 files changed, 14 insertions(+), 17 deletions(-) diff --git a/cli/setup/setup.go b/cli/setup/setup.go index db7c6c5f..039d6ec5 100644 --- a/cli/setup/setup.go +++ b/cli/setup/setup.go @@ -2,7 +2,6 @@ package setup import ( "fmt" - "io/ioutil" "os" "path/filepath" "strings" @@ -156,7 +155,7 @@ func SaveConfig(config *util.ConfigType) (configPath string) { } configPath = filepath.Join(configDirectory, "config.json") - if err = ioutil.WriteFile(configPath, bytes, 0644); err != nil { + if err = os.WriteFile(configPath, bytes, 0644); err != nil { panic(err) } diff --git a/db/AccessKey.go b/db/AccessKey.go index 67239047..45aa126a 100644 --- a/db/AccessKey.go +++ b/db/AccessKey.go @@ -9,7 +9,6 @@ import ( "fmt" "github.com/ansible-semaphore/semaphore/lib" "io" - "io/ioutil" "math/big" "os" "path" @@ -132,12 +131,12 @@ func (key *AccessKey) Install(usage AccessKeyRole, logger lib.Logger) (installat agent, err = key.startSshAgent(logger) installation.SshAgent = &agent - //err = ioutil.WriteFile(installationPath, []byte(key.SshKey.PrivateKey+"\n"), 0600) + //err = os.WriteFile(installationPath, []byte(key.SshKey.PrivateKey+"\n"), 0600) } case AccessKeyRoleAnsiblePasswordVault: switch key.Type { case AccessKeyLoginPassword: - err = ioutil.WriteFile(installationPath, []byte(key.LoginPassword.Password), 0600) + err = os.WriteFile(installationPath, []byte(key.LoginPassword.Password), 0600) } case AccessKeyRoleAnsibleBecomeUser: switch key.Type { @@ -152,7 +151,7 @@ func (key *AccessKey) Install(usage AccessKeyRole, logger lib.Logger) (installat if err != nil { return } - err = ioutil.WriteFile(installationPath, bytes, 0600) + err = os.WriteFile(installationPath, bytes, 0600) default: err = fmt.Errorf("access key type not supported for ansible user") } @@ -162,7 +161,7 @@ func (key *AccessKey) Install(usage AccessKeyRole, logger lib.Logger) (installat var agent lib.SshAgent agent, err = key.startSshAgent(logger) installation.SshAgent = &agent - //err = ioutil.WriteFile(installationPath, []byte(key.SshKey.PrivateKey+"\n"), 0600) + //err = os.WriteFile(installationPath, []byte(key.SshKey.PrivateKey+"\n"), 0600) case AccessKeyLoginPassword: content := make(map[string]string) content["ansible_user"] = key.LoginPassword.Login @@ -172,7 +171,7 @@ func (key *AccessKey) Install(usage AccessKeyRole, logger lib.Logger) (installat if err != nil { return } - err = ioutil.WriteFile(installationPath, bytes, 0600) + err = os.WriteFile(installationPath, bytes, 0600) default: err = fmt.Errorf("access key type not supported for ansible user") diff --git a/db_lib/AnsibleApp.go b/db_lib/AnsibleApp.go index 601280c1..f685a735 100644 --- a/db_lib/AnsibleApp.go +++ b/db_lib/AnsibleApp.go @@ -6,7 +6,6 @@ import ( "github.com/ansible-semaphore/semaphore/db" "github.com/ansible-semaphore/semaphore/lib" "io" - "io/ioutil" "os" "path" ) @@ -26,7 +25,7 @@ func getMD5Hash(filepath string) (string, error) { } func hasRequirementsChanges(requirementsFilePath string, requirementsHashFilePath string) bool { - oldFileMD5HashBytes, err := ioutil.ReadFile(requirementsHashFilePath) + oldFileMD5HashBytes, err := os.ReadFile(requirementsHashFilePath) if err != nil { return true } @@ -45,7 +44,7 @@ func writeMD5Hash(requirementsFile string, requirementsHashFile string) error { return err } - return ioutil.WriteFile(requirementsHashFile, []byte(newFileMD5Hash), 0644) + return os.WriteFile(requirementsHashFile, []byte(newFileMD5Hash), 0644) } type AnsibleApp struct { diff --git a/services/runners/JobPool.go b/services/runners/JobPool.go index 00ea6b5c..76d6904f 100644 --- a/services/runners/JobPool.go +++ b/services/runners/JobPool.go @@ -10,13 +10,13 @@ import ( "bytes" "encoding/json" "fmt" - log "github.com/sirupsen/logrus" "github.com/ansible-semaphore/semaphore/db" "github.com/ansible-semaphore/semaphore/db_lib" "github.com/ansible-semaphore/semaphore/lib" "github.com/ansible-semaphore/semaphore/services/tasks" "github.com/ansible-semaphore/semaphore/util" - "io/ioutil" + log "github.com/sirupsen/logrus" + "io" "net/http" "os" "os/exec" @@ -388,7 +388,7 @@ func (p *JobPool) tryRegisterRunner() bool { return false } - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { fmt.Println("Error reading response body:", err) return false @@ -446,7 +446,7 @@ func (p *JobPool) checkNewJobs() { defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { log.Error("Checking new jobs, error reading response body:", err) return diff --git a/services/tasks/LobalJob_inventory.go b/services/tasks/LobalJob_inventory.go index c5aeb005..0b72d631 100644 --- a/services/tasks/LobalJob_inventory.go +++ b/services/tasks/LobalJob_inventory.go @@ -2,7 +2,7 @@ package tasks import ( "github.com/ansible-semaphore/semaphore/db" - "io/ioutil" + "os" "strconv" "github.com/ansible-semaphore/semaphore/util" @@ -39,7 +39,7 @@ func (t *LocalJob) installStaticInventory() error { } // create inventory file - return ioutil.WriteFile(path, []byte(t.Inventory.Inventory), 0664) + return os.WriteFile(path, []byte(t.Inventory.Inventory), 0664) } func (t *LocalJob) destroyKeys() {