Skip to content

Commit

Permalink
Unexport logger getter and setter (#219)
Browse files Browse the repository at this point in the history
* keep setter and getter unexported

* add change note
  • Loading branch information
joe94 committed Jun 11, 2021
1 parent 23e1cb9 commit df106dc
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]
- Keep setter and getter unexported. [#219](https://github.com/xmidt-org/tr1d1um/pull/219)
- Prevent Authorization header from getting logged. [#218](https://github.com/xmidt-org/tr1d1um/pull/218)


Expand Down
4 changes: 2 additions & 2 deletions basculeLogging.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func sanitizeHeaders(headers http.Header) (filtered http.Header) {
return
}

func SetLogger(logger log.Logger) func(delegate http.Handler) http.Handler {
func setLogger(logger log.Logger) func(delegate http.Handler) http.Handler {
return func(delegate http.Handler) http.Handler {
return http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) {
Expand All @@ -34,7 +34,7 @@ func SetLogger(logger log.Logger) func(delegate http.Handler) http.Handler {
}
}

func GetLogger(ctx context.Context) log.Logger {
func getLogger(ctx context.Context) log.Logger {
logger := log.With(logging.GetLogger(ctx), "ts", log.DefaultTimestampUTC, "caller", log.DefaultCaller)
return logger
}
8 changes: 4 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func tr1d1um(arguments []string) (exitCode int) {
}
webhookConfig.Argus.HTTPClient = newHTTPClient(argusClientTimeout, tracing)

svc, stopWatch, err := ancla.Initialize(webhookConfig, GetLogger)
svc, stopWatch, err := ancla.Initialize(webhookConfig, getLogger)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to initialize webhook service: %s\n", err.Error())
return 1
Expand Down Expand Up @@ -450,7 +450,7 @@ func authenticationHandler(v *viper.Viper, logger log.Logger, registry xmetrics.
logging.Debug(logger).Log(logging.MessageKey(), "Created list of allowed basic auths", "allowed", basicAllowed, "config", basicAuth)

options := []basculehttp.COption{
basculehttp.WithCLogger(GetLogger),
basculehttp.WithCLogger(getLogger),
basculehttp.WithCErrorResponseFunc(listener.OnErrorResponse),
basculehttp.WithParseURLFunc(basculehttp.CreateRemovePrefixURLFunc("/"+apiBase+"/", basculehttp.DefaultParseURLFunc)),
}
Expand Down Expand Up @@ -508,14 +508,14 @@ func authenticationHandler(v *viper.Viper, logger log.Logger, registry xmetrics.
}

authEnforcer := basculehttp.NewEnforcer(
basculehttp.WithELogger(GetLogger),
basculehttp.WithELogger(getLogger),
basculehttp.WithRules("Basic", bascule.Validators{
bchecks.AllowAll(),
}),
basculehttp.WithRules("Bearer", bearerRules),
basculehttp.WithEErrorResponseFunc(listener.OnErrorResponse),
)
constructors := []alice.Constructor{SetLogger(logger), authConstructor, authEnforcer, basculehttp.NewListenerDecorator(listener)}
constructors := []alice.Constructor{setLogger(logger), authConstructor, authEnforcer, basculehttp.NewListenerDecorator(listener)}

chain := alice.New(constructors...)
return &chain, nil
Expand Down

0 comments on commit df106dc

Please sign in to comment.