TUN-7590: Remove usages of ioutil
This commit is contained in:
parent
1b0b6bf7a8
commit
b500e556bf
|
@ -3,7 +3,7 @@ package cfapi
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -49,7 +49,7 @@ func Test_parseListTunnels(t *testing.T) {
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
body := ioutil.NopCloser(bytes.NewReader([]byte(tt.args.body)))
|
body := io.NopCloser(bytes.NewReader([]byte(tt.args.body)))
|
||||||
got, err := parseListTunnels(body)
|
got, err := parseListTunnels(body)
|
||||||
if (err != nil) != tt.wantErr {
|
if (err != nil) != tt.wantErr {
|
||||||
t.Errorf("parseListTunnels() error = %v, wantErr %v", err, tt.wantErr)
|
t.Errorf("parseListTunnels() error = %v, wantErr %v", err, tt.wantErr)
|
||||||
|
|
|
@ -5,7 +5,6 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path"
|
"path"
|
||||||
|
@ -64,7 +63,7 @@ func (st *ServiceTemplate) Generate(args *ServiceTemplateArgs) error {
|
||||||
return fmt.Errorf("error creating %s: %v", plistFolder, err)
|
return fmt.Errorf("error creating %s: %v", plistFolder, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = ioutil.WriteFile(resolvedPath, buffer.Bytes(), fileMode)
|
err = os.WriteFile(resolvedPath, buffer.Bytes(), fileMode)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error writing %s: %v", resolvedPath, err)
|
return fmt.Errorf("error writing %s: %v", resolvedPath, err)
|
||||||
}
|
}
|
||||||
|
@ -103,7 +102,7 @@ func runCommand(command string, args ...string) error {
|
||||||
return fmt.Errorf("error starting %s: %v", command, err)
|
return fmt.Errorf("error starting %s: %v", command, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
output, _ := ioutil.ReadAll(stderr)
|
output, _ := io.ReadAll(stderr)
|
||||||
err = cmd.Wait()
|
err = cmd.Wait()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("%s %v returned with error code %v due to: %v", command, args, err, string(output))
|
return fmt.Errorf("%s %v returned with error code %v due to: %v", command, args, err, string(output))
|
||||||
|
|
|
@ -4,7 +4,6 @@ import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"runtime/trace"
|
"runtime/trace"
|
||||||
|
@ -305,7 +304,7 @@ func StartServer(
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.IsSet("trace-output") {
|
if c.IsSet("trace-output") {
|
||||||
tmpTraceFile, err := ioutil.TempFile("", "trace")
|
tmpTraceFile, err := os.CreateTemp("", "trace")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Err(err).Msg("Failed to create new temporary file to save trace output")
|
log.Err(err).Msg("Failed to create new temporary file to save trace output")
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package tunnel
|
package tunnel
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -23,5 +22,5 @@ func (fs realFileSystem) validFilePath(path string) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fs realFileSystem) readFile(filePath string) ([]byte, error) {
|
func (fs realFileSystem) readFile(filePath string) ([]byte, error) {
|
||||||
return ioutil.ReadFile(filePath)
|
return os.ReadFile(filePath)
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@ package tunnel
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -66,7 +65,7 @@ func login(c *cli.Context) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := ioutil.WriteFile(path, resourceData, 0600); err != nil {
|
if err := os.WriteFile(path, resourceData, 0600); err != nil {
|
||||||
return errors.Wrap(err, fmt.Sprintf("error writing cert to %s", path))
|
return errors.Wrap(err, fmt.Sprintf("error writing cert to %s", path))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,6 @@ import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
@ -241,7 +240,7 @@ func writeTunnelCredentials(filePath string, credentials *connection.Credentials
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "Unable to marshal tunnel credentials to JSON")
|
return errors.Wrap(err, "Unable to marshal tunnel credentials to JSON")
|
||||||
}
|
}
|
||||||
return ioutil.WriteFile(filePath, body, 400)
|
return os.WriteFile(filePath, body, 0400)
|
||||||
}
|
}
|
||||||
|
|
||||||
func buildListCommand() *cli.Command {
|
func buildListCommand() *cli.Command {
|
||||||
|
|
|
@ -11,7 +11,6 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
|
@ -224,7 +223,7 @@ func TestUpdateService(t *testing.T) {
|
||||||
require.Equal(t, v.Version(), mostRecentVersion)
|
require.Equal(t, v.Version(), mostRecentVersion)
|
||||||
|
|
||||||
require.NoError(t, v.Apply())
|
require.NoError(t, v.Apply())
|
||||||
dat, err := ioutil.ReadFile(testFilePath)
|
dat, err := os.ReadFile(testFilePath)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
require.Equal(t, string(dat), mostRecentVersion)
|
require.Equal(t, string(dat), mostRecentVersion)
|
||||||
|
@ -243,7 +242,7 @@ func TestBetaUpdateService(t *testing.T) {
|
||||||
require.Equal(t, v.Version(), mostRecentBetaVersion)
|
require.Equal(t, v.Version(), mostRecentBetaVersion)
|
||||||
|
|
||||||
require.NoError(t, v.Apply())
|
require.NoError(t, v.Apply())
|
||||||
dat, err := ioutil.ReadFile(testFilePath)
|
dat, err := os.ReadFile(testFilePath)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
require.Equal(t, string(dat), mostRecentBetaVersion)
|
require.Equal(t, string(dat), mostRecentBetaVersion)
|
||||||
|
@ -289,7 +288,7 @@ func TestForcedUpdateService(t *testing.T) {
|
||||||
require.Equal(t, v.Version(), mostRecentVersion)
|
require.Equal(t, v.Version(), mostRecentVersion)
|
||||||
|
|
||||||
require.NoError(t, v.Apply())
|
require.NoError(t, v.Apply())
|
||||||
dat, err := ioutil.ReadFile(testFilePath)
|
dat, err := os.ReadFile(testFilePath)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
require.Equal(t, string(dat), mostRecentVersion)
|
require.Equal(t, string(dat), mostRecentVersion)
|
||||||
|
@ -309,7 +308,7 @@ func TestUpdateSpecificVersionService(t *testing.T) {
|
||||||
require.Equal(t, reqVersion, v.Version())
|
require.Equal(t, reqVersion, v.Version())
|
||||||
|
|
||||||
require.NoError(t, v.Apply())
|
require.NoError(t, v.Apply())
|
||||||
dat, err := ioutil.ReadFile(testFilePath)
|
dat, err := os.ReadFile(testFilePath)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
require.Equal(t, reqVersion, string(dat))
|
require.Equal(t, reqVersion, string(dat))
|
||||||
|
@ -328,7 +327,7 @@ func TestCompressedUpdateService(t *testing.T) {
|
||||||
require.Equal(t, "2020.09.02", v.Version())
|
require.Equal(t, "2020.09.02", v.Version())
|
||||||
|
|
||||||
require.NoError(t, v.Apply())
|
require.NoError(t, v.Apply())
|
||||||
dat, err := ioutil.ReadFile(testFilePath)
|
dat, err := os.ReadFile(testFilePath)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
require.Equal(t, "2020.09.02", string(dat))
|
require.Equal(t, "2020.09.02", string(dat))
|
||||||
|
|
|
@ -6,7 +6,6 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
|
@ -84,7 +83,7 @@ func TestHTTP2ConfigurationSet(t *testing.T) {
|
||||||
resp, err := edgeHTTP2Conn.RoundTrip(req)
|
resp, err := edgeHTTP2Conn.RoundTrip(req)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, http.StatusOK, resp.StatusCode)
|
require.Equal(t, http.StatusOK, resp.StatusCode)
|
||||||
bdy, err := ioutil.ReadAll(resp.Body)
|
bdy, err := io.ReadAll(resp.Body)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, `{"lastAppliedVersion":2,"err":null}`, string(bdy))
|
assert.Equal(t, `{"lastAppliedVersion":2,"err":null}`, string(bdy))
|
||||||
cancel()
|
cancel()
|
||||||
|
@ -149,7 +148,7 @@ func TestServeHTTP(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, test.expectedStatus, resp.StatusCode)
|
require.Equal(t, test.expectedStatus, resp.StatusCode)
|
||||||
if test.expectedBody != nil {
|
if test.expectedBody != nil {
|
||||||
respBody, err := ioutil.ReadAll(resp.Body)
|
respBody, err := io.ReadAll(resp.Body)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, test.expectedBody, respBody)
|
require.Equal(t, test.expectedBody, respBody)
|
||||||
}
|
}
|
||||||
|
@ -546,7 +545,7 @@ func benchmarkServeHTTP(b *testing.B, test testRequest) {
|
||||||
require.NoError(b, err)
|
require.NoError(b, err)
|
||||||
require.Equal(b, test.expectedStatus, resp.StatusCode)
|
require.Equal(b, test.expectedStatus, resp.StatusCode)
|
||||||
if test.expectedBody != nil {
|
if test.expectedBody != nil {
|
||||||
respBody, err := ioutil.ReadAll(resp.Body)
|
respBody, err := io.ReadAll(resp.Body)
|
||||||
require.NoError(b, err)
|
require.NoError(b, err)
|
||||||
require.Equal(b, test.expectedBody, respBody)
|
require.Equal(b, test.expectedBody, respBody)
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,6 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
|
@ -652,7 +651,7 @@ func TestHPACK(t *testing.T) {
|
||||||
if stream.Headers[0].Value != "200" {
|
if stream.Headers[0].Value != "200" {
|
||||||
t.Fatalf("expected status 200, got %s", stream.Headers[0].Value)
|
t.Fatalf("expected status 200, got %s", stream.Headers[0].Value)
|
||||||
}
|
}
|
||||||
_, _ = ioutil.ReadAll(stream)
|
_, _ = io.ReadAll(stream)
|
||||||
_ = stream.Close()
|
_ = stream.Close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -905,7 +904,7 @@ func loadSampleFiles(paths []string) (map[string][]byte, error) {
|
||||||
files := make(map[string][]byte)
|
files := make(map[string][]byte)
|
||||||
for _, path := range paths {
|
for _, path := range paths {
|
||||||
if _, ok := files[path]; !ok {
|
if _, ok := files[path]; !ok {
|
||||||
expectBody, err := ioutil.ReadFile(path)
|
expectBody, err := os.ReadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
@ -234,7 +234,7 @@ func rootHandler(serverName string) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
var buffer bytes.Buffer
|
var buffer bytes.Buffer
|
||||||
var body string
|
var body string
|
||||||
rawBody, err := ioutil.ReadAll(r.Body)
|
rawBody, err := io.ReadAll(r.Body)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
body = string(rawBody)
|
body = string(rawBody)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -5,7 +5,6 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
|
@ -118,7 +117,7 @@ func TestSocksStreamWSOverTCPConnection(t *testing.T) {
|
||||||
}
|
}
|
||||||
for _, status := range statusCodes {
|
for _, status := range statusCodes {
|
||||||
handler := func(w http.ResponseWriter, r *http.Request) {
|
handler := func(w http.ResponseWriter, r *http.Request) {
|
||||||
body, err := ioutil.ReadAll(r.Body)
|
body, err := io.ReadAll(r.Body)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, []byte(sendMessage), body)
|
require.Equal(t, []byte(sendMessage), body)
|
||||||
|
|
||||||
|
@ -180,7 +179,7 @@ func TestSocksStreamWSOverTCPConnection(t *testing.T) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, status, resp.StatusCode)
|
assert.Equal(t, status, resp.StatusCode)
|
||||||
require.Equal(t, echoHeaderReturnValue, resp.Header.Get(echoHeaderName))
|
require.Equal(t, echoHeaderReturnValue, resp.Header.Get(echoHeaderName))
|
||||||
body, err := ioutil.ReadAll(resp.Body)
|
body, err := io.ReadAll(resp.Body)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, []byte(echoMessage), body)
|
require.Equal(t, []byte(echoMessage), body)
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ package ingress
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
|
@ -141,7 +141,7 @@ func TestHTTPServiceHostHeaderOverride(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, http.StatusOK, resp.StatusCode)
|
require.Equal(t, http.StatusOK, resp.StatusCode)
|
||||||
|
|
||||||
respBody, err := ioutil.ReadAll(resp.Body)
|
respBody, err := io.ReadAll(resp.Body)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, respBody, []byte(originURL.Host))
|
require.Equal(t, respBody, []byte(originURL.Host))
|
||||||
}
|
}
|
||||||
|
@ -180,7 +180,7 @@ func TestHTTPServiceUsesIngressRuleScheme(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, http.StatusOK, resp.StatusCode)
|
require.Equal(t, http.StatusOK, resp.StatusCode)
|
||||||
|
|
||||||
respBody, err := ioutil.ReadAll(resp.Body)
|
respBody, err := io.ReadAll(resp.Body)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, respBody, []byte(p))
|
require.Equal(t, respBody, []byte(p))
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,6 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
|
@ -338,7 +337,7 @@ func TestConcurrentUpdateAndRead(t *testing.T) {
|
||||||
switch resp.StatusCode {
|
switch resp.StatusCode {
|
||||||
// v1 proxy, warp enabled
|
// v1 proxy, warp enabled
|
||||||
case 200:
|
case 200:
|
||||||
body, err := ioutil.ReadAll(resp.Body)
|
body, err := io.ReadAll(resp.Body)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, t.Name(), string(body))
|
require.Equal(t, t.Name(), string(body))
|
||||||
warpRoutingDisabled = false
|
warpRoutingDisabled = false
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package proxy
|
package proxy
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
|
@ -17,7 +16,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestUnixSocketOrigin(t *testing.T) {
|
func TestUnixSocketOrigin(t *testing.T) {
|
||||||
file, err := ioutil.TempFile("", "unix.sock")
|
file, err := os.CreateTemp("", "unix.sock")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
os.Remove(file.Name()) // remove the file since binding the socket expects to create it
|
os.Remove(file.Name()) // remove the file since binding the socket expects to create it
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ package socks
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -32,7 +32,7 @@ func sendSocksRequest(t *testing.T) []byte {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
b, err := ioutil.ReadAll(resp.Body)
|
b, err := io.ReadAll(resp.Body)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
return b
|
return b
|
||||||
|
|
|
@ -10,9 +10,9 @@ import (
|
||||||
"encoding/pem"
|
"encoding/pem"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/go-jose/go-jose/v3/jwt"
|
"github.com/go-jose/go-jose/v3/jwt"
|
||||||
|
@ -148,7 +148,7 @@ func generateKeyPair(fullName string) ([]byte, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if exist {
|
if exist {
|
||||||
return ioutil.ReadFile(pubKeyName)
|
return os.ReadFile(pubKeyName)
|
||||||
}
|
}
|
||||||
|
|
||||||
key, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
|
key, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
|
||||||
|
@ -187,5 +187,5 @@ func writeKey(filename string, data []byte) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return ioutil.WriteFile(filepath, data, 0600)
|
return os.WriteFile(filepath, data, 0600)
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,6 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
@ -64,7 +63,7 @@ func TestCertGenSuccess(t *testing.T) {
|
||||||
mockRequest = func(url, contentType string, body io.Reader) (*http.Response, error) {
|
mockRequest = func(url, contentType string, body io.Reader) (*http.Response, error) {
|
||||||
assert.Contains(t, "/cdn-cgi/access/cert_sign", url)
|
assert.Contains(t, "/cdn-cgi/access/cert_sign", url)
|
||||||
assert.Equal(t, "application/json", contentType)
|
assert.Equal(t, "application/json", contentType)
|
||||||
buf, err := ioutil.ReadAll(body)
|
buf, err := io.ReadAll(body)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.NotEmpty(t, buf)
|
assert.NotEmpty(t, buf)
|
||||||
return w.Result(), nil
|
return w.Result(), nil
|
||||||
|
|
|
@ -2,7 +2,7 @@ package supervisor
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
@ -72,7 +72,7 @@ func fetchActiveIncidents() (incidents []Incident) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
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 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"crypto/x509"
|
"crypto/x509"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
@ -77,7 +77,7 @@ func LoadOriginCA(originCAPoolFilename string, log *zerolog.Logger) (*x509.CertP
|
||||||
|
|
||||||
if originCAPoolFilename != "" {
|
if originCAPoolFilename != "" {
|
||||||
var err error
|
var err error
|
||||||
originCustomCAPool, err = ioutil.ReadFile(originCAPoolFilename)
|
originCustomCAPool, err = os.ReadFile(originCAPoolFilename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, fmt.Sprintf("unable to read the file %s for --%s", originCAPoolFilename, OriginCAPoolFlag))
|
return nil, errors.Wrap(err, fmt.Sprintf("unable to read the file %s for --%s", originCAPoolFilename, OriginCAPoolFlag))
|
||||||
}
|
}
|
||||||
|
@ -116,7 +116,7 @@ func LoadCustomOriginCA(originCAFilename string) (*x509.CertPool, error) {
|
||||||
return certPool, nil
|
return certPool, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
customOriginCA, err := ioutil.ReadFile(originCAFilename)
|
customOriginCA, err := os.ReadFile(originCAFilename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, fmt.Sprintf("unable to read the file %s", originCAFilename))
|
return nil, errors.Wrap(err, fmt.Sprintf("unable to read the file %s", originCAFilename))
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ package tlsconfig
|
||||||
import (
|
import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"crypto/x509"
|
"crypto/x509"
|
||||||
"io/ioutil"
|
"os"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
@ -90,7 +90,7 @@ func GetConfig(p *TLSParameters) (*tls.Config, error) {
|
||||||
func LoadCert(certPaths []string) (*x509.CertPool, error) {
|
func LoadCert(certPaths []string) (*x509.CertPool, error) {
|
||||||
ca := x509.NewCertPool()
|
ca := x509.NewCertPool()
|
||||||
for _, certPath := range certPaths {
|
for _, certPath := range certPaths {
|
||||||
caCert, err := ioutil.ReadFile(certPath)
|
caCert, err := os.ReadFile(certPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(err, "Error reading certificate %s", certPath)
|
return nil, errors.Wrapf(err, "Error reading certificate %s", certPath)
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
|
@ -124,7 +123,7 @@ func (l *lock) Acquire() error {
|
||||||
|
|
||||||
// Create a lock file so other processes won't also try to get the token at
|
// Create a lock file so other processes won't also try to get the token at
|
||||||
// the same time
|
// the same time
|
||||||
if err := ioutil.WriteFile(l.lockFilePath, []byte{}, 0600); err != nil {
|
if err := os.WriteFile(l.lockFilePath, []byte{}, 0600); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -208,7 +207,7 @@ func getToken(appURL *url.URL, appInfo *AppInfo, useHostOnly bool, log *zerolog.
|
||||||
log.Debug().Msgf("failed to exchange org token for app token: %s", err)
|
log.Debug().Msgf("failed to exchange org token for app token: %s", err)
|
||||||
} else {
|
} else {
|
||||||
// generate app path
|
// generate app path
|
||||||
if err := ioutil.WriteFile(appTokenPath, []byte(appToken), 0600); err != nil {
|
if err := os.WriteFile(appTokenPath, []byte(appToken), 0600); err != nil {
|
||||||
return "", errors.Wrap(err, "failed to write app token to disk")
|
return "", errors.Wrap(err, "failed to write app token to disk")
|
||||||
}
|
}
|
||||||
return appToken, nil
|
return appToken, nil
|
||||||
|
@ -237,12 +236,12 @@ func getTokensFromEdge(appURL *url.URL, appAUD, appTokenPath, orgTokenPath strin
|
||||||
|
|
||||||
// If we were able to get the auth domain and generate an org token path, lets write it to disk.
|
// If we were able to get the auth domain and generate an org token path, lets write it to disk.
|
||||||
if orgTokenPath != "" {
|
if orgTokenPath != "" {
|
||||||
if err := ioutil.WriteFile(orgTokenPath, []byte(resp.OrgToken), 0600); err != nil {
|
if err := os.WriteFile(orgTokenPath, []byte(resp.OrgToken), 0600); err != nil {
|
||||||
return "", errors.Wrap(err, "failed to write org token to disk")
|
return "", errors.Wrap(err, "failed to write org token to disk")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := ioutil.WriteFile(appTokenPath, []byte(resp.AppToken), 0600); err != nil {
|
if err := os.WriteFile(appTokenPath, []byte(resp.AppToken), 0600); err != nil {
|
||||||
return "", errors.Wrap(err, "failed to write app token to disk")
|
return "", errors.Wrap(err, "failed to write app token to disk")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -389,7 +388,7 @@ func GetAppTokenIfExists(appInfo *AppInfo) (string, error) {
|
||||||
|
|
||||||
// GetTokenIfExists will return the token from local storage if it exists and not expired
|
// GetTokenIfExists will return the token from local storage if it exists and not expired
|
||||||
func getTokenIfExists(path string) (*jose.JSONWebSignature, error) {
|
func getTokenIfExists(path string) (*jose.JSONWebSignature, error) {
|
||||||
content, err := ioutil.ReadFile(path)
|
content, err := os.ReadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
@ -105,7 +105,7 @@ func exchangeWireformat(msg []byte, endpoint *url.URL, client *http.Client) ([]b
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read wireformat response from the body
|
// Read wireformat response from the body
|
||||||
buf, err := ioutil.ReadAll(resp.Body)
|
buf, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "failed to read the response body")
|
return nil, errors.Wrap(err, "failed to read the response body")
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ package validation
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -329,7 +329,7 @@ func (f testRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
|
||||||
func emptyResponse(statusCode int) *http.Response {
|
func emptyResponse(statusCode int) *http.Response {
|
||||||
return &http.Response{
|
return &http.Response{
|
||||||
StatusCode: statusCode,
|
StatusCode: statusCode,
|
||||||
Body: ioutil.NopCloser(bytes.NewReader(nil)),
|
Body: io.NopCloser(bytes.NewReader(nil)),
|
||||||
Header: make(http.Header),
|
Header: make(http.Header),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue