Feat: Update the logger config to show the parent_id
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/beckn-one/beckn-onix/pkg/model"
|
||||
"github.com/beckn-one/beckn-onix/pkg/plugin/implementation/reqpreprocessor"
|
||||
)
|
||||
|
||||
@@ -18,6 +19,11 @@ func (p provider) New(ctx context.Context, c map[string]string) (func(http.Handl
|
||||
if contextKeys, ok := c["contextKeys"]; ok {
|
||||
config.ContextKeys = strings.Split(contextKeys, ",")
|
||||
}
|
||||
|
||||
if v := ctx.Value(model.ContextKeyParentID); v != nil {
|
||||
config.ParentID = v.(string)
|
||||
}
|
||||
|
||||
return reqpreprocessor.NewPreProcessor(config)
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/beckn-one/beckn-onix/pkg/model"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
@@ -92,7 +93,9 @@ func TestProviderNew(t *testing.T) {
|
||||
}`
|
||||
|
||||
p := provider{}
|
||||
middleware, err := p.New(context.Background(), tc.config)
|
||||
ctx := context.Background()
|
||||
ctx = context.WithValue(ctx, model.ContextKeyParentID, "bap:bap-1:instanceID")
|
||||
middleware, err := p.New(ctx, tc.config)
|
||||
if tc.expectedError {
|
||||
assert.Error(t, err)
|
||||
return
|
||||
|
||||
@@ -17,6 +17,7 @@ import (
|
||||
type Config struct {
|
||||
Role string
|
||||
ContextKeys []string
|
||||
ParentID string
|
||||
}
|
||||
|
||||
const contextKey = "context"
|
||||
@@ -58,6 +59,11 @@ func NewPreProcessor(cfg *Config) (func(http.Handler) http.Handler, error) {
|
||||
log.Debugf(ctx, "adding subscriberId to request:%s, %v", model.ContextKeySubscriberID, subID)
|
||||
ctx = context.WithValue(ctx, model.ContextKeySubscriberID, subID)
|
||||
}
|
||||
|
||||
if cfg.ParentID != "" {
|
||||
log.Debugf(ctx, "adding parentID to request:%s, %v", model.ContextKeyParentID, cfg.ParentID)
|
||||
ctx = context.WithValue(ctx, model.ContextKeyParentID, cfg.ParentID)
|
||||
}
|
||||
for _, key := range cfg.ContextKeys {
|
||||
ctxKey, _ := model.ParseContextKey(key)
|
||||
if v, ok := reqContext[key]; ok {
|
||||
|
||||
@@ -22,7 +22,8 @@ func TestNewPreProcessorSuccessCases(t *testing.T) {
|
||||
{
|
||||
name: "BAP role with valid context",
|
||||
config: &Config{
|
||||
Role: "bap",
|
||||
Role: "bap",
|
||||
ParentID: "bap:bap-123",
|
||||
},
|
||||
requestBody: map[string]interface{}{
|
||||
"context": map[string]interface{}{
|
||||
@@ -38,7 +39,8 @@ func TestNewPreProcessorSuccessCases(t *testing.T) {
|
||||
{
|
||||
name: "BPP role with valid context",
|
||||
config: &Config{
|
||||
Role: "bpp",
|
||||
Role: "bpp",
|
||||
ParentID: "bap:bap-123",
|
||||
},
|
||||
requestBody: map[string]interface{}{
|
||||
"context": map[string]interface{}{
|
||||
|
||||
Reference in New Issue
Block a user