add logger to auth manager
This commit is contained in:
@@ -2,6 +2,8 @@ package prism
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"git.wisehodl.dev/jay/go-mana-component"
|
||||||
|
"log/slog"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -30,14 +32,18 @@ type AuthManager struct {
|
|||||||
inbox <-chan InboxMessage
|
inbox <-chan InboxMessage
|
||||||
events <-chan OutboundPoolEvent
|
events <-chan OutboundPoolEvent
|
||||||
|
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
cancel context.CancelFunc
|
cancel context.CancelFunc
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
wg sync.WaitGroup
|
wg sync.WaitGroup
|
||||||
|
handler slog.Handler
|
||||||
|
logger *slog.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewAuthManager(e *Envoy, respond func(string) ([]byte, error)) *AuthManager {
|
func NewAuthManager(e *Envoy, respond func(string) ([]byte, error)) *AuthManager {
|
||||||
ctx, cancel := context.WithCancel(e.Context())
|
ctx, cancel := context.WithCancel(
|
||||||
|
component.MustExtend(e.Context(), "auth_manager"))
|
||||||
|
|
||||||
m := &AuthManager{
|
m := &AuthManager{
|
||||||
envoy: e,
|
envoy: e,
|
||||||
respond: respond,
|
respond: respond,
|
||||||
@@ -46,6 +52,13 @@ func NewAuthManager(e *Envoy, respond func(string) ([]byte, error)) *AuthManager
|
|||||||
ctx: ctx,
|
ctx: ctx,
|
||||||
cancel: cancel,
|
cancel: cancel,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if e.Handler() != nil {
|
||||||
|
comp := component.FromContext(ctx)
|
||||||
|
m.handler = e.Handler()
|
||||||
|
m.logger = slog.New(m.handler).With(slog.Any("component", comp))
|
||||||
|
}
|
||||||
|
|
||||||
m.wg.Go(m.routeInbox)
|
m.wg.Go(m.routeInbox)
|
||||||
m.wg.Go(m.handleEvents)
|
m.wg.Go(m.handleEvents)
|
||||||
return m
|
return m
|
||||||
@@ -85,6 +98,10 @@ func (m *AuthManager) routeInbox() {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if m.logger != nil {
|
||||||
|
m.logger.Info("responded to auth", "challenge", challenge)
|
||||||
|
}
|
||||||
|
|
||||||
m.envoy.Observer().Record(msg.ID, AuthResponseSent{At: time.Now()})
|
m.envoy.Observer().Record(msg.ID, AuthResponseSent{At: time.Now()})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -157,11 +157,11 @@ func NewRequestManager(e *Envoy) *RequestManager {
|
|||||||
ctx: ctx,
|
ctx: ctx,
|
||||||
cancel: cancel,
|
cancel: cancel,
|
||||||
observer: e.Observer(),
|
observer: e.Observer(),
|
||||||
handler: e.Handler(),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if m.handler != nil {
|
if e.Handler() != nil {
|
||||||
comp := component.FromContext(ctx)
|
comp := component.FromContext(ctx)
|
||||||
|
m.handler = e.Handler()
|
||||||
m.logger = slog.New(m.handler).With(slog.Any("component", comp))
|
m.logger = slog.New(m.handler).With(slog.Any("component", comp))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user