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 ( import (
"fmt" "fmt"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
@ -156,7 +155,7 @@ func SaveConfig(config *util.ConfigType) (configPath string) {
} }
configPath = filepath.Join(configDirectory, "config.json") 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) panic(err)
} }

View File

@ -9,7 +9,6 @@ import (
"fmt" "fmt"
"github.com/ansible-semaphore/semaphore/lib" "github.com/ansible-semaphore/semaphore/lib"
"io" "io"
"io/ioutil"
"math/big" "math/big"
"os" "os"
"path" "path"
@ -132,12 +131,12 @@ func (key *AccessKey) Install(usage AccessKeyRole, logger lib.Logger) (installat
agent, err = key.startSshAgent(logger) agent, err = key.startSshAgent(logger)
installation.SshAgent = &agent 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: case AccessKeyRoleAnsiblePasswordVault:
switch key.Type { switch key.Type {
case AccessKeyLoginPassword: case AccessKeyLoginPassword:
err = ioutil.WriteFile(installationPath, []byte(key.LoginPassword.Password), 0600) err = os.WriteFile(installationPath, []byte(key.LoginPassword.Password), 0600)
} }
case AccessKeyRoleAnsibleBecomeUser: case AccessKeyRoleAnsibleBecomeUser:
switch key.Type { switch key.Type {
@ -152,7 +151,7 @@ func (key *AccessKey) Install(usage AccessKeyRole, logger lib.Logger) (installat
if err != nil { if err != nil {
return return
} }
err = ioutil.WriteFile(installationPath, bytes, 0600) err = os.WriteFile(installationPath, bytes, 0600)
default: default:
err = fmt.Errorf("access key type not supported for ansible user") 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 var agent lib.SshAgent
agent, err = key.startSshAgent(logger) agent, err = key.startSshAgent(logger)
installation.SshAgent = &agent 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: case AccessKeyLoginPassword:
content := make(map[string]string) content := make(map[string]string)
content["ansible_user"] = key.LoginPassword.Login content["ansible_user"] = key.LoginPassword.Login
@ -172,7 +171,7 @@ func (key *AccessKey) Install(usage AccessKeyRole, logger lib.Logger) (installat
if err != nil { if err != nil {
return return
} }
err = ioutil.WriteFile(installationPath, bytes, 0600) err = os.WriteFile(installationPath, bytes, 0600)
default: default:
err = fmt.Errorf("access key type not supported for ansible user") 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/db"
"github.com/ansible-semaphore/semaphore/lib" "github.com/ansible-semaphore/semaphore/lib"
"io" "io"
"io/ioutil"
"os" "os"
"path" "path"
) )
@ -26,7 +25,7 @@ func getMD5Hash(filepath string) (string, error) {
} }
func hasRequirementsChanges(requirementsFilePath string, requirementsHashFilePath string) bool { func hasRequirementsChanges(requirementsFilePath string, requirementsHashFilePath string) bool {
oldFileMD5HashBytes, err := ioutil.ReadFile(requirementsHashFilePath) oldFileMD5HashBytes, err := os.ReadFile(requirementsHashFilePath)
if err != nil { if err != nil {
return true return true
} }
@ -45,7 +44,7 @@ func writeMD5Hash(requirementsFile string, requirementsHashFile string) error {
return err return err
} }
return ioutil.WriteFile(requirementsHashFile, []byte(newFileMD5Hash), 0644) return os.WriteFile(requirementsHashFile, []byte(newFileMD5Hash), 0644)
} }
type AnsibleApp struct { type AnsibleApp struct {

View File

@ -10,13 +10,13 @@ import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"fmt" "fmt"
log "github.com/sirupsen/logrus"
"github.com/ansible-semaphore/semaphore/db" "github.com/ansible-semaphore/semaphore/db"
"github.com/ansible-semaphore/semaphore/db_lib" "github.com/ansible-semaphore/semaphore/db_lib"
"github.com/ansible-semaphore/semaphore/lib" "github.com/ansible-semaphore/semaphore/lib"
"github.com/ansible-semaphore/semaphore/services/tasks" "github.com/ansible-semaphore/semaphore/services/tasks"
"github.com/ansible-semaphore/semaphore/util" "github.com/ansible-semaphore/semaphore/util"
"io/ioutil" log "github.com/sirupsen/logrus"
"io"
"net/http" "net/http"
"os" "os"
"os/exec" "os/exec"
@ -388,7 +388,7 @@ func (p *JobPool) tryRegisterRunner() bool {
return false return false
} }
body, err := ioutil.ReadAll(resp.Body) body, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
fmt.Println("Error reading response body:", err) fmt.Println("Error reading response body:", err)
return false return false
@ -446,7 +446,7 @@ func (p *JobPool) checkNewJobs() {
defer resp.Body.Close() defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body) body, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
log.Error("Checking new jobs, error reading response body:", err) log.Error("Checking new jobs, error reading response body:", err)
return return

View File

@ -2,7 +2,7 @@ package tasks
import ( import (
"github.com/ansible-semaphore/semaphore/db" "github.com/ansible-semaphore/semaphore/db"
"io/ioutil" "os"
"strconv" "strconv"
"github.com/ansible-semaphore/semaphore/util" "github.com/ansible-semaphore/semaphore/util"
@ -39,7 +39,7 @@ func (t *LocalJob) installStaticInventory() error {
} }
// create inventory file // 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() { func (t *LocalJob) destroyKeys() {