From b054257e06c81f64742699e7466695ae3cbaa883 Mon Sep 17 00:00:00 2001 From: john Date: Tue, 4 Oct 2022 17:57:32 +0300 Subject: [PATCH] MSP-1069 update proxy grpc http --- proxy/const.go | 5 +++++ proxy/grpc.go | 11 ++++------- proxy/http.go | 9 ++++++--- 3 files changed, 15 insertions(+), 10 deletions(-) create mode 100644 proxy/const.go diff --git a/proxy/const.go b/proxy/const.go new file mode 100644 index 0000000..a332011 --- /dev/null +++ b/proxy/const.go @@ -0,0 +1,5 @@ +package proxy + +const ( + xAdminIdHeader = "x-admin-id" +) diff --git a/proxy/grpc.go b/proxy/grpc.go index dbea4f9..1cdc406 100644 --- a/proxy/grpc.go +++ b/proxy/grpc.go @@ -7,6 +7,9 @@ import ( "strconv" "time" + "isp-gate-service/httperrors" + "isp-gate-service/request" + "github.com/integration-system/isp-kit/grpc" "github.com/integration-system/isp-kit/grpc/client" "github.com/integration-system/isp-kit/grpc/isp" @@ -17,12 +20,6 @@ import ( "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" "google.golang.org/grpc/status" - "isp-gate-service/httperrors" - "isp-gate-service/request" -) - -const ( - adminAuthHeader = "x-auth-admin" ) func init() { @@ -84,7 +81,7 @@ func (p Grpc) Handle(ctx *request.Context) error { md[grpc.ServiceIdHeader] = []string{strconv.Itoa(authData.ServiceId)} md[grpc.ApplicationIdHeader] = []string{strconv.Itoa(authData.ApplicationId)} if ctx.IsAdminAuthenticated() { - md[adminAuthHeader] = []string{ctx.AdminToken()} + md[xAdminIdHeader] = []string{strconv.Itoa(ctx.AdminId())} } } requestContext := metadata.NewOutgoingContext(ctx.Context(), md) diff --git a/proxy/http.go b/proxy/http.go index d7123a0..669b7ad 100644 --- a/proxy/http.go +++ b/proxy/http.go @@ -8,12 +8,13 @@ import ( "strconv" "time" + "isp-gate-service/httperrors" + "isp-gate-service/request" + "github.com/integration-system/isp-kit/grpc" "github.com/integration-system/isp-kit/requestid" "github.com/pkg/errors" "golang.org/x/net/context" - "isp-gate-service/httperrors" - "isp-gate-service/request" ) type HttpHostManager interface { @@ -59,7 +60,9 @@ func (p Http) Handle(ctx *request.Context) error { request.Header.Set(grpc.ServiceIdHeader, strconv.Itoa(authData.ServiceId)) request.Header.Set(grpc.ApplicationIdHeader, strconv.Itoa(authData.ApplicationId)) if ctx.IsAdminAuthenticated() { - request.Header.Set(adminAuthHeader, ctx.AdminToken()) + request.Header.Set(xAdminIdHeader, strconv.Itoa(ctx.AdminId())) + } else { + request.Header.Del(xAdminIdHeader) } }