mirror of
https://github.com/open-cluster-management-io/ocm.git
synced 2026-08-23 22:26:49 +00:00
Post / coverage (push) Failing after 26m56s
Post / images (amd64) (push) Failing after 6m52s
Post / images (arm64) (push) Failing after 6m50s
Post / image manifest (push) Has been skipped
Post / trigger clusteradm e2e (push) Has been skipped
Close stale issues and PRs / stale (push) Successful in 54s
Scorecard supply-chain security / Scorecard analysis (push) Failing after 1m19s
* Acceping AWS IRSA registraion request Signed-off-by: Gaurav Jaswal <jaswalkiranavtar@gmail.com> * Addressing comments Signed-off-by: Gaurav Jaswal <jaswalkiranavtar@gmail.com> * Addressing comments Signed-off-by: Gaurav Jaswal <jaswalkiranavtar@gmail.com> * Making csr as a default enabled driver if no other driver is explicitly enabled Signed-off-by: Gaurav Jaswal <jaswalkiranavtar@gmail.com> --------- Signed-off-by: Gaurav Jaswal <jaswalkiranavtar@gmail.com> Co-authored-by: “Jeffrey <jeffreywong0417@gmail.com> Co-authored-by: Gaurav Jaswal <jaswalkiranavtar@gmail.com>
47 lines
1.5 KiB
Go
47 lines
1.5 KiB
Go
package middleware
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/aws/smithy-go/logging"
|
|
)
|
|
|
|
// loggerKey is the context value key for which the logger is associated with.
|
|
type loggerKey struct{}
|
|
|
|
// GetLogger takes a context to retrieve a Logger from. If no logger is present on the context a logging.Nop logger
|
|
// is returned. If the logger retrieved from context supports the ContextLogger interface, the context will be passed
|
|
// to the WithContext method and the resulting logger will be returned. Otherwise the stored logger is returned as is.
|
|
func GetLogger(ctx context.Context) logging.Logger {
|
|
logger, ok := ctx.Value(loggerKey{}).(logging.Logger)
|
|
if !ok || logger == nil {
|
|
return logging.Nop{}
|
|
}
|
|
|
|
return logging.WithContext(ctx, logger)
|
|
}
|
|
|
|
// SetLogger sets the provided logger value on the provided ctx.
|
|
func SetLogger(ctx context.Context, logger logging.Logger) context.Context {
|
|
return context.WithValue(ctx, loggerKey{}, logger)
|
|
}
|
|
|
|
type setLogger struct {
|
|
Logger logging.Logger
|
|
}
|
|
|
|
// AddSetLoggerMiddleware adds a middleware that will add the provided logger to the middleware context.
|
|
func AddSetLoggerMiddleware(stack *Stack, logger logging.Logger) error {
|
|
return stack.Initialize.Add(&setLogger{Logger: logger}, After)
|
|
}
|
|
|
|
func (a *setLogger) ID() string {
|
|
return "SetLogger"
|
|
}
|
|
|
|
func (a *setLogger) HandleInitialize(ctx context.Context, in InitializeInput, next InitializeHandler) (
|
|
out InitializeOutput, metadata Metadata, err error,
|
|
) {
|
|
return next.HandleInitialize(SetLogger(ctx, a.Logger), in)
|
|
}
|