Remove 99% of deprecated ioutil usage

Signed-off-by: David Gageot <david.gageot@docker.com>
This commit is contained in:
David Gageot
2022-10-07 20:28:10 +02:00
parent 8ef4fa3483
commit d4e132021a
21 changed files with 78 additions and 89 deletions

View File

@@ -2,7 +2,7 @@ package main
import (
"fmt"
"io/ioutil"
"io"
"log"
"net/http"
"os"
@@ -37,7 +37,7 @@ func (p *ProviderOpenstack) Extract() ([]byte, error) {
if err != nil {
return nil, err
}
err = ioutil.WriteFile(path.Join(ConfigPath, Hostname), hostname, 0644)
err = os.WriteFile(path.Join(ConfigPath, Hostname), hostname, 0644)
if err != nil {
return nil, fmt.Errorf("OpenStack: Failed to write hostname: %s", err)
}
@@ -79,7 +79,7 @@ func (p *ProviderOpenstack) Extract() ([]byte, error) {
func openstackMetaGet(lookupName string, fileName string, fileMode os.FileMode) {
if lookupValue, err := openstackGet(metaDataURL + lookupName); err == nil {
// we got a value from the metadata server, now save to filesystem
err = ioutil.WriteFile(path.Join(ConfigPath, fileName), lookupValue, fileMode)
err = os.WriteFile(path.Join(ConfigPath, fileName), lookupValue, fileMode)
if err != nil {
// we couldn't save the file for some reason
log.Printf("OpenStack: Failed to write %s:%s %s", fileName, lookupValue, err)
@@ -108,7 +108,7 @@ func openstackGet(url string) ([]byte, error) {
if resp.StatusCode != 200 {
return nil, fmt.Errorf("OpenStack: Status not ok: %d", resp.StatusCode)
}
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("OpenStack: Failed to read http response: %s", err)
}
@@ -126,7 +126,7 @@ func (p *ProviderOpenstack) handleSSH() error {
return fmt.Errorf("Failed to create %s: %s", SSH, err)
}
err = ioutil.WriteFile(path.Join(ConfigPath, SSH, "authorized_keys"), sshKeys, 0600)
err = os.WriteFile(path.Join(ConfigPath, SSH, "authorized_keys"), sshKeys, 0600)
if err != nil {
return fmt.Errorf("Failed to write ssh keys: %s", err)
}