1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-25 08:19:40 +02:00

fix(code): replace calls to ioutil EE-4425 (#7878)

This commit is contained in:
andres-portainer 2022-10-17 15:29:12 -03:00 committed by GitHub
parent 69f498c431
commit 5488389278
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
48 changed files with 109 additions and 112 deletions

View file

@ -5,7 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/url"
"strings"
@ -96,7 +96,7 @@ func Get(url string, timeout int) ([]byte, error) {
return nil, errInvalidResponseStatus
}
body, err := ioutil.ReadAll(response.Body)
body, err := io.ReadAll(response.Body)
if err != nil {
return nil, err
}

View file

@ -4,7 +4,6 @@ import (
"bytes"
"context"
"io"
"io/ioutil"
"net/http"
"net/http/httptest"
"os"
@ -38,7 +37,7 @@ func listFiles(dir string) []string {
func contains(t *testing.T, list []string, path string) {
assert.Contains(t, list, path)
copyContent, _ := ioutil.ReadFile(path)
copyContent, _ := os.ReadFile(path)
assert.Equal(t, "content\n", string(copyContent))
}
@ -58,7 +57,7 @@ func Test_backupHandlerWithoutPassword_shouldCreateATarballArchive(t *testing.T)
tmpdir := t.TempDir()
archivePath := filepath.Join(tmpdir, "archive.tar.gz")
err := ioutil.WriteFile(archivePath, body, 0600)
err := os.WriteFile(archivePath, body, 0600)
if err != nil {
t.Fatal("Failed to save downloaded .tar.gz archive: ", err)
}

View file

@ -1,7 +1,7 @@
package edgegroups
import (
"github.com/portainer/portainer/api"
portainer "github.com/portainer/portainer/api"
)
type endpointSetType map[portainer.EndpointID]bool

View file

@ -2,7 +2,6 @@ package helm
import (
"fmt"
"io/ioutil"
"net/http"
"os"
"strings"
@ -192,7 +191,7 @@ func (handler *Handler) updateHelmAppManifest(r *http.Request, manifest []byte,
for _, resource := range yamlResources {
resource := resource // https://golang.org/doc/faq#closures_and_goroutines
g.Go(func() error {
tmpfile, err := ioutil.TempFile("", "helm-manifest-*")
tmpfile, err := os.CreateTemp("", "helm-manifest-*")
if err != nil {
return errors.Wrap(err, "failed to create a tmp helm manifest file")
}

View file

@ -4,7 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"time"
@ -139,7 +139,7 @@ func pullImage(ctx context.Context, docker *client.Client, imageName string) err
}
defer out.Close()
outputBytes, err := ioutil.ReadAll(out)
outputBytes, err := io.ReadAll(out)
if err != nil {
log.Error().Str("image_name", imageName).Err(err).Msg("could not read image pull output")
@ -261,7 +261,7 @@ func runContainer(ctx context.Context, docker *client.Client, imageName, contain
return "", err
}
outputBytes, err := ioutil.ReadAll(out)
outputBytes, err := io.ReadAll(out)
if err != nil {
log.Error().
Str("image_name", imageName).

View file

@ -3,7 +3,6 @@ package stacks
import (
"context"
"fmt"
"io/ioutil"
"net/http"
"os"
"strconv"
@ -200,7 +199,7 @@ func (handler *Handler) deleteStack(userID portainer.UserID, stack *portainer.St
//then process the remove operation
if stack.IsComposeFormat {
fileNames := stackutils.GetStackFilePaths(stack, false)
tmpDir, err := ioutil.TempDir("", "kube_delete")
tmpDir, err := os.MkdirTemp("", "kube_delete")
if err != nil {
return errors.Wrap(err, "failed to create temp directory for deleting kub stack")
}

View file

@ -2,7 +2,6 @@ package stacks
import (
"fmt"
"io/ioutil"
"net/http"
"os"
"strconv"
@ -105,7 +104,7 @@ func (handler *Handler) updateKubernetesStack(r *http.Request, stack *portainer.
return httperror.BadRequest("Failed to retrieve user token data", err)
}
tempFileDir, _ := ioutil.TempDir("", "kub_file_content")
tempFileDir, _ := os.MkdirTemp("", "kub_file_content")
defer os.RemoveAll(tempFileDir)
if err := filesystem.WriteToFile(filesystem.JoinPaths(tempFileDir, stack.EntryPoint), []byte(payload.StackFileContent)); err != nil {

View file

@ -2,7 +2,7 @@ package upload
import (
httperror "github.com/portainer/libhttp/error"
"github.com/portainer/portainer/api"
portainer "github.com/portainer/portainer/api"
"github.com/portainer/portainer/api/http/security"
"net/http"

View file

@ -1,9 +1,10 @@
package users
import (
"github.com/portainer/portainer/api/dataservices/errors"
"net/http"
"github.com/portainer/portainer/api/dataservices/errors"
httperror "github.com/portainer/libhttp/error"
"github.com/portainer/libhttp/response"
portainer "github.com/portainer/portainer/api"

View file

@ -2,9 +2,10 @@ package webhooks
import (
"errors"
"github.com/portainer/portainer/api/http/security"
"net/http"
"github.com/portainer/portainer/api/http/security"
httperror "github.com/portainer/libhttp/error"
"github.com/portainer/libhttp/request"
"github.com/portainer/libhttp/response"

View file

@ -3,11 +3,12 @@ package webhooks
import (
"context"
"errors"
"github.com/portainer/portainer/api/internal/registryutils"
"io"
"net/http"
"strings"
"github.com/portainer/portainer/api/internal/registryutils"
dockertypes "github.com/docker/docker/api/types"
httperror "github.com/portainer/libhttp/error"
"github.com/portainer/libhttp/request"

View file

@ -1,9 +1,10 @@
package webhooks
import (
"github.com/portainer/portainer/api/http/security"
"net/http"
"github.com/portainer/portainer/api/http/security"
httperror "github.com/portainer/libhttp/error"
"github.com/portainer/libhttp/request"
"github.com/portainer/libhttp/response"

View file

@ -4,8 +4,9 @@
package websocket
import (
"github.com/Microsoft/go-winio"
"net"
"github.com/Microsoft/go-winio"
)
func createDial(scheme, host string) (net.Conn, error) {

View file

@ -5,7 +5,7 @@ import (
"net"
"net/url"
"github.com/portainer/portainer/api"
portainer "github.com/portainer/portainer/api"
"github.com/portainer/portainer/api/crypto"
)

View file

@ -8,7 +8,7 @@ import (
"github.com/gorilla/websocket"
"github.com/koding/websocketproxy"
"github.com/portainer/portainer/api"
portainer "github.com/portainer/portainer/api"
)
func (handler *Handler) proxyEdgeAgentWebsocketRequest(w http.ResponseWriter, r *http.Request, params *webSocketRequestParams) error {

View file

@ -1,6 +1,6 @@
package websocket
import "github.com/portainer/portainer/api"
import portainer "github.com/portainer/portainer/api"
type webSocketRequestParams struct {
ID string

View file

@ -4,7 +4,7 @@ import (
"bytes"
"encoding/json"
"errors"
"io/ioutil"
"io"
"mime"
"net/http"
@ -37,7 +37,7 @@ func buildOperation(request *http.Request) error {
var buffer []byte
switch mediaType {
case "":
body, err := ioutil.ReadAll(request.Body)
body, err := io.ReadAll(request.Body)
if err != nil {
return err
}
@ -81,7 +81,7 @@ func buildOperation(request *http.Request) error {
log.Info().Str("filename", hdr.Filename).Int64("size", hdr.Size).Msg("upload the file to build image")
content, err := ioutil.ReadAll(f)
content, err := io.ReadAll(f)
if err != nil {
return err
}
@ -105,7 +105,7 @@ func buildOperation(request *http.Request) error {
return nil
}
request.Body = ioutil.NopCloser(bytes.NewReader(buffer))
request.Body = io.NopCloser(bytes.NewReader(buffer))
request.ContentLength = int64(len(buffer))
request.Header.Set("Content-Type", "application/x-tar")

View file

@ -5,7 +5,7 @@ import (
"context"
"encoding/json"
"errors"
"io/ioutil"
"io"
"net/http"
"strings"
@ -190,7 +190,7 @@ func (transport *Transport) decorateContainerCreationOperation(request *http.Req
return nil, err
}
body, err := ioutil.ReadAll(request.Body)
body, err := io.ReadAll(request.Body)
if err != nil {
return nil, err
}
@ -229,7 +229,7 @@ func (transport *Transport) decorateContainerCreationOperation(request *http.Req
}
}
request.Body = ioutil.NopCloser(bytes.NewBuffer(body))
request.Body = io.NopCloser(bytes.NewBuffer(body))
}
response, err := transport.executeDockerRequest(request)

View file

@ -5,7 +5,7 @@ import (
"context"
"encoding/json"
"errors"
"io/ioutil"
"io"
"net/http"
"github.com/docker/docker/api/types"
@ -116,7 +116,7 @@ func (transport *Transport) decorateServiceCreationOperation(request *http.Reque
return nil, err
}
body, err := ioutil.ReadAll(request.Body)
body, err := io.ReadAll(request.Body)
if err != nil {
return nil, err
}
@ -135,7 +135,7 @@ func (transport *Transport) decorateServiceCreationOperation(request *http.Reque
}
}
request.Body = ioutil.NopCloser(bytes.NewBuffer(body))
request.Body = io.NopCloser(bytes.NewBuffer(body))
}
return transport.replaceRegistryAuthenticationHeader(request)

View file

@ -6,7 +6,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"net/http"
"path"
"regexp"
@ -197,7 +197,7 @@ func (transport *Transport) proxyAgentRequest(r *http.Request) (*http.Response,
r.Method = http.MethodPost
r.Body = ioutil.NopCloser(bytes.NewReader(newBody))
r.Body = io.NopCloser(bytes.NewReader(newBody))
r.ContentLength = int64(len(newBody))
}

View file

@ -1,7 +1,7 @@
package kubernetes
import (
"io/ioutil"
"os"
portainer "github.com/portainer/portainer/api"
"github.com/portainer/portainer/api/dataservices"
@ -28,7 +28,7 @@ func NewTokenManager(kubecli portainer.KubeClient, dataStore dataservices.DataSt
}
if setLocalAdminToken {
token, err := ioutil.ReadFile(defaultServiceAccountTokenFile)
token, err := os.ReadFile(defaultServiceAccountTokenFile)
if err != nil {
return nil, err
}

View file

@ -4,7 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"path"
"regexp"
@ -189,7 +189,7 @@ func decorateAgentDockerHubRequest(r *http.Request, dataStore dataservices.DataS
}
r.Method = http.MethodPost
r.Body = ioutil.NopCloser(bytes.NewReader(newBody))
r.Body = io.NopCloser(bytes.NewReader(newBody))
r.ContentLength = int64(len(newBody))
return nil

View file

@ -6,7 +6,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"mime"
"gopkg.in/yaml.v3"
@ -50,7 +49,7 @@ func getBody(body io.ReadCloser, contentType string, isGzip bool) (interface{},
defer reader.Close()
bodyBytes, err := ioutil.ReadAll(reader)
bodyBytes, err := io.ReadAll(reader)
if err != nil {
return nil, err
}

View file

@ -2,7 +2,7 @@ package utils
import (
"bytes"
"io/ioutil"
"io"
"net/http"
"strconv"
)
@ -25,7 +25,7 @@ func RewriteRequest(request *http.Request, newData interface{}) error {
return err
}
body := ioutil.NopCloser(bytes.NewReader(data))
body := io.NopCloser(bytes.NewReader(data))
request.Body = body
request.ContentLength = int64(len(data))

View file

@ -3,7 +3,7 @@ package utils
import (
"bytes"
"fmt"
"io/ioutil"
"io"
"net/http"
"strconv"
@ -82,7 +82,7 @@ func RewriteResponse(response *http.Response, newResponseData interface{}, statu
return err
}
body := ioutil.NopCloser(bytes.NewReader(data))
body := io.NopCloser(bytes.NewReader(data))
response.StatusCode = statusCode
response.Body = body