From 14a2fb7235028cd9c5287655f99688a75cadcbb0 Mon Sep 17 00:00:00 2001 From: John Cai Date: Fri, 3 Jun 2022 10:48:10 -0400 Subject: gitaly-hooks: Pass in user details to call to PackObjectsHook Now that we have access to the user_id, username, and protocol, we can pass these values into the request to PackObjectsHookWithSidechannel --- cmd/gitaly-hooks/hooks.go | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/cmd/gitaly-hooks/hooks.go b/cmd/gitaly-hooks/hooks.go index 5a56464c8..10a0d2514 100644 --- a/cmd/gitaly-hooks/hooks.go +++ b/cmd/gitaly-hooks/hooks.go @@ -25,6 +25,7 @@ import ( "gitlab.com/gitlab-org/gitaly/v15/streamio" "gitlab.com/gitlab-org/labkit/tracing" "google.golang.org/grpc" + "google.golang.org/grpc/metadata" ) type hookError struct { @@ -387,9 +388,42 @@ func handlePackObjectsWithSidechannel(ctx context.Context, payload git.HooksPayl } defer wt.Close() + var glID, glUsername, gitProtocol string + + // TODO: remove this conditional in 15.2. + // Since the git2go binary is replaced before the gitaly binary, there + // is a period of time during an upgrade when the gitaly binary is older + // than the corresponding git2go binary, which means gitaly will still + // be sending ReceiveHooksPayload until the upgrade is finished. + if payload.UserDetails != nil { + glID = payload.UserDetails.UserID + glUsername = payload.UserDetails.Username + gitProtocol = payload.UserDetails.Protocol + } else { + glID = payload.ReceiveHooksPayload.UserID + glUsername = payload.ReceiveHooksPayload.Username + gitProtocol = payload.ReceiveHooksPayload.Protocol + } + + ctx = metadata.AppendToOutgoingContext( + ctx, + "user_id", + glID, + "username", + glUsername, + "protocol", + gitProtocol, + ) + if _, err := hookClient.PackObjectsHookWithSidechannel( ctx, - &gitalypb.PackObjectsHookWithSidechannelRequest{Repository: payload.Repo, Args: args}, + &gitalypb.PackObjectsHookWithSidechannelRequest{ + Repository: payload.Repo, + Args: args, + GlId: glID, + GlUsername: glUsername, + GitProtocol: gitProtocol, + }, ); err != nil { return fmt.Errorf("call PackObjectsHookWithSidechannel: %w", err) } -- cgit v1.2.3