Skip to content

Commit

Permalink
Merge pull request #264 from xmidt-org/feature/add-trust-to-logs
Browse files Browse the repository at this point in the history
Feature/add trust to logs
  • Loading branch information
johnabass authored Nov 21, 2024
2 parents 5453dc5 + f2211d4 commit 8438956
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
1 change: 1 addition & 0 deletions token/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func (f *factory) NewToken(ctx context.Context, r *Request) (string, error) {
return "", err
}

r.Logger.Info("new token", zap.Any("trust", merged[ClaimTrust]))
token := jwt.NewWithClaims(f.method, jwt.MapClaims(merged))
pair := f.pair.Load().(key.Pair)
token.Header["kid"] = pair.KID()
Expand Down
3 changes: 2 additions & 1 deletion token/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/xmidt-org/themis/key"
"github.com/xmidt-org/themis/random"
"go.uber.org/zap"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -72,7 +73,7 @@ func testNewFactorySuccess(t *testing.T) {
require.NoError(err)
require.NotNil(factory)

token, err := factory.NewToken(context.Background(), new(Request))
token, err := factory.NewToken(context.Background(), &Request{Logger: zap.NewNop()})
require.NoError(err)
assert.True(len(token) > 0)
}
Expand Down
8 changes: 4 additions & 4 deletions xhttp/xhttpserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ func NewServerChain(o Options, l *zap.Logger, fbs ...sallusthttp.FieldBuilder) a
bs.Add(func(r *http.Request, l *zap.Logger) *zap.Logger {
return l.With(zap.String("userAgent", r.UserAgent()))
})
bs.Add(func(r *http.Request, l *zap.Logger) *zap.Logger {
return l.With(connectionStateField("state", r.TLS))
})

chain := alice.New(
ResponseHeaders{Header: o.Header}.Then,
Expand All @@ -73,10 +76,7 @@ func NewServerChain(o Options, l *zap.Logger, fbs ...sallusthttp.FieldBuilder) a
func(next http.Handler) http.Handler {
return http.HandlerFunc(func(response http.ResponseWriter, request *http.Request) {
requestLogger := bs.Build(request, l)
requestLogger.Info(
"tls info",
connectionStateField("state", request.TLS),
)
requestLogger.Info("request received")

next.ServeHTTP(
response,
Expand Down

0 comments on commit 8438956

Please sign in to comment.