From 8f81c76dc7696f0393fb982e8b7fefe17416d234 Mon Sep 17 00:00:00 2001 From: dongjiang Date: Tue, 20 Feb 2024 09:46:09 +0800 Subject: [PATCH] [3.1] cherry-pick ioutil replace to release-3.1 (#2597) --- config/config_loader_options.go | 16 ++++---------- config/tls_config.go | 8 +++---- config_center/file/impl.go | 14 ++++-------- config_center/file/listener.go | 14 ++++-------- go.mod | 2 +- go.sum | 9 -------- .../dubbo3/reflection/serverreflection.go | 11 +++------- protocol/jsonrpc/http.go | 12 +++------- protocol/jsonrpc/server.go | 17 +++++--------- remoting/xds/mapping/handler.go | 14 +++++------- remoting/xds/mapping/handler_test.go | 16 +++++--------- xds/client/bootstrap/bootstrap.go | 22 +++++++------------ xds/credentials/cert_manager.go | 10 ++------- xds/credentials/certgenerate/generate_cert.go | 8 +++---- xds/credentials/certgenerate/generate_csr.go | 6 ++--- .../certprovider/pemfile/watcher.go | 15 +++++-------- xds/credentials/token_provider.go | 4 ++-- 17 files changed, 59 insertions(+), 139 deletions(-) diff --git a/config/config_loader_options.go b/config/config_loader_options.go index 03cbe1ff1e..83736a5481 100644 --- a/config/config_loader_options.go +++ b/config/config_loader_options.go @@ -18,26 +18,18 @@ package config import ( - "io/ioutil" "os" "path/filepath" "runtime" "strings" -) -import ( + "dubbo.apache.org/dubbo-go/v3/common/constant" + "dubbo.apache.org/dubbo-go/v3/common/constant/file" "github.com/dubbogo/gost/log/logger" - "github.com/knadh/koanf" - "github.com/pkg/errors" ) -import ( - "dubbo.apache.org/dubbo-go/v3/common/constant" - "dubbo.apache.org/dubbo-go/v3/common/constant/file" -) - type loaderConf struct { suffix string // loaderConf file extension default yaml path string // loaderConf file path default ./conf/dubbogo.yaml @@ -66,7 +58,7 @@ func NewLoaderConf(opts ...LoaderConfOption) *loaderConf { return conf } if len(conf.bytes) <= 0 { - if bytes, err := ioutil.ReadFile(conf.path); err != nil { + if bytes, err := os.ReadFile(conf.path); err != nil { panic(err) } else { conf.bytes = bytes @@ -108,7 +100,7 @@ func WithSuffix(suffix file.Suffix) LoaderConfOption { func WithPath(path string) LoaderConfOption { return loaderConfigFunc(func(conf *loaderConf) { conf.path = absolutePath(path) - if bytes, err := ioutil.ReadFile(conf.path); err != nil { + if bytes, err := os.ReadFile(conf.path); err != nil { panic(err) } else { conf.bytes = bytes diff --git a/config/tls_config.go b/config/tls_config.go index 97c79ec2c9..b5da5ba859 100644 --- a/config/tls_config.go +++ b/config/tls_config.go @@ -20,10 +20,8 @@ package config import ( "crypto/tls" "crypto/x509" - "io/ioutil" -) + "os" -import ( "dubbo.apache.org/dubbo-go/v3/common/constant" ) @@ -50,7 +48,7 @@ func GetServerTlsConfig(opt *TLSConfig) (*tls.Config, error) { //need mTLS if opt.CACertFile != "" { ca = x509.NewCertPool() - caBytes, err := ioutil.ReadFile(opt.CACertFile) + caBytes, err := os.ReadFile(opt.CACertFile) if err != nil { return nil, err } @@ -80,7 +78,7 @@ func GetClientTlsConfig(opt *TLSConfig) (*tls.Config, error) { ServerName: opt.TLSServerName, } ca := x509.NewCertPool() - caBytes, err := ioutil.ReadFile(opt.CACertFile) + caBytes, err := os.ReadFile(opt.CACertFile) if err != nil { return nil, err } diff --git a/config_center/file/impl.go b/config_center/file/impl.go index 2261eba154..061b015877 100644 --- a/config_center/file/impl.go +++ b/config_center/file/impl.go @@ -20,25 +20,19 @@ package file import ( "bytes" "errors" - "io/ioutil" "os" "os/exec" "os/user" "path/filepath" "runtime" "strings" -) -import ( gxset "github.com/dubbogo/gost/container/set" - perrors "github.com/pkg/errors" -) - -import ( "dubbo.apache.org/dubbo-go/v3/common" "dubbo.apache.org/dubbo-go/v3/config_center" "dubbo.apache.org/dubbo-go/v3/config_center/parser" + perrors "github.com/pkg/errors" ) var osType = runtime.GOOS @@ -132,7 +126,7 @@ func (fsdc *FileSystemDynamicConfiguration) GetProperties(key string, opts ...co } tmpPath := fsdc.GetPath(key, tmpOpts.Group) - file, err := ioutil.ReadFile(tmpPath) + file, err := os.ReadFile(tmpPath) if err != nil { return "", perrors.WithStack(err) } @@ -161,7 +155,7 @@ func (fsdc *FileSystemDynamicConfiguration) GetConfigKeysByGroup(group string) ( tmpPath := fsdc.GetPath("", group) r := gxset.NewSet() - fileInfo, _ := ioutil.ReadDir(tmpPath) + fileInfo, _ := os.ReadDir(tmpPath) for _, file := range fileInfo { // list file @@ -217,7 +211,7 @@ func (fsdc *FileSystemDynamicConfiguration) write2File(fp string, value string) return perrors.WithStack(err) } - return ioutil.WriteFile(fp, []byte(value), os.ModePerm) + return os.WriteFile(fp, []byte(value), os.ModePerm) } func forceMkdirParent(fp string) error { diff --git a/config_center/file/listener.go b/config_center/file/listener.go index c68643532e..2a588b2208 100644 --- a/config_center/file/listener.go +++ b/config_center/file/listener.go @@ -18,20 +18,14 @@ package file import ( - "io/ioutil" + "os" "sync" -) - -import ( - "github.com/dubbogo/gost/log/logger" - - "github.com/fsnotify/fsnotify" -) -import ( "dubbo.apache.org/dubbo-go/v3/common/extension" "dubbo.apache.org/dubbo-go/v3/config_center" "dubbo.apache.org/dubbo-go/v3/remoting" + "github.com/dubbogo/gost/log/logger" + "github.com/fsnotify/fsnotify" ) // CacheListener is file watcher @@ -154,7 +148,7 @@ func (cl *CacheListener) RemoveListener(key string, listener config_center.Confi } func getFileContent(path string) string { - c, err := ioutil.ReadFile(path) + c, err := os.ReadFile(path) if err != nil { logger.Errorf("read file path:%s err:%v", path, err) return "" diff --git a/go.mod b/go.mod index afa1845bd4..7490e92cbd 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module dubbo.apache.org/dubbo-go/v3 -go 1.15 +go 1.16 require ( cloud.google.com/go/compute/metadata v0.2.3 // indirect diff --git a/go.sum b/go.sum index 965544e020..820a31f372 100644 --- a/go.sum +++ b/go.sum @@ -470,7 +470,6 @@ github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA github.com/census-instrumentation/opencensus-proto v0.3.0/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/census-instrumentation/opencensus-proto v0.4.1 h1:iKLQ0xPNFxR/2hzXZMrBo8f1j86j5WHzznCCQxV/b8g= github.com/census-instrumentation/opencensus-proto v0.4.1/go.mod h1:4T9NM4+4Vw91VeyqjLS6ao50K5bOcLKN6Q42XnYaRYw= -github.com/certifi/gocertifi v0.0.0-20191021191039-0944d244cd40 h1:xvUo53O5MRZhVMJAxWCJcS5HHrqAiAG9SJ1LpMu6aAI= github.com/certifi/gocertifi v0.0.0-20191021191039-0944d244cd40/go.mod h1:sGbDF6GwGcLpkNXPUTkMRoywsNa/ol15pxFe6ERfguA= github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko= github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= @@ -500,11 +499,8 @@ github.com/cncf/xds/go v0.0.0-20220314180256-7f1daf1720fc/go.mod h1:eXthEFrGJvWH github.com/cncf/xds/go v0.0.0-20230310173818-32f1caf87195 h1:58f1tJ1ra+zFINPlwLWvQsR9CzAKt2e+EWV2yX9oXQ4= github.com/cncf/xds/go v0.0.0-20230310173818-32f1caf87195/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8= -github.com/cockroachdb/datadriven v0.0.0-20200714090401-bf6692d28da5 h1:xD/lrqdvwsc+O2bjSSi3YqY73Ke3LAiSCx49aCesA0E= github.com/cockroachdb/datadriven v0.0.0-20200714090401-bf6692d28da5/go.mod h1:h6jFvWxBdQXxjopDMZyH2UVceIRfR84bdzbkoKrsWNo= -github.com/cockroachdb/errors v1.2.4 h1:Lap807SXTH5tri2TivECb/4abUkMZC9zRoLarvcKDqs= github.com/cockroachdb/errors v1.2.4/go.mod h1:rQD95gz6FARkaKkQXUksEje/d9a6wBJoCr5oaCLELYA= -github.com/cockroachdb/logtags v0.0.0-20190617123548-eb05cc24525f h1:o/kfcElHqOiXqcou5a3rIlMc7oJbMQkeLk0VQJ7zgqY= github.com/cockroachdb/logtags v0.0.0-20190617123548-eb05cc24525f/go.mod h1:i/u985jwjWRlyHXQbwatDASoW0RMlZ/3i9yJHE2xLkI= github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI= github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= @@ -599,7 +595,6 @@ github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMo github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY= github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw= -github.com/getsentry/raven-go v0.2.0 h1:no+xWJRb5ZI7eE8TWgIq1jLulQiIoLG0IfYxv5JYMGs= github.com/getsentry/raven-go v0.2.0/go.mod h1:KungGk8q33+aIAZUIVWZDr2OfAEBsO49PX4NzFV5kcQ= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/go-asn1-ber/asn1-ber v1.3.1/go.mod h1:hEBeB/ic+5LoWskz+yKT7vGhhPYkProFKoKdwZRWMe0= @@ -1380,7 +1375,6 @@ golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRu golang.org/x/lint v0.0.0-20200130185559-910be7a94367/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= -golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 h1:VLliZ0d+/avPrXXH+OakdXhpJuEoBZuwh1m2j7U6Iug= golang.org/x/lint v0.0.0-20210508222113-6edffad5e616/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= @@ -1396,7 +1390,6 @@ golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.7.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= -golang.org/x/mod v0.9.0 h1:KENHtAZL2y3NLMYZeHY9DW8HW8V+kQyJsY/V9JlKvCs= golang.org/x/mod v0.9.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20180530234432-1e491301e022/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -1728,7 +1721,6 @@ golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/tools v0.3.0/go.mod h1:/rWhSS2+zyEVwoJf8YAX6L2f0ntZ7Kn/mGgAWcipA5k= golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= -golang.org/x/tools v0.7.0 h1:W4OVu8VVOaIO0yzWMNdepAulS7YfoS3Zabrm8DOXXU4= golang.org/x/tools v0.7.0/go.mod h1:4pg6aUX35JBAogB10C9AtvVL+qowtN4pT3CGSQex14s= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -1743,7 +1735,6 @@ gonum.org/v1/gonum v0.0.0-20181121035319-3f7ecaa7e8ca/go.mod h1:Y+Yx5eoAFn32cQvJ gonum.org/v1/gonum v0.8.2 h1:CCXrcPKiGGotvnN6jfUsKk4rRqm7q09/YbKb5xCEvtM= gonum.org/v1/gonum v0.8.2/go.mod h1:oe/vMfY3deqTw+1EZJhuvEW2iwGF1bW9wwu7XCu0+v0= gonum.org/v1/netlib v0.0.0-20181029234149-ec6d1f5cefe6/go.mod h1:wa6Ws7BG/ESfp6dHfk7C6KdzKA7wR7u/rKwOGE66zvw= -gonum.org/v1/netlib v0.0.0-20190313105609-8cb42192e0e0 h1:OE9mWmgKkjJyEmDAAtGMPjXu+YNeGvK9VTSHY6+Qihc= gonum.org/v1/netlib v0.0.0-20190313105609-8cb42192e0e0/go.mod h1:wa6Ws7BG/ESfp6dHfk7C6KdzKA7wR7u/rKwOGE66zvw= gonum.org/v1/plot v0.0.0-20190515093506-e2840ee46a6b/go.mod h1:Wt8AAjI+ypCyYX3nZBvf6cAIx93T+c/OS2HFAYskSZc= google.golang.org/api v0.3.1/go.mod h1:6wY9I6uQWHQ8EM57III9mq/AjF+i8G65rmVagqKMtkk= diff --git a/protocol/dubbo3/reflection/serverreflection.go b/protocol/dubbo3/reflection/serverreflection.go index 4d0ff1d185..b5d41df46a 100644 --- a/protocol/dubbo3/reflection/serverreflection.go +++ b/protocol/dubbo3/reflection/serverreflection.go @@ -28,24 +28,19 @@ import ( "compress/gzip" "fmt" "io" - "io/ioutil" "reflect" "sort" "strings" "sync" -) -import ( "github.com/dubbogo/grpc-go" "github.com/dubbogo/grpc-go/codes" "github.com/dubbogo/grpc-go/status" - "github.com/golang/protobuf/proto" - dpb "github.com/golang/protobuf/protoc-gen-go/descriptor" -) -import ( "dubbo.apache.org/dubbo-go/v3/config" + dpb "github.com/golang/protobuf/protoc-gen-go/descriptor" + rpb "dubbo.apache.org/dubbo-go/v3/protocol/dubbo3/reflection/triple_reflection_v1alpha" ) @@ -219,7 +214,7 @@ func decompress(b []byte) ([]byte, error) { if err != nil { return nil, fmt.Errorf("bad gzipped descriptor: %v", err) } - out, err := ioutil.ReadAll(r) + out, err := io.ReadAll(r) if err != nil { return nil, fmt.Errorf("bad gzipped descriptor: %v", err) } diff --git a/protocol/jsonrpc/http.go b/protocol/jsonrpc/http.go index 2a62c46179..3cd31a5558 100644 --- a/protocol/jsonrpc/http.go +++ b/protocol/jsonrpc/http.go @@ -22,7 +22,7 @@ import ( "bytes" "context" "fmt" - "io/ioutil" + "io" "net" "net/http" "net/url" @@ -30,19 +30,13 @@ import ( "strings" "sync/atomic" "time" -) -import ( "github.com/dubbogo/gost/log/logger" - "github.com/opentracing/opentracing-go" - perrors "github.com/pkg/errors" -) - -import ( "dubbo.apache.org/dubbo-go/v3/common" "dubbo.apache.org/dubbo-go/v3/common/constant" + perrors "github.com/pkg/errors" ) // Request is HTTP protocol request @@ -194,7 +188,7 @@ func (c *HTTPClient) Do(addr, path string, httpHeader http.Header, body []byte) } defer httpRsp.Body.Close() - b, err := ioutil.ReadAll(httpRsp.Body) + b, err := io.ReadAll(httpRsp.Body) if err != nil { return nil, perrors.WithStack(err) } diff --git a/protocol/jsonrpc/server.go b/protocol/jsonrpc/server.go index 2b3e9a7699..171aea1b27 100644 --- a/protocol/jsonrpc/server.go +++ b/protocol/jsonrpc/server.go @@ -22,27 +22,20 @@ import ( "bytes" "context" "io" - "io/ioutil" "net" "net/http" "runtime" "runtime/debug" "sync" "time" -) -import ( "github.com/dubbogo/gost/log/logger" - "github.com/opentracing/opentracing-go" - perrors "github.com/pkg/errors" -) - -import ( "dubbo.apache.org/dubbo-go/v3/common" "dubbo.apache.org/dubbo-go/v3/common/constant" "dubbo.apache.org/dubbo-go/v3/protocol/invocation" + perrors "github.com/pkg/errors" ) // A value sent as a placeholder for the server's response value when the server @@ -106,7 +99,7 @@ func (s *Server) handlePkg(conn net.Conn) { ProtoMajor: 1, ProtoMinor: 1, ContentLength: int64(len(body)), - Body: ioutil.NopCloser(bytes.NewReader(body)), + Body: io.NopCloser(bytes.NewReader(body)), } rsp.Header.Del("Content-Type") rsp.Header.Del("Content-Length") @@ -130,7 +123,7 @@ func (s *Server) handlePkg(conn net.Conn) { return } - reqBody, err := ioutil.ReadAll(r.Body) + reqBody, err := io.ReadAll(r.Body) r.Body.Close() if err != nil { return @@ -277,7 +270,7 @@ func serveRequest(ctx context.Context, header map[string]string, body []byte, co ProtoMajor: 1, ProtoMinor: 1, ContentLength: int64(len(body)), - Body: ioutil.NopCloser(bytes.NewReader(body)), + Body: io.NopCloser(bytes.NewReader(body)), } rsp.Header.Del("Content-Type") rsp.Header.Del("Content-Length") @@ -303,7 +296,7 @@ func serveRequest(ctx context.Context, header map[string]string, body []byte, co ProtoMajor: 1, ProtoMinor: 1, ContentLength: int64(len(body)), - Body: ioutil.NopCloser(bytes.NewReader(body)), + Body: io.NopCloser(bytes.NewReader(body)), } rsp.Header.Del("Content-Type") rsp.Header.Del("Content-Length") diff --git a/remoting/xds/mapping/handler.go b/remoting/xds/mapping/handler.go index b306b62b1f..7e11cc247f 100644 --- a/remoting/xds/mapping/handler.go +++ b/remoting/xds/mapping/handler.go @@ -20,23 +20,19 @@ package mapping import ( "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" + "os" "sync" "time" -) -import ( "github.com/dubbogo/gost/log/logger" structpb "github.com/golang/protobuf/ptypes/struct" - perrors "github.com/pkg/errors" -) - -import ( "dubbo.apache.org/dubbo-go/v3/remoting/xds/common" "dubbo.apache.org/dubbo-go/v3/xds/client" + perrors "github.com/pkg/errors" ) const ( @@ -125,7 +121,7 @@ func (i *InterfaceMapHandlerImpl) GetHostAddrMap(serviceUniqueKey string) (strin func (i *InterfaceMapHandlerImpl) getServiceUniqueKeyHostAddrMapFromPilot() (map[string]string, error) { req, _ := http.NewRequest(http.MethodGet, fmt.Sprintf("http://%s/debug/adsz", i.istioDebugAddr.String()), nil) if !i.localDebugMode { - token, err := ioutil.ReadFile(i.istioTokenPath) + token, err := os.ReadFile(i.istioTokenPath) if err != nil { return nil, err } @@ -138,7 +134,7 @@ func (i *InterfaceMapHandlerImpl) getServiceUniqueKeyHostAddrMapFromPilot() (map return nil, err } - data, err := ioutil.ReadAll(rsp.Body) + data, err := io.ReadAll(rsp.Body) if err != nil { return nil, err } diff --git a/remoting/xds/mapping/handler_test.go b/remoting/xds/mapping/handler_test.go index 9e1a0d8c5e..919bc6f420 100644 --- a/remoting/xds/mapping/handler_test.go +++ b/remoting/xds/mapping/handler_test.go @@ -18,23 +18,17 @@ package mapping import ( - "io/ioutil" "net/http" + "os" "testing" "time" -) - -import ( - structpb "github.com/golang/protobuf/ptypes/struct" - - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/mock" -) -import ( "dubbo.apache.org/dubbo-go/v3/common/constant" "dubbo.apache.org/dubbo-go/v3/remoting/xds/common" "dubbo.apache.org/dubbo-go/v3/xds/client/mocks" + structpb "github.com/golang/protobuf/ptypes/struct" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" ) const ( @@ -125,5 +119,5 @@ func getMatchFunction(metadata string) func(abc *structpb.Struct) bool { } func generateMockToken() error { - return ioutil.WriteFile(istioTokenPathFoo, []byte(istioTokenFoo), 0777) + return os.WriteFile(istioTokenPathFoo, []byte(istioTokenFoo), 0777) } diff --git a/xds/client/bootstrap/bootstrap.go b/xds/client/bootstrap/bootstrap.go index 7cc623db95..e0057a4215 100644 --- a/xds/client/bootstrap/bootstrap.go +++ b/xds/client/bootstrap/bootstrap.go @@ -29,30 +29,24 @@ import ( "bytes" "encoding/json" "fmt" - "io/ioutil" + "os" "strings" -) -import ( dubbogoLogger "github.com/dubbogo/gost/log/logger" v2corepb "github.com/envoyproxy/go-control-plane/envoy/api/v2/core" - v3corepb "github.com/envoyproxy/go-control-plane/envoy/config/core/v3" - - "github.com/golang/protobuf/jsonpb" - "github.com/golang/protobuf/proto" - - "google.golang.org/grpc" - "google.golang.org/grpc/credentials/google" - "google.golang.org/grpc/credentials/insecure" -) -import ( "dubbo.apache.org/dubbo-go/v3/xds/client/resource/version" "dubbo.apache.org/dubbo-go/v3/xds/credentials/certprovider" "dubbo.apache.org/dubbo-go/v3/xds/internal" "dubbo.apache.org/dubbo-go/v3/xds/utils/envconfig" "dubbo.apache.org/dubbo-go/v3/xds/utils/pretty" + v3corepb "github.com/envoyproxy/go-control-plane/envoy/config/core/v3" + "github.com/golang/protobuf/jsonpb" + "github.com/golang/protobuf/proto" + "google.golang.org/grpc" + "google.golang.org/grpc/credentials/google" + "google.golang.org/grpc/credentials/insecure" ) const ( @@ -71,7 +65,7 @@ const ( var gRPCVersion = fmt.Sprintf("%s %s", gRPCUserAgentName, grpc.Version) // For overriding in unit tests. -var bootstrapFileReadFunc = ioutil.ReadFile +var bootstrapFileReadFunc = os.ReadFile // ServerConfig contains the configuration to connect to a server, including // URI, creds, and transport API version (e.g. v2 or v3). diff --git a/xds/credentials/cert_manager.go b/xds/credentials/cert_manager.go index d29aeaa4de..9a8b34853c 100644 --- a/xds/credentials/cert_manager.go +++ b/xds/credentials/cert_manager.go @@ -24,18 +24,11 @@ import ( "crypto/x509" "encoding/pem" "fmt" - "io/ioutil" "os" "strconv" "strings" "time" -) -import ( - "github.com/dubbogo/gost/log/logger" -) - -import ( "dubbo.apache.org/dubbo-go/v3/xds/client/bootstrap" "dubbo.apache.org/dubbo-go/v3/xds/credentials/certgenerate" "dubbo.apache.org/dubbo-go/v3/xds/credentials/certprovider" @@ -43,6 +36,7 @@ import ( "dubbo.apache.org/dubbo-go/v3/xds/credentials/certprovider/remote" "dubbo.apache.org/dubbo-go/v3/xds/internal" "dubbo.apache.org/dubbo-go/v3/xds/utils/envconfig" + "github.com/dubbogo/gost/log/logger" ) func init() { @@ -162,7 +156,7 @@ func (c *CACertManager) GetRootCertificate() (*x509.CertPool, error) { // UpdateRoot update root cert func (c *CACertManager) UpdateRoot() error { - rootFileContents, err := ioutil.ReadFile(c.rootPath) + rootFileContents, err := os.ReadFile(c.rootPath) if err != nil { return err } diff --git a/xds/credentials/certgenerate/generate_cert.go b/xds/credentials/certgenerate/generate_cert.go index 8f590be33b..9d2091e119 100644 --- a/xds/credentials/certgenerate/generate_cert.go +++ b/xds/credentials/certgenerate/generate_cert.go @@ -35,13 +35,11 @@ import ( "encoding/pem" "errors" "fmt" - "io/ioutil" "math/big" + "os" "strings" "time" -) -import ( "github.com/dubbogo/gost/log/logger" ) @@ -242,12 +240,12 @@ func GenCertFromCSR(csr *x509.CertificateRequest, signingCert *x509.Certificate, // signerCertFile: cert file name // signerPrivFile: private key file name func LoadSignerCredsFromFiles(signerCertFile string, signerPrivFile string) (*x509.Certificate, crypto.PrivateKey, error) { - signerCertBytes, err := ioutil.ReadFile(signerCertFile) + signerCertBytes, err := os.ReadFile(signerCertFile) if err != nil { return nil, nil, fmt.Errorf("certificate file reading failure (%v)", err) } - signerPrivBytes, err := ioutil.ReadFile(signerPrivFile) + signerPrivBytes, err := os.ReadFile(signerPrivFile) if err != nil { return nil, nil, fmt.Errorf("private key file reading failure (%v)", err) } diff --git a/xds/credentials/certgenerate/generate_csr.go b/xds/credentials/certgenerate/generate_csr.go index 7e1edf0afc..35c9b29770 100644 --- a/xds/credentials/certgenerate/generate_csr.go +++ b/xds/credentials/certgenerate/generate_csr.go @@ -33,11 +33,9 @@ import ( "crypto/x509/pkix" "errors" "fmt" - "io/ioutil" + "os" "strings" -) -import ( "github.com/dubbogo/gost/log/logger" ) @@ -116,7 +114,7 @@ func AppendRootCerts(pemCert []byte, rootCertFile string) ([]byte, error) { rootCerts := pemCert if len(rootCertFile) > 0 { logger.Debugf("append root certificates from %v", rootCertFile) - certBytes, err := ioutil.ReadFile(rootCertFile) + certBytes, err := os.ReadFile(rootCertFile) if err != nil { return rootCerts, fmt.Errorf("failed to read root certificates (%v)", err) } diff --git a/xds/credentials/certprovider/pemfile/watcher.go b/xds/credentials/certprovider/pemfile/watcher.go index 0b1540a8ed..0e04a01813 100644 --- a/xds/credentials/certprovider/pemfile/watcher.go +++ b/xds/credentials/certprovider/pemfile/watcher.go @@ -32,17 +32,12 @@ import ( "crypto/x509" "errors" "fmt" - "io/ioutil" + "os" "path/filepath" "time" -) -import ( - "github.com/dubbogo/grpc-go/grpclog" -) - -import ( "dubbo.apache.org/dubbo-go/v3/xds/credentials/certprovider" + "github.com/dubbogo/grpc-go/grpclog" ) const defaultCertRefreshDuration = 1 * time.Hour @@ -159,12 +154,12 @@ func (w *watcher) updateIdentityDistributor() { return } - certFileContents, err := ioutil.ReadFile(w.opts.CertFile) + certFileContents, err := os.ReadFile(w.opts.CertFile) if err != nil { logger.Warningf("certFile (%s) read failed: %v", w.opts.CertFile, err) return } - keyFileContents, err := ioutil.ReadFile(w.opts.KeyFile) + keyFileContents, err := os.ReadFile(w.opts.KeyFile) if err != nil { logger.Warningf("keyFile (%s) read failed: %v", w.opts.KeyFile, err) return @@ -196,7 +191,7 @@ func (w *watcher) updateRootDistributor() { return } - rootFileContents, err := ioutil.ReadFile(w.opts.RootFile) + rootFileContents, err := os.ReadFile(w.opts.RootFile) if err != nil { logger.Warningf("rootFile (%s) read failed: %v", w.opts.RootFile, err) return diff --git a/xds/credentials/token_provider.go b/xds/credentials/token_provider.go index c6cc713afe..fdcc98bfea 100644 --- a/xds/credentials/token_provider.go +++ b/xds/credentials/token_provider.go @@ -19,7 +19,7 @@ package credentials import ( "context" - "io/ioutil" + "os" ) // provide k8s service account @@ -30,7 +30,7 @@ type saTokenProvider struct { // NewSaTokenProvider return a provider func NewSaTokenProvider(tokenPath string) (*saTokenProvider, error) { - sa, err := ioutil.ReadFile(tokenPath) + sa, err := os.ReadFile(tokenPath) if err != nil { return nil, err }