From 3b20f466c3bcad89e7bab7ab76df9cbf346703b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89mile=20R=C3=A9?= Date: Wed, 20 May 2026 11:53:50 +0400 Subject: [PATCH] Fix indentation after errors.AsType refactor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Émile Ré --- pkg/probod/probod.go | 6 +-- pkg/server/api/authn/api_key_middleware.go | 42 +++++++++--------- pkg/server/api/authn/session_middleware.go | 50 +++++++++++----------- pkg/server/api/trust/v1/auth_resolvers.go | 24 +++++------ 4 files changed, 61 insertions(+), 61 deletions(-) diff --git a/pkg/probod/probod.go b/pkg/probod/probod.go index b4343cd58..190792688 100644 --- a/pkg/probod/probod.go +++ b/pkg/probod/probod.go @@ -1114,9 +1114,9 @@ func (impl *Implm) runTrustCenterServer( cert, err := certSelector.GetCertificate(hello) // Silently reject connections without SNI (load balancers, health checks, scanners) if err != nil { - if _, ok := errors.AsType[*certmanager.NoSNIError](err); ok { - return nil, nil - } + if _, ok := errors.AsType[*certmanager.NoSNIError](err); ok { + return nil, nil + } if errors.Is(err, coredata.ErrResourceNotFound) { return nil, nil diff --git a/pkg/server/api/authn/api_key_middleware.go b/pkg/server/api/authn/api_key_middleware.go index efaae897d..6c9d1f4a3 100644 --- a/pkg/server/api/authn/api_key_middleware.go +++ b/pkg/server/api/authn/api_key_middleware.go @@ -62,31 +62,31 @@ func NewAPIKeyMiddleware(svc *iam.Service, tokenSecret string) func(next http.Ha return } - apiKey, err := svc.APIKeyService.GetAPIKey(ctx, keyID) - if err != nil { - if _, ok := errors.AsType[*iam.ErrPersonalAPIKeyNotFound](err); ok { - next.ServeHTTP(w, r) - return + apiKey, err := svc.APIKeyService.GetAPIKey(ctx, keyID) + if err != nil { + if _, ok := errors.AsType[*iam.ErrPersonalAPIKeyNotFound](err); ok { + next.ServeHTTP(w, r) + return + } + + if _, ok := errors.AsType[*iam.ErrPersonalAPIKeyExpired](err); ok { + next.ServeHTTP(w, r) + return + } + + panic(fmt.Errorf("cannot get personal API key: %w", err)) } - if _, ok := errors.AsType[*iam.ErrPersonalAPIKeyExpired](err); ok { - next.ServeHTTP(w, r) - return + identity, err := svc.AccountService.GetIdentity(ctx, apiKey.IdentityID) + if err != nil { + if _, ok := errors.AsType[*iam.ErrIdentityNotFound](err); ok { + next.ServeHTTP(w, r) + return + } + + panic(fmt.Errorf("cannot get identity: %w", err)) } - panic(fmt.Errorf("cannot get personal API key: %w", err)) - } - - identity, err := svc.AccountService.GetIdentity(ctx, apiKey.IdentityID) - if err != nil { - if _, ok := errors.AsType[*iam.ErrIdentityNotFound](err); ok { - next.ServeHTTP(w, r) - return - } - - panic(fmt.Errorf("cannot get identity: %w", err)) - } - ctx = ContextWithAPIKey(ctx, apiKey) ctx = ContextWithIdentity(ctx, identity) diff --git a/pkg/server/api/authn/session_middleware.go b/pkg/server/api/authn/session_middleware.go index 4295d8481..13118003b 100644 --- a/pkg/server/api/authn/session_middleware.go +++ b/pkg/server/api/authn/session_middleware.go @@ -65,37 +65,37 @@ func NewSessionMiddleware(svc *iam.Service, cookieConfig securecookie.Config) fu return } - session, err := svc.SessionService.GetSession(ctx, sessionID) - if err != nil { - if _, ok := errors.AsType[*iam.ErrSessionNotFound](err); ok { - securecookie.Clear(w, cookieConfig) - next.ServeHTTP(w, r) + session, err := svc.SessionService.GetSession(ctx, sessionID) + if err != nil { + if _, ok := errors.AsType[*iam.ErrSessionNotFound](err); ok { + securecookie.Clear(w, cookieConfig) + next.ServeHTTP(w, r) - return + return + } + + if _, ok := errors.AsType[*iam.ErrSessionExpired](err); ok { + securecookie.Clear(w, cookieConfig) + next.ServeHTTP(w, r) + + return + } + + panic(fmt.Errorf("cannot get session: %w", err)) } - if _, ok := errors.AsType[*iam.ErrSessionExpired](err); ok { - securecookie.Clear(w, cookieConfig) - next.ServeHTTP(w, r) + identity, err := svc.AccountService.GetIdentity(ctx, session.IdentityID) + if err != nil { + if _, ok := errors.AsType[*iam.ErrIdentityNotFound](err); ok { + securecookie.Clear(w, cookieConfig) + next.ServeHTTP(w, r) - return + return + } + + panic(fmt.Errorf("cannot get identity: %w", err)) } - panic(fmt.Errorf("cannot get session: %w", err)) - } - - identity, err := svc.AccountService.GetIdentity(ctx, session.IdentityID) - if err != nil { - if _, ok := errors.AsType[*iam.ErrIdentityNotFound](err); ok { - securecookie.Clear(w, cookieConfig) - next.ServeHTTP(w, r) - - return - } - - panic(fmt.Errorf("cannot get identity: %w", err)) - } - userAgent := r.UserAgent() // TODO: will work well when no layer 7 proxy is in front of the server var ipAddress net.IP diff --git a/pkg/server/api/trust/v1/auth_resolvers.go b/pkg/server/api/trust/v1/auth_resolvers.go index 149a55670..030b743f4 100644 --- a/pkg/server/api/trust/v1/auth_resolvers.go +++ b/pkg/server/api/trust/v1/auth_resolvers.go @@ -79,13 +79,13 @@ func (r *mutationResolver) VerifyMagicLink(ctx context.Context, input types.Veri identity, session, continueURL, err = r.iam.AuthService.OpenSessionWithMagicLink(ctx, input.Token) if err != nil { - if _, ok := errors.AsType[*iam.ErrExpiredToken](err); ok { - return nil, gqlutils.Invalid(ctx, err) - } + if _, ok := errors.AsType[*iam.ErrExpiredToken](err); ok { + return nil, gqlutils.Invalid(ctx, err) + } - if _, ok := errors.AsType[*iam.ErrInvalidToken](err); ok { - return nil, gqlutils.Invalid(ctx, err) - } + if _, ok := errors.AsType[*iam.ErrInvalidToken](err); ok { + return nil, gqlutils.Invalid(ctx, err) + } r.logger.ErrorCtx(ctx, "cannot open session with magic link", log.Error(err)) @@ -101,13 +101,13 @@ func (r *mutationResolver) VerifyMagicLink(ctx context.Context, input types.Veri identity, session, continueURL, err = r.iam.AuthService.OpenSessionWithMagicLink(ctx, input.Token) if err != nil { - if _, ok := errors.AsType[*iam.ErrExpiredToken](err); ok { - return nil, gqlutils.Invalid(ctx, err) - } + if _, ok := errors.AsType[*iam.ErrExpiredToken](err); ok { + return nil, gqlutils.Invalid(ctx, err) + } - if _, ok := errors.AsType[*iam.ErrInvalidToken](err); ok { - return nil, gqlutils.Invalid(ctx, err) - } + if _, ok := errors.AsType[*iam.ErrInvalidToken](err); ok { + return nil, gqlutils.Invalid(ctx, err) + } r.logger.ErrorCtx(ctx, "cannot open session with magic link", log.Error(err))