update libs

This commit is contained in:
d1slike committed 2020-06-02 14:52:24 +03:00
1 parent 48cbb5c25d
commit b1c16e4901
22 files changed
+301 -204

No files matched your search

+3 -21
View File
@@ -3,16 +3,11 @@ package grpc
import (
"github.com/integration-system/isp-lib/v2/backend"
"github.com/integration-system/isp-lib/v2/structure"
log "github.com/integration-system/isp-log"
"github.com/pkg/errors"
"github.com/valyala/fasthttp"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"isp-gate-service/conf"
"isp-gate-service/domain"
"isp-gate-service/log_code"
"isp-gate-service/proxy/grpc/handlers"
"isp-gate-service/utils"
)
type grpcProxy struct {
@@ -25,29 +20,16 @@ func NewProxy(skipAuth, skipExistCheck bool) *grpcProxy {
return &grpcProxy{
client: backend.NewRxGrpcClient(
backend.WithDialOptions(
grpc.WithInsecure(), grpc.WithBlock(),
grpc.WithInsecure(),
grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(int(conf.DefaultMaxResponseBodySize))),
grpc.WithDefaultCallOptions(grpc.MaxCallSendMsgSize(int(conf.DefaultMaxResponseBodySize))),
),
backend.WithDialingErrorHandler(func(err error) {
log.Errorf(log_code.ErrorClientGrpc, "dialing err: %v", err)
})),
)),
skipAuth: skipAuth,
skipExistCheck: skipExistCheck,
}
}
func (p *grpcProxy) ProxyRequest(ctx *fasthttp.RequestCtx, path string) domain.ProxyResponse {
if p.client.InternalGrpcClient == nil {
msg := "client undefined"
log.Error(log_code.ErrorClientGrpc, msg)
utils.WriteError(ctx, msg, codes.Internal, nil)
return domain.Create().
SetRequestBody(ctx.Request.Body()).
SetResponseBody(ctx.Response.Body()).
SetError(errors.New(msg))
}
return handlers.Handler.Get(ctx).Complete(ctx, path, p.client)
}
@@ -64,5 +46,5 @@ func (p *grpcProxy) SkipExistCheck() bool {
}
func (p *grpcProxy) Close() {
p.client.Close()
_ = p.client.Close()
}
+1 -4
View File
@@ -110,10 +110,7 @@ func logHandlerError(typeData, method string, err error) {
func openStream(headers *fasthttp.RequestHeader, method string, timeout time.Duration, client *backend.RxGrpcClient) (
isp.BackendService_RequestStreamClient, context.CancelFunc, error) {
cli, err := client.Conn()
if err != nil {
return nil, nil, err
}
cli := client.Conn()
md, _ := makeMetadata(headers, method)
ctx := metadata.NewOutgoingContext(context.Background(), md)
ctx, cancel := context.WithTimeout(ctx, timeout)
+6 -3
View File
@@ -19,7 +19,10 @@ import (
"strconv"
)
var getFile getFileDesc
var (
errInvalidJson = errors.New("invalid json format. Expected object or array")
getFile getFileDesc
)
type getFileDesc struct{}
@@ -120,11 +123,11 @@ func (getFileDesc) readJsonBody(ctx *fasthttp.RequestCtx) (interface{}, error) {
case '[':
body = make([]interface{}, 0)
default:
return nil, errors.New("Invalid json format. Expected object or array")
return nil, errInvalidJson
}
err := json.Unmarshal(requestBody, &body)
if err != nil {
return nil, errors.New("Not able to read request body")
return nil, err
}
return body, err
}
+1 -6
View File
@@ -27,12 +27,7 @@ func (p handleJsonDesc) Complete(c *fasthttp.RequestCtx, method string, client *
ctx, cancel := context.WithTimeout(ctx, grpcSetting.GetSyncInvokeTimeout())
defer cancel()
cli, err := client.Conn()
if err != nil {
logHandlerError(log_code.TypeData.JsonContent, methodName, err)
utils.WriteError(c, errorMsgInternal, codes.Internal, nil)
return domain.Create().SetRequestBody(body).SetResponseBody(c.Response.Body()).SetError(err)
}
cli := client.Conn()
msg, invokerErr := cli.Request(
ctx,
+7 -4
View File
@@ -14,6 +14,10 @@ import (
"isp-gate-service/utils"
)
var (
errNotInitialized = errors.New("http proxy not initialized")
)
type httpProxy struct {
client *fasthttp.HostClient
skipAuth bool
@@ -43,13 +47,12 @@ func (p *httpProxy) Consumer(addressList []structure.AddressConfiguration) bool
func (p *httpProxy) ProxyRequest(ctx *fasthttp.RequestCtx, path string) domain.ProxyResponse {
client := p.client
if client == nil {
msg := "client undefined"
log.Error(log_code.ErrorClientHttp, msg)
utils.WriteError(ctx, msg, codes.Internal, nil)
log.Error(log_code.ErrorClientHttp, errNotInitialized)
utils.WriteError(ctx, errNotInitialized.Error(), codes.Internal, nil)
return domain.Create().
SetRequestBody(ctx.Request.Body()).
SetResponseBody(ctx.Response.Body()).
SetError(errors.New(msg))
SetError(errNotInitialized)
}
req := &ctx.Request
File renamed without changes.
@@ -1,4 +1,4 @@
package proxy
package proxy //nolint
import (
"testing"
@@ -23,7 +23,8 @@ func Test_getPathWithoutPrefix(t *testing.T) {
prefix: "/api",
}, want: "service/group/method"},
}
for _, tt := range tests {
for _, test := range tests {
tt := test
t.Run(tt.name, func(t *testing.T) {
if got := getPathWithoutPrefix(tt.args.path, tt.args.prefix); got != tt.want {
t.Errorf("getPathWithoutPrefix() = %v, want %v", got, tt.want)
+11 -8
View File
@@ -24,12 +24,16 @@ const (
readBufSize = 4 << 10
)
var pool = &sync.Pool{New: func() interface{} {
buf := make([]byte, readBufSize)
return &buf
}}
var (
errNoAddresses = errors.New("no available address")
pool = &sync.Pool{New: func() interface{} {
buf := make([]byte, readBufSize)
return &buf
}}
)
// used to filter client request headers
//
var forbiddenDuplicateHeaders = map[string]struct{}{
"Upgrade": {},
"Connection": {},
@@ -69,13 +73,13 @@ func (p *websocketProxy) Consumer(addressList []structure.AddressConfiguration)
func (p *websocketProxy) ProxyRequest(ctx *fasthttp.RequestCtx, path string) domain.ProxyResponse {
addrs := p.addrs
if addrs == nil {
msg := "no available address"
msg := errNoAddresses
log.Error(log_code.ErrorWebsocketProxy, msg)
utils.WriteError(ctx, msg, codes.Internal, nil)
utils.WriteError(ctx, msg.Error(), codes.Internal, nil)
return domain.Create().
SetRequestBody(ctx.Request.Body()).
SetResponseBody(ctx.Response.Body()).
SetError(errors.New(msg))
SetError(errNoAddresses)
}
reqHeaders := fasthttp.RequestHeader{}
@@ -141,7 +145,6 @@ func (p *websocketProxy) SkipExistCheck() bool {
return p.skipExistCheck
}
// no-op
func (p *websocketProxy) Close() {
}