Commit 164baba2 authored by Kim "BKC" Carlbäcker's avatar Kim "BKC" Carlbäcker

refactor Gitaly dialOpts

parent 51fe7f28
...@@ -5,6 +5,10 @@ import ( ...@@ -5,6 +5,10 @@ import (
"os/exec" "os/exec"
"syscall" "syscall"
"google.golang.org/grpc"
"gitlab.com/gitlab-org/gitaly/auth"
"gitlab.com/gitlab-org/gitaly/client"
"gitlab.com/gitlab-org/gitlab-shell/go/internal/config" "gitlab.com/gitlab-org/gitlab-shell/go/internal/config"
"gitlab.com/gitlab-org/gitlab-shell/go/internal/logger" "gitlab.com/gitlab-org/gitlab-shell/go/internal/logger"
) )
...@@ -36,3 +40,12 @@ func execCommand(command string, args ...string) error { ...@@ -36,3 +40,12 @@ func execCommand(command string, args ...string) error {
args = append([]string{binPath}, args...) args = append([]string{binPath}, args...)
return syscall.Exec(binPath, args, os.Environ()) return syscall.Exec(binPath, args, os.Environ())
} }
func dialOpts(token string) []grpc.DialOption {
connOpts := client.DefaultDialOpts
if token := os.Getenv("GITALY_TOKEN"); token != "" {
connOpts = append(client.DefaultDialOpts, grpc.WithPerRPCCredentials(gitalyauth.RPCCredentials(token)))
}
return connOpts
}
...@@ -5,10 +5,7 @@ import ( ...@@ -5,10 +5,7 @@ import (
"fmt" "fmt"
"os" "os"
"google.golang.org/grpc"
pb "gitlab.com/gitlab-org/gitaly-proto/go" pb "gitlab.com/gitlab-org/gitaly-proto/go"
"gitlab.com/gitlab-org/gitaly/auth"
"gitlab.com/gitlab-org/gitaly/client" "gitlab.com/gitlab-org/gitaly/client"
) )
...@@ -17,12 +14,7 @@ func ReceivePack(gitalyAddress string, request *pb.SSHReceivePackRequest) (int32 ...@@ -17,12 +14,7 @@ func ReceivePack(gitalyAddress string, request *pb.SSHReceivePackRequest) (int32
return 0, fmt.Errorf("no gitaly_address given") return 0, fmt.Errorf("no gitaly_address given")
} }
connOpts := client.DefaultDialOpts conn, err := client.Dial(gitalyAddress, dialOpts(os.Getenv("GITALY_TOKEN")))
if token := os.Getenv("GITALY_TOKEN"); token != "" {
connOpts = append(client.DefaultDialOpts, grpc.WithPerRPCCredentials(gitalyauth.RPCCredentials(token)))
}
conn, err := client.Dial(gitalyAddress, connOpts)
if err != nil { if err != nil {
return 0, err return 0, err
} }
......
...@@ -5,10 +5,7 @@ import ( ...@@ -5,10 +5,7 @@ import (
"fmt" "fmt"
"os" "os"
"google.golang.org/grpc"
pb "gitlab.com/gitlab-org/gitaly-proto/go" pb "gitlab.com/gitlab-org/gitaly-proto/go"
"gitlab.com/gitlab-org/gitaly/auth"
"gitlab.com/gitlab-org/gitaly/client" "gitlab.com/gitlab-org/gitaly/client"
) )
...@@ -17,12 +14,7 @@ func UploadPack(gitalyAddress string, request *pb.SSHUploadPackRequest) (int32, ...@@ -17,12 +14,7 @@ func UploadPack(gitalyAddress string, request *pb.SSHUploadPackRequest) (int32,
return 0, fmt.Errorf("no gitaly_address given") return 0, fmt.Errorf("no gitaly_address given")
} }
connOpts := client.DefaultDialOpts conn, err := client.Dial(gitalyAddress, dialOpts(os.Getenv("GITALY_TOKEN")))
if token := os.Getenv("GITALY_TOKEN"); token != "" {
connOpts = append(client.DefaultDialOpts, grpc.WithPerRPCCredentials(gitalyauth.RPCCredentials(token)))
}
conn, err := client.Dial(gitalyAddress, connOpts)
if err != nil { if err != nil {
return 0, err return 0, err
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment