solve some bugs

This commit is contained in:
Tim Möhlmann 2023-11-16 23:09:23 +02:00
parent 728f838a09
commit 953e9433eb
6 changed files with 21 additions and 22 deletions

View File

@ -25,7 +25,7 @@ func (s *Server) Introspect(ctx context.Context, r *op.Request[op.IntrospectionR
}
if s.features.TriggerIntrospectionProjections {
// Execute all triggers in one concurrent sweep.
ctx = query.TriggerIntrospectionProjections(ctx)
query.TriggerIntrospectionProjections(ctx)
}
ctx, cancel := context.WithCancel(ctx)
@ -78,8 +78,8 @@ func (s *Server) Introspect(ctx context.Context, r *op.Request[op.IntrospectionR
defer func() {
if err != nil {
s.getLogger(ctx).ErrorContext(ctx, "oidc introspection", "err", err)
resp, err = op.NewResponse(new(oidc.IntrospectionResponse)), nil
}
resp, err = op.NewResponse(new(oidc.IntrospectionResponse)), nil
}()
if err != nil {

View File

@ -1,16 +1,16 @@
with config as (
select app_id, client_id, client_secret
from projections.apps5_api_configs
from projections.apps6_api_configs
where instance_id = $1
and client_id = $2
union
select app_id, client_id, client_secret
from projections.apps5_oidc_configs
from projections.apps6_oidc_configs
where instance_id = $1
and client_id = $2
),
keys as (
select identifier as client_id, json_object_agg(id, public_key) as public_keys
select identifier as client_id, json_object_agg(id, encode(public_key, 'base64')) as public_keys
from projections.authn_keys2
where $3 = true -- when argument is false, don't waste time on trying to query for keys.
and instance_id = $1
@ -19,5 +19,5 @@ keys as (
group by identifier
)
select config.client_id, config.client_secret, apps.project_id, keys.public_keys from config
join projections.apps5 apps on apps.id = config.app_id
join projections.apps6 apps on apps.id = config.app_id
left join keys on keys.client_id = config.client_id;

View File

@ -18,8 +18,8 @@ var introspectionTriggerHandlers = append(oidcUserInfoTriggerHandlers,
projection.AuthNKeyProjection,
)
func TriggerIntrospectionProjections(ctx context.Context) context.Context {
return triggerBatch(ctx, introspectionTriggerHandlers...)
func TriggerIntrospectionProjections(ctx context.Context) {
triggerBatch(ctx, introspectionTriggerHandlers...)
}
type IntrospectionClient struct {

View File

@ -153,22 +153,21 @@ func init() {
// triggerBatch calls Trigger on every handler in a seperate Go routine.
// The returned context is the context returned by the Trigger that finishes last.
func triggerBatch(ctx context.Context, handlers ...*handler.Handler) context.Context {
ctxChan := make(chan context.Context)
func triggerBatch(ctx context.Context, handlers ...*handler.Handler) {
var wg sync.WaitGroup
wg.Add(len(handlers))
for _, h := range handlers {
go func(ctx context.Context, h *handler.Handler, ctxChan chan<- context.Context) {
go func(ctx context.Context, h *handler.Handler) {
name := h.ProjectionName()
_, traceSpan := tracing.NewNamedSpan(ctx, fmt.Sprintf("Trigger%s", name))
newCtx, err := h.Trigger(ctx, handler.WithAwaitRunning())
_, err := h.Trigger(ctx, handler.WithAwaitRunning())
logging.OnError(err).WithField("projection", name).Debug("trigger failed")
traceSpan.EndWithError(err)
ctxChan <- newCtx
}(ctx, h, ctxChan)
wg.Done()
}(ctx, h)
}
for i := 0; i < len(handlers); i++ {
ctx = <-ctxChan
}
return ctx
wg.Wait()
}

View File

@ -706,8 +706,8 @@ func NewUserLoginNameExistsQuery(value string, comparison TextComparison) (Searc
)
}
func triggerUserProjections(ctx context.Context) context.Context {
return triggerBatch(ctx, projection.UserProjection, projection.LoginNameProjection)
func triggerUserProjections(ctx context.Context) {
triggerBatch(ctx, projection.UserProjection, projection.LoginNameProjection)
}
func prepareLoginNamesQuery() (string, []interface{}, error) {

View File

@ -22,8 +22,8 @@ var oidcUserInfoTriggerHandlers = []*handler.Handler{
projection.ProjectProjection,
}
func TriggerOIDCUserInfoProjections(ctx context.Context) context.Context {
return triggerBatch(ctx, oidcUserInfoTriggerHandlers...)
func TriggerOIDCUserInfoProjections(ctx context.Context) {
triggerBatch(ctx, oidcUserInfoTriggerHandlers...)
}
//go:embed embed/userinfo_by_id.sql