-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow injection of a logger into tenantmiddleware #29
base: main
Are you sure you want to change the base?
Conversation
@@ -61,7 +61,7 @@ const ( | |||
// Adds systemBaseUri and tenantId to request context. | |||
// If the headers are not present the given defaultSystemBaseUri and tenant "0" are used. | |||
// The signatureSecretKey is specific for each App and is provided by the registration process for d.velop cloud. | |||
func AddToCtx(defaultSystemBaseUri string, signatureSecretKey []byte) func(http.Handler) http.Handler { | |||
func AddToCtx(defaultSystemBaseUri string, signatureSecretKey []byte, logger func(ctx context.Context, message string)) func(http.Handler) http.Handler { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use logError instead of logger for the name of the log func param to use a naming similar to the idp middleware.
@@ -71,19 +71,19 @@ func AddToCtx(defaultSystemBaseUri string, signatureSecretKey []byte) func(http. | |||
|
|||
if systemBaseUri != "" || tenantId != "" { | |||
if signatureSecretKey == nil { | |||
log.Printf("error validating signature for headers '%v' and '%v' because secret signature key has not been configured", systemBaseUriHeader, tenantIdHeader) | |||
logger(req.Context(), fmt.Sprintf("validating signature for headers '%v' and '%v' because secret signature key has not been configured", systemBaseUriHeader, tenantIdHeader)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using the local ctx var because it is shorter.
Fixes #28
Add an additional parameter to the signature of
AddToCtx
, allowing the caller to inject a logger method, similar to the idp middleware.