summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Kim <dkim@gitlab.com>2020-04-07 15:12:10 +0930
committerDavid Kim <dkim@gitlab.com>2020-04-07 15:16:32 +0930
commita9d9243401d887083477079192eb30452f7ccfc3 (patch)
tree3f3f6d1f8cf13978e611a3c683a904727f2ba39f
parent12c6711f321dd4b0acf507041cf05fbaa623e29e (diff)
downloadgitlab-shell-a9d9243401d887083477079192eb30452f7ccfc3.tar.gz
Move logging to handler instead
-rw-r--r--internal/command/receivepack/gitalycall.go5
-rw-r--r--internal/command/shared/commandlogger/commandlogger.go20
-rw-r--r--internal/command/uploadarchive/gitalycall.go5
-rw-r--r--internal/command/uploadpack/gitalycall.go5
-rw-r--r--internal/handler/exec.go17
5 files changed, 23 insertions, 29 deletions
diff --git a/internal/command/receivepack/gitalycall.go b/internal/command/receivepack/gitalycall.go
index 9de3b8e..c1c6e03 100644
--- a/internal/command/receivepack/gitalycall.go
+++ b/internal/command/receivepack/gitalycall.go
@@ -10,7 +10,6 @@ import (
pb "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
"gitlab.com/gitlab-org/gitlab-shell/internal/command/commandargs"
"gitlab.com/gitlab-org/gitlab-shell/internal/command/shared/accessverifier"
- "gitlab.com/gitlab-org/gitlab-shell/internal/command/shared/commandlogger"
"gitlab.com/gitlab-org/gitlab-shell/internal/handler"
)
@@ -32,12 +31,12 @@ func (c *Command) performGitalyCall(response *accessverifier.Response) error {
GitConfigOptions: response.GitConfigOptions,
}
- commandlogger.Log("git-receive-pack", request.Repository, response, "")
-
return gc.RunGitalyCommand(func(ctx context.Context, conn *grpc.ClientConn) (int32, error) {
ctx, cancel := context.WithCancel(ctx)
defer cancel()
+ gc.LogExecution("git-receive-pack", request.Repository, response, "")
+
rw := c.ReadWriter
return client.ReceivePack(ctx, conn, rw.In, rw.Out, rw.ErrOut, request)
})
diff --git a/internal/command/shared/commandlogger/commandlogger.go b/internal/command/shared/commandlogger/commandlogger.go
deleted file mode 100644
index cc357eb..0000000
--- a/internal/command/shared/commandlogger/commandlogger.go
+++ /dev/null
@@ -1,20 +0,0 @@
-package commandlogger
-
-import (
- log "github.com/sirupsen/logrus"
- pb "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
- "gitlab.com/gitlab-org/gitlab-shell/internal/gitlabnet/accessverifier"
-)
-
-func Log(command string, repository *pb.Repository, response *accessverifier.Response, protocol string) {
- fields := log.Fields{
- "command": command,
- "gl_project_path": repository.GlProjectPath,
- "gl_repository": repository.GlRepository,
- "user_id": response.UserId,
- "username": response.Username,
- "git_protocol": protocol,
- }
-
- log.WithFields(fields).Info("executing git command")
-}
diff --git a/internal/command/uploadarchive/gitalycall.go b/internal/command/uploadarchive/gitalycall.go
index edc3bb1..40a5359 100644
--- a/internal/command/uploadarchive/gitalycall.go
+++ b/internal/command/uploadarchive/gitalycall.go
@@ -8,7 +8,6 @@ import (
"gitlab.com/gitlab-org/gitaly/client"
pb "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
"gitlab.com/gitlab-org/gitlab-shell/internal/command/commandargs"
- "gitlab.com/gitlab-org/gitlab-shell/internal/command/shared/commandlogger"
"gitlab.com/gitlab-org/gitlab-shell/internal/gitlabnet/accessverifier"
"gitlab.com/gitlab-org/gitlab-shell/internal/handler"
)
@@ -24,12 +23,12 @@ func (c *Command) performGitalyCall(response *accessverifier.Response) error {
request := &pb.SSHUploadArchiveRequest{Repository: &response.Gitaly.Repo}
- commandlogger.Log("git-upload-archive", request.Repository, response, "")
-
return gc.RunGitalyCommand(func(ctx context.Context, conn *grpc.ClientConn) (int32, error) {
ctx, cancel := context.WithCancel(ctx)
defer cancel()
+ gc.LogExecution("git-upload-archive", request.Repository, response, "")
+
rw := c.ReadWriter
return client.UploadArchive(ctx, conn, rw.In, rw.Out, rw.ErrOut, request)
})
diff --git a/internal/command/uploadpack/gitalycall.go b/internal/command/uploadpack/gitalycall.go
index 8ab163d..d33fac8 100644
--- a/internal/command/uploadpack/gitalycall.go
+++ b/internal/command/uploadpack/gitalycall.go
@@ -9,7 +9,6 @@ import (
"gitlab.com/gitlab-org/gitaly/client"
pb "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
"gitlab.com/gitlab-org/gitlab-shell/internal/command/commandargs"
- "gitlab.com/gitlab-org/gitlab-shell/internal/command/shared/commandlogger"
"gitlab.com/gitlab-org/gitlab-shell/internal/gitlabnet/accessverifier"
"gitlab.com/gitlab-org/gitlab-shell/internal/handler"
)
@@ -29,12 +28,12 @@ func (c *Command) performGitalyCall(response *accessverifier.Response) error {
GitConfigOptions: response.GitConfigOptions,
}
- commandlogger.Log("git-upload-pack", request.Repository, response, request.GitProtocol)
-
return gc.RunGitalyCommand(func(ctx context.Context, conn *grpc.ClientConn) (int32, error) {
ctx, cancel := context.WithCancel(ctx)
defer cancel()
+ gc.LogExecution("git-upload-pack", request.Repository, response, request.GitProtocol)
+
rw := c.ReadWriter
return client.UploadPack(ctx, conn, rw.In, rw.Out, rw.ErrOut, request)
})
diff --git a/internal/handler/exec.go b/internal/handler/exec.go
index 19621fa..977fadc 100644
--- a/internal/handler/exec.go
+++ b/internal/handler/exec.go
@@ -6,10 +6,14 @@ import (
"os"
"strings"
+ log "github.com/sirupsen/logrus"
+
"gitlab.com/gitlab-org/gitaly/auth"
"gitlab.com/gitlab-org/gitaly/client"
+ pb "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
"gitlab.com/gitlab-org/gitlab-shell/internal/config"
+ "gitlab.com/gitlab-org/gitlab-shell/internal/gitlabnet/accessverifier"
"gitlab.com/gitlab-org/labkit/tracing"
"google.golang.org/grpc"
"google.golang.org/grpc/metadata"
@@ -51,6 +55,19 @@ func (gc *GitalyCommand) RunGitalyCommand(handler GitalyHandlerFunc) error {
return err
}
+func (gc *GitalyCommand) LogExecution(command string, repository *pb.Repository, response *accessverifier.Response, protocol string) {
+ fields := log.Fields{
+ "command": command,
+ "gl_project_path": repository.GlProjectPath,
+ "gl_repository": repository.GlRepository,
+ "user_id": response.UserId,
+ "username": response.Username,
+ "git_protocol": protocol,
+ }
+
+ log.WithFields(fields).Info("executing git command")
+}
+
func withOutgoingMetadata(ctx context.Context, features map[string]string) context.Context {
md := metadata.New(nil)
for k, v := range features {