From 75eb4ca041c93b638c173478ca148feebe22f15c Mon Sep 17 00:00:00 2001 From: Juan Antonio Osorio Date: Fri, 22 Nov 2024 14:05:11 +0200 Subject: [PATCH] Expect `GetContext` for context v2 resources The getter interfaces for v2-context-only resources was incorrect and it expected us to have a parameter called contextv2. This won't work for our use-cases. This fixes the accessor, thus making the compat middleware work. Signed-off-by: Juan Antonio Osorio --- internal/controlplane/common.go | 8 ++++---- internal/controlplane/handlers_authz.go | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/internal/controlplane/common.go b/internal/controlplane/common.go index 1c479ee400..9127c420e3 100644 --- a/internal/controlplane/common.go +++ b/internal/controlplane/common.go @@ -47,7 +47,7 @@ type HasProtoContextV2Compat interface { // HasProtoContextV2 is an interface that can be implemented by a request type HasProtoContextV2 interface { - GetContextV2() *pb.ContextV2 + GetContext() *pb.ContextV2 } // HasProtoContext is an interface that can be implemented by a request @@ -74,13 +74,13 @@ func getProjectFromContextV2Compat(accessor HasProtoContextV2Compat) (uuid.UUID, } func getProjectFromContextV2(accessor HasProtoContextV2) (uuid.UUID, error) { - if accessor.GetContextV2() == nil { + if accessor.GetContext() == nil { return uuid.Nil, util.UserVisibleError(codes.InvalidArgument, "context cannot be nil") } // First check if the context is V2 - if accessor.GetContextV2() != nil && accessor.GetContextV2().GetProjectId() != "" { - return parseProject(accessor.GetContextV2().GetProjectId()) + if accessor.GetContext() != nil && accessor.GetContext().GetProjectId() != "" { + return parseProject(accessor.GetContext().GetProjectId()) } return uuid.Nil, ErrNoProjectInContext diff --git a/internal/controlplane/handlers_authz.go b/internal/controlplane/handlers_authz.go index 8bf3a532f3..b44c946e82 100644 --- a/internal/controlplane/handlers_authz.go +++ b/internal/controlplane/handlers_authz.go @@ -155,7 +155,7 @@ func getProviderFromContext(req any) string { } return req.GetContext().GetProvider() case HasProtoContextV2: - return req.GetContextV2().GetProvider() + return req.GetContext().GetProvider() case HasProtoContext: return req.GetContext().GetProvider() default: