Refactor sign-in page and IAM service lifecycle
Redesign the sign-in page to show email/password form inline with OIDC provider buttons (with vendor icons) instead of separate pages. Extract OIDCProvider type to its own file. Replace errgroup with sync.WaitGroup + WithCancelCause for graceful shutdown in IAM services. Refactor garbage collectors to use functional options and time.Ticker instead of time.After to avoid repeated allocations. Signed-off-by: Bryan Frimin <bryan@getprobo.com>
This commit is contained in:
@@ -34,20 +34,36 @@ type (
|
||||
interval time.Duration
|
||||
logger *log.Logger
|
||||
}
|
||||
|
||||
GarbageCollectorOption func(*GarbageCollector)
|
||||
)
|
||||
|
||||
func NewGarbageCollector(
|
||||
pg *pg.Client,
|
||||
interval time.Duration,
|
||||
logger *log.Logger,
|
||||
) *GarbageCollector {
|
||||
return &GarbageCollector{
|
||||
pg: pg,
|
||||
interval: interval,
|
||||
logger: logger.Named("saml.garbage_collector").With(log.Duration("interval", interval)),
|
||||
func WithGarbageCollectionInterval(interval time.Duration) GarbageCollectorOption {
|
||||
return func(gc *GarbageCollector) {
|
||||
gc.interval = interval
|
||||
}
|
||||
}
|
||||
|
||||
func NewGarbageCollector(
|
||||
pgClient *pg.Client,
|
||||
logger *log.Logger,
|
||||
opts ...GarbageCollectorOption,
|
||||
) *GarbageCollector {
|
||||
gc := &GarbageCollector{
|
||||
pg: pgClient,
|
||||
interval: DefaultGarbageCollectionInterval,
|
||||
logger: logger.Named("saml.garbage_collector"),
|
||||
}
|
||||
|
||||
for _, opt := range opts {
|
||||
opt(gc)
|
||||
}
|
||||
|
||||
gc.logger = gc.logger.With(log.Duration("interval", gc.interval))
|
||||
|
||||
return gc
|
||||
}
|
||||
|
||||
func (gc *GarbageCollector) Run(ctx context.Context) error {
|
||||
gc.logger.InfoCtx(ctx, "saml garbage collector starting")
|
||||
|
||||
@@ -55,12 +71,15 @@ func (gc *GarbageCollector) Run(ctx context.Context) error {
|
||||
gc.logger.ErrorCtx(ctx, "cannot run initial cleanup", log.Error(err))
|
||||
}
|
||||
|
||||
ticker := time.NewTicker(gc.interval)
|
||||
defer ticker.Stop()
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
gc.logger.InfoCtx(ctx, "saml garbage collector shutting down")
|
||||
return ctx.Err()
|
||||
case <-time.After(gc.interval):
|
||||
case <-ticker.C:
|
||||
if err := gc.cleanup(ctx); err != nil {
|
||||
gc.logger.ErrorCtx(ctx, "cannot run periodic cleanup", log.Error(err))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user