William Petit
7de166765b
All checks were successful
Cadoles/bouncer/pipeline/head This commit looks good
58 lines
964 B
Go
58 lines
964 B
Go
package integration
|
|
|
|
import (
|
|
"context"
|
|
|
|
"forge.cadoles.com/cadoles/bouncer/internal/jwk"
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
type Integration interface {
|
|
Integration()
|
|
}
|
|
|
|
type OnStartup interface {
|
|
Integration
|
|
OnStartup(ctx context.Context) error
|
|
}
|
|
|
|
type OnKeyLoad interface {
|
|
Integration
|
|
OnKeyLoad(ctx context.Context) (jwk.Key, error)
|
|
}
|
|
|
|
func RunOnStartup(ctx context.Context, integrations []Integration) error {
|
|
for _, it := range integrations {
|
|
onStartup, ok := it.(OnStartup)
|
|
if !ok {
|
|
continue
|
|
}
|
|
|
|
if err := onStartup.OnStartup(ctx); err != nil {
|
|
return errors.WithStack(err)
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func RunOnKeyLoad(ctx context.Context, integrations []Integration) (jwk.Key, error) {
|
|
for _, it := range integrations {
|
|
onKeyLoad, ok := it.(OnKeyLoad)
|
|
if !ok {
|
|
continue
|
|
}
|
|
|
|
key, err := onKeyLoad.OnKeyLoad(ctx)
|
|
if err != nil {
|
|
return nil, errors.WithStack(err)
|
|
}
|
|
|
|
if key != nil {
|
|
return key, nil
|
|
}
|
|
}
|
|
|
|
return nil, nil
|
|
}
|