Skip to content
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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Allow injection of a logger into tenantmiddleware #29

wants to merge 4 commits into from

Conversation

tlanfer
Copy link
Contributor

@tlanfer tlanfer commented Dec 2, 2020

Fixes #28

Add an additional parameter to the signature of AddToCtx, allowing the caller to inject a logger method, similar to the idp middleware.

@tlanfer tlanfer marked this pull request as ready for review December 2, 2020 07:20
@tlanfer tlanfer requested a review from mtestrot December 2, 2020 07:21
@@ -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 {
Copy link
Member

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))
Copy link
Member

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.

@d-velop-github-admin d-velop-github-admin changed the base branch from master to main December 1, 2022 13:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tenant middleware does not allow injection of a logging method
2 participants