fix proxy path & add skip auth

This commit is contained in:
DeniskaRediska committed 2019-11-25 15:44:03 +03:00
1 parent 38806190e7
commit 244d8fbdc2
13 files changed
+137 -95

No files matched your search

+21 -15
View File
@@ -16,23 +16,26 @@ import (
)
type grpcProxy struct {
client *backend.RxGrpcClient
client *backend.RxGrpcClient
skipAuth bool
}
func NewProxy() *grpcProxy {
return &grpcProxy{client: backend.NewRxGrpcClient(
backend.WithDialOptions(
grpc.WithInsecure(), grpc.WithBlock(),
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)
}),
)}
func NewProxy(skiAuth bool) *grpcProxy {
return &grpcProxy{
client: backend.NewRxGrpcClient(
backend.WithDialOptions(
grpc.WithInsecure(), grpc.WithBlock(),
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: skiAuth,
}
}
func (p *grpcProxy) ProxyRequest(ctx *fasthttp.RequestCtx) domain.ProxyResponse {
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)
@@ -43,14 +46,17 @@ func (p *grpcProxy) ProxyRequest(ctx *fasthttp.RequestCtx) domain.ProxyResponse
SetError(errors.New(msg))
}
uri := string(ctx.RequestURI())
return handlers.Handler.Get(ctx).Complete(ctx, uri, p.client)
return handlers.Handler.Get(ctx).Complete(ctx, path, p.client)
}
func (p *grpcProxy) Consumer(addr []structure.AddressConfiguration) bool {
return p.client.ReceiveAddressList(addr)
}
func (p *grpcProxy) SkipAuth() bool {
return p.skipAuth
}
func (p *grpcProxy) Close() {
p.client.Close()
}
+1 -1
View File
@@ -128,7 +128,7 @@ func openStream(headers *fasthttp.RequestHeader, method string, timeout time.Dur
}
func makeMetadata(r *fasthttp.RequestHeader, method string) (metadata.MD, string) {
method = strings.TrimPrefix(method, "/api/")
//method = strings.TrimPrefix(method, "/api/")
md := metadata.Pairs(utils.ProxyMethodNameHeader, method)
r.VisitAll(func(key, v []byte) {
lowerHeader := strings.ToLower(string(key))
-7
View File
@@ -19,13 +19,7 @@ var handleJson handleJsonDesc
type handleJsonDesc struct{}
func (p handleJsonDesc) Complete(c *fasthttp.RequestCtx, method string, client *backend.RxGrpcClient) domain.ProxyResponse {
//body, err := utils.ReadJsonBody(c)
body := c.Request.Body()
/*if err != nil {
streaming.LogError(log_code.TypeData.JsonContent, method, err)
streaming.SendError(err.Error(), codes.InvalidArgument, []interface{}{err.Error()}, c)
return
}*/
md, methodName := makeMetadata(&c.Request.Header, method)
ctx := metadata.NewOutgoingContext(context.Background(), md)
@@ -40,7 +34,6 @@ func (p handleJsonDesc) Complete(c *fasthttp.RequestCtx, method string, client *
return domain.Create().SetError(err)
}
//structBody := u.ConvertInterfaceToGrpcStruct(body)
resp, invokerErr := cli.Request(
ctx,
&isp.Message{