Fix deprecation io/ioutil

This commit is contained in:
gavrilov.nikita 2024-03-10 22:07:19 +03:00
parent a90b270dc5
commit 741a6748fd
5 changed files with 14 additions and 17 deletions

View File

@ -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)
}

View File

@ -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")

View File

@ -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 {

View File

@ -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

View File

@ -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() {