mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Handle ioutil deprecations (#53526)
* replace ioutil.ReadFile -> os.ReadFile * replace ioutil.ReadAll -> io.ReadAll * replace ioutil.TempFile -> os.CreateTemp * replace ioutil.NopCloser -> io.NopCloser * replace ioutil.WriteFile -> os.WriteFile * replace ioutil.TempDir -> os.MkdirTemp * replace ioutil.Discard -> io.Discard
This commit is contained in:
@@ -5,7 +5,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
@@ -1124,7 +1124,7 @@ func (s *DryRunRuleStorage) ListChannelRules(_ context.Context, _ int64) ([]pipe
|
||||
|
||||
// HandlePipelineConvertTestHTTP ...
|
||||
func (g *GrafanaLive) HandlePipelineConvertTestHTTP(c *models.ReqContext) response.Response {
|
||||
body, err := ioutil.ReadAll(c.Req.Body)
|
||||
body, err := io.ReadAll(c.Req.Body)
|
||||
if err != nil {
|
||||
return response.Error(http.StatusInternalServerError, "Error reading body", err)
|
||||
}
|
||||
@@ -1169,7 +1169,7 @@ func (g *GrafanaLive) HandlePipelineConvertTestHTTP(c *models.ReqContext) respon
|
||||
|
||||
// HandleChannelRulesPostHTTP ...
|
||||
func (g *GrafanaLive) HandleChannelRulesPostHTTP(c *models.ReqContext) response.Response {
|
||||
body, err := ioutil.ReadAll(c.Req.Body)
|
||||
body, err := io.ReadAll(c.Req.Body)
|
||||
if err != nil {
|
||||
return response.Error(http.StatusInternalServerError, "Error reading body", err)
|
||||
}
|
||||
@@ -1189,7 +1189,7 @@ func (g *GrafanaLive) HandleChannelRulesPostHTTP(c *models.ReqContext) response.
|
||||
|
||||
// HandleChannelRulesPutHTTP ...
|
||||
func (g *GrafanaLive) HandleChannelRulesPutHTTP(c *models.ReqContext) response.Response {
|
||||
body, err := ioutil.ReadAll(c.Req.Body)
|
||||
body, err := io.ReadAll(c.Req.Body)
|
||||
if err != nil {
|
||||
return response.Error(http.StatusInternalServerError, "Error reading body", err)
|
||||
}
|
||||
@@ -1212,7 +1212,7 @@ func (g *GrafanaLive) HandleChannelRulesPutHTTP(c *models.ReqContext) response.R
|
||||
|
||||
// HandleChannelRulesDeleteHTTP ...
|
||||
func (g *GrafanaLive) HandleChannelRulesDeleteHTTP(c *models.ReqContext) response.Response {
|
||||
body, err := ioutil.ReadAll(c.Req.Body)
|
||||
body, err := io.ReadAll(c.Req.Body)
|
||||
if err != nil {
|
||||
return response.Error(http.StatusInternalServerError, "Error reading body", err)
|
||||
}
|
||||
@@ -1259,7 +1259,7 @@ func (g *GrafanaLive) HandleWriteConfigsListHTTP(c *models.ReqContext) response.
|
||||
|
||||
// HandleWriteConfigsPostHTTP ...
|
||||
func (g *GrafanaLive) HandleWriteConfigsPostHTTP(c *models.ReqContext) response.Response {
|
||||
body, err := ioutil.ReadAll(c.Req.Body)
|
||||
body, err := io.ReadAll(c.Req.Body)
|
||||
if err != nil {
|
||||
return response.Error(http.StatusInternalServerError, "Error reading body", err)
|
||||
}
|
||||
@@ -1279,7 +1279,7 @@ func (g *GrafanaLive) HandleWriteConfigsPostHTTP(c *models.ReqContext) response.
|
||||
|
||||
// HandleWriteConfigsPutHTTP ...
|
||||
func (g *GrafanaLive) HandleWriteConfigsPutHTTP(c *models.ReqContext) response.Response {
|
||||
body, err := ioutil.ReadAll(c.Req.Body)
|
||||
body, err := io.ReadAll(c.Req.Body)
|
||||
if err != nil {
|
||||
return response.Error(http.StatusInternalServerError, "Error reading body", err)
|
||||
}
|
||||
@@ -1323,7 +1323,7 @@ func (g *GrafanaLive) HandleWriteConfigsPutHTTP(c *models.ReqContext) response.R
|
||||
|
||||
// HandleWriteConfigsDeleteHTTP ...
|
||||
func (g *GrafanaLive) HandleWriteConfigsDeleteHTTP(c *models.ReqContext) response.Response {
|
||||
body, err := ioutil.ReadAll(c.Req.Body)
|
||||
body, err := io.ReadAll(c.Req.Body)
|
||||
if err != nil {
|
||||
return response.Error(http.StatusInternalServerError, "Error reading body", err)
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package pipeline
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -19,7 +19,7 @@ func loadTestJson(t testing.TB, file string) []byte {
|
||||
t.Helper()
|
||||
// Safe to disable, this is a test.
|
||||
// nolint:gosec
|
||||
content, err := ioutil.ReadFile(filepath.Join("testdata", file+".json"))
|
||||
content, err := os.ReadFile(filepath.Join("testdata", file+".json"))
|
||||
require.NoError(t, err, "expected to be able to read file")
|
||||
require.True(t, len(content) > 0)
|
||||
return content
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
@@ -240,7 +239,7 @@ func (f *FileStorage) readRules() (ChannelRules, error) {
|
||||
ruleFile := f.ruleFilePath()
|
||||
// Safe to ignore gosec warning G304.
|
||||
// nolint:gosec
|
||||
ruleBytes, err := ioutil.ReadFile(ruleFile)
|
||||
ruleBytes, err := os.ReadFile(ruleFile)
|
||||
if err != nil {
|
||||
return ChannelRules{}, fmt.Errorf("can't read pipeline rules: %s: %w", f.ruleFilePath(), err)
|
||||
}
|
||||
@@ -309,7 +308,7 @@ func (f *FileStorage) readWriteConfigs() (WriteConfigs, error) {
|
||||
filePath := f.writeConfigsFilePath()
|
||||
// Safe to ignore gosec warning G304.
|
||||
// nolint:gosec
|
||||
bytes, err := ioutil.ReadFile(filePath)
|
||||
bytes, err := os.ReadFile(filePath)
|
||||
if err != nil {
|
||||
return WriteConfigs{}, fmt.Errorf("can't read %s file: %w", filePath, err)
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
@@ -18,7 +18,7 @@ func loadTestData(tb testing.TB, file string) []byte {
|
||||
tb.Helper()
|
||||
// Safe to disable, this is a test.
|
||||
// nolint:gosec
|
||||
content, err := ioutil.ReadFile(filepath.Join("testdata", file+".txt"))
|
||||
content, err := os.ReadFile(filepath.Join("testdata", file+".txt"))
|
||||
require.NoError(tb, err, "expected to be able to read file")
|
||||
require.True(tb, len(content) > 0)
|
||||
return content
|
||||
@@ -28,7 +28,7 @@ func checkTestData(t *testing.T, file string) *backend.DataResponse {
|
||||
t.Helper()
|
||||
// Safe to disable, this is a test.
|
||||
// nolint:gosec
|
||||
content, err := ioutil.ReadFile(filepath.Join("testdata", file+".txt"))
|
||||
content, err := os.ReadFile(filepath.Join("testdata", file+".txt"))
|
||||
require.NoError(t, err, "expected to be able to read file")
|
||||
require.True(t, len(content) > 0)
|
||||
|
||||
@@ -143,13 +143,13 @@ func TestConverter_Convert_NumFrameFields(t *testing.T) {
|
||||
frameJSON, err := json.MarshalIndent(frame, "", " ")
|
||||
require.NoError(t, err)
|
||||
if *update {
|
||||
if err := ioutil.WriteFile(goldenFile, frameJSON, 0600); err != nil {
|
||||
if err := os.WriteFile(goldenFile, frameJSON, 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
// Safe to disable, this is a test.
|
||||
// nolint:gosec
|
||||
want, err := ioutil.ReadFile(goldenFile)
|
||||
want, err := os.ReadFile(goldenFile)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -223,13 +223,13 @@ func TestConverter_Convert_NumFrameFields_LabelsColumn(t *testing.T) {
|
||||
frameJSON, err := json.MarshalIndent(frame, "", " ")
|
||||
require.NoError(t, err)
|
||||
if *update {
|
||||
if err := ioutil.WriteFile(goldenFile, frameJSON, 0600); err != nil {
|
||||
if err := os.WriteFile(goldenFile, frameJSON, 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
// Safe to disable, this is a test.
|
||||
// nolint:gosec
|
||||
want, err := ioutil.ReadFile(goldenFile)
|
||||
want, err := os.ReadFile(goldenFile)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user