From 1f2ac96b4be25eb1102bb48a7deab36990c8b7a0 Mon Sep 17 00:00:00 2001 From: John Cai Date: Mon, 27 Apr 2020 13:36:26 -0700 Subject: Inject storages to repository service Transition away from global config struct by injecting into the repository service, and adding helpers that take a storage object instead of accessing the global config. --- internal/config/config.go | 21 +++++++++- internal/helper/repo.go | 46 ++++++++++++++++++++++ internal/praefect/helper_test.go | 2 +- internal/praefect/replicator_test.go | 5 ++- internal/rubyserver/proxy.go | 23 ++++++++--- internal/service/register.go | 6 +-- internal/service/remote/fetch_internal_remote.go | 4 +- .../service/remote/find_remote_root_ref_test.go | 7 ++-- internal/service/remote/remotes_test.go | 17 ++++---- internal/service/remote/server.go | 6 ++- internal/service/remote/testhelper_test.go | 5 ++- .../service/remote/update_remote_mirror_test.go | 9 +++-- internal/service/repository/apply_gitattributes.go | 4 +- .../service/repository/apply_gitattributes_test.go | 5 ++- internal/service/repository/archive_test.go | 7 ++-- internal/service/repository/backup_custom_hooks.go | 2 +- .../service/repository/backup_custom_hooks_test.go | 11 +++--- internal/service/repository/calculate_checksum.go | 2 +- .../service/repository/calculate_checksum_test.go | 11 +++--- internal/service/repository/cleanup.go | 8 ++-- internal/service/repository/cleanup_test.go | 11 +++--- internal/service/repository/clone_from_pool.go | 8 ++-- .../service/repository/clone_from_pool_internal.go | 14 +++---- .../repository/clone_from_pool_internal_test.go | 3 +- .../service/repository/clone_from_pool_test.go | 3 +- internal/service/repository/config_test.go | 5 ++- internal/service/repository/create.go | 2 +- internal/service/repository/create_bundle_test.go | 5 ++- internal/service/repository/create_from_bundle.go | 2 +- .../service/repository/create_from_bundle_test.go | 9 +++-- .../service/repository/create_from_snapshot.go | 4 +- .../repository/create_from_snapshot_test.go | 3 +- internal/service/repository/create_from_url.go | 2 +- .../service/repository/create_from_url_test.go | 11 +++--- internal/service/repository/create_test.go | 9 +++-- internal/service/repository/fetch_remote_test.go | 14 +++---- internal/service/repository/fetch_test.go | 17 ++++---- internal/service/repository/fork.go | 2 +- internal/service/repository/fork_test.go | 8 ++-- internal/service/repository/fsck_test.go | 7 ++-- internal/service/repository/gc.go | 12 +++--- internal/service/repository/gc_test.go | 15 +++---- internal/service/repository/info_attributes.go | 4 +- .../service/repository/info_attributes_test.go | 5 ++- internal/service/repository/license_test.go | 7 ++-- internal/service/repository/merge_base_test.go | 5 ++- internal/service/repository/raw_changes_test.go | 13 +++--- internal/service/repository/rebase_in_progress.go | 2 +- .../service/repository/rebase_in_progress_test.go | 5 ++- internal/service/repository/remove.go | 2 +- internal/service/repository/remove_test.go | 5 ++- internal/service/repository/rename.go | 4 +- internal/service/repository/rename_test.go | 9 +++-- internal/service/repository/repack_test.go | 17 ++++---- internal/service/repository/replicate.go | 10 ++--- internal/service/repository/replicate_test.go | 36 ++++++----------- internal/service/repository/repository.go | 2 +- internal/service/repository/repository_test.go | 21 ++++------ .../service/repository/restore_custom_hooks.go | 2 +- .../repository/restore_custom_hooks_test.go | 11 +++--- internal/service/repository/search_files_test.go | 10 ++--- internal/service/repository/server.go | 6 ++- internal/service/repository/size.go | 2 +- internal/service/repository/size_test.go | 7 ++-- internal/service/repository/snapshot.go | 8 ++-- internal/service/repository/snapshot_test.go | 3 +- internal/service/repository/squash_in_progress.go | 2 +- .../service/repository/squash_in_progress_test.go | 5 ++- internal/service/repository/testhelper_test.go | 8 ++-- internal/service/repository/write_ref_test.go | 5 ++- internal/tempdir/tempdir.go | 14 +++---- internal/tempdir/tempdir_test.go | 3 +- internal/testhelper/testserver.go | 17 ++++++-- 73 files changed, 365 insertions(+), 252 deletions(-) diff --git a/internal/config/config.go b/internal/config/config.go index c96aee290..00f00fa8a 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -37,7 +37,7 @@ type Cfg struct { PrometheusListenAddr string `toml:"prometheus_listen_addr" split_words:"true"` BinDir string `toml:"bin_dir"` Git Git `toml:"git" envconfig:"git"` - Storages []Storage `toml:"storage" envconfig:"storage"` + Storages Storages `toml:"storage" envconfig:"storage"` Logging Logging `toml:"logging" envconfig:"logging"` Prometheus prometheus.Config `toml:"prometheus"` Auth auth.Config `toml:"auth"` @@ -430,3 +430,22 @@ func trySocketCreation(dir string) error { return l.Close() } + +type Storages []Storage + +// StoragePath looks up the base path for storageName. The second boolean +// return value indicates if anything was found. +func (s Storages) GetPath(storageName string) (string, bool) { + storage, ok := s.Get(storageName) + return storage.Path, ok +} + +// Storage looks up storageName. +func (s Storages) Get(storageName string) (Storage, bool) { + for _, storage := range s { + if storage.Name == storageName { + return storage, true + } + } + return Storage{}, false +} diff --git a/internal/helper/repo.go b/internal/helper/repo.go index 9274949a4..74e7fb2c0 100644 --- a/internal/helper/repo.go +++ b/internal/helper/repo.go @@ -31,6 +31,26 @@ func GetRepoPath(repo repository.GitRepo) (string, error) { return "", status.Errorf(codes.NotFound, "GetRepoPath: not a git repository '%s'", repoPath) } +// GetValidatedRepoPath is functionally the same as GetRepoPath except that the storage gets passed in. +// This is for migrating away from using the global config.Config singleton. +// TODO: remove GetRepoPath completely once all usages have been switched over to GetValidatedRepoPath +func GetValidatedRepoPath(repo repository.GitRepo, storages config.Storages) (string, error) { + repoPath, err := GetRepositoryPath(repo, storages) + if err != nil { + return "", err + } + + if repoPath == "" { + return "", status.Errorf(codes.InvalidArgument, "GetRepoPath: empty repo") + } + + if IsGitDirectory(repoPath) { + return repoPath, nil + } + + return "", status.Errorf(codes.NotFound, "GetRepoPath: not a git repository '%s'", repoPath) +} + // GetPath returns the path of the repo passed as first argument. An error is // returned when either the storage can't be found or the path includes // constructs trying to perform directory traversal. @@ -57,6 +77,32 @@ func GetPath(repo repository.GitRepo) (string, error) { return path.Join(storagePath, relativePath), nil } +// GetRepositoryPath is functionally the same as GetPath except that the storage gets passed in. +// This is for migrating away from using the global config.Config singleton. +// TODO: remove GetPath completely once all usages have been switched over to GetRepositoryPath +func GetRepositoryPath(repo repository.GitRepo, storages config.Storages) (string, error) { + storagePath, ok := storages.GetPath(repo.GetStorageName()) + if !ok { + return "", status.Errorf(codes.InvalidArgument, "Storage can not be found by name '%s'", repo.GetStorageName()) + } + + if _, err := os.Stat(storagePath); err != nil { + return "", status.Errorf(codes.Internal, "GetPath: storage path: %v", err) + } + + relativePath := repo.GetRelativePath() + if len(relativePath) == 0 { + err := status.Errorf(codes.InvalidArgument, "GetPath: relative path missing from %+v", repo) + return "", err + } + + if ContainsPathTraversal(relativePath) { + return "", status.Errorf(codes.InvalidArgument, "GetRepoPath: relative path can't contain directory traversal") + } + + return path.Join(storagePath, relativePath), nil +} + // GetStorageByName will return the path for the storage, which is fetched by // its key. An error is return if it cannot be found. func GetStorageByName(storageName string) (string, error) { diff --git a/internal/praefect/helper_test.go b/internal/praefect/helper_test.go index e2baabc0a..aca0655df 100644 --- a/internal/praefect/helper_test.go +++ b/internal/praefect/helper_test.go @@ -257,7 +257,7 @@ func runInternalGitalyServer(t *testing.T, storages []gconfig.Storage, token str require.NoError(t, err) gitalypb.RegisterServerServiceServer(server, gitalyserver.NewServer(storages)) - gitalypb.RegisterRepositoryServiceServer(server, repository.NewServer(RubyServer, internalSocket)) + gitalypb.RegisterRepositoryServiceServer(server, repository.NewServer(RubyServer, storages, internalSocket)) gitalypb.RegisterInternalGitalyServer(server, internalgitaly.NewServer(gconfig.Config.Storages)) healthpb.RegisterHealthServer(server, health.NewServer()) diff --git a/internal/praefect/replicator_test.go b/internal/praefect/replicator_test.go index d47de04ac..e966ecb97 100644 --- a/internal/praefect/replicator_test.go +++ b/internal/praefect/replicator_test.go @@ -13,6 +13,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" gitalyauth "gitlab.com/gitlab-org/gitaly/auth" + gconfig "gitlab.com/gitlab-org/gitaly/internal/config" gitaly_config "gitlab.com/gitlab-org/gitaly/internal/config" "gitlab.com/gitlab-org/gitaly/internal/git/objectpool" "gitlab.com/gitlab-org/gitaly/internal/helper" @@ -733,9 +734,9 @@ func newReplicationService(tb testing.TB) (*grpc.Server, string) { svr := testhelper.NewTestGrpcServer(tb, nil, nil) - gitalypb.RegisterRepositoryServiceServer(svr, repository.NewServer(RubyServer, internalSocketName)) + gitalypb.RegisterRepositoryServiceServer(svr, repository.NewServer(RubyServer, gconfig.Config.Storages, internalSocketName)) gitalypb.RegisterObjectPoolServiceServer(svr, objectpoolservice.NewServer()) - gitalypb.RegisterRemoteServiceServer(svr, remote.NewServer(RubyServer)) + gitalypb.RegisterRemoteServiceServer(svr, remote.NewServer(RubyServer, gconfig.Config.Storages)) gitalypb.RegisterSSHServiceServer(svr, ssh.NewServer()) reflection.Register(svr) diff --git a/internal/rubyserver/proxy.go b/internal/rubyserver/proxy.go index 87052c900..0fc41b2b6 100644 --- a/internal/rubyserver/proxy.go +++ b/internal/rubyserver/proxy.go @@ -6,9 +6,12 @@ import ( "os" "strings" + "gitlab.com/gitlab-org/gitaly/internal/config" "gitlab.com/gitlab-org/gitaly/internal/helper" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" + "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/grpc/status" ) // Headers prefixed with this string get whitelisted automatically @@ -34,17 +37,27 @@ func SetHeaders(ctx context.Context, repo *gitalypb.Repository) (context.Context return setHeaders(ctx, repo, true) } +// SetHeaders adds headers that tell gitaly-ruby the full path to the repository. +func SetHeadersWithStorages(ctx context.Context, storages config.Storages, repo *gitalypb.Repository) (context.Context, error) { + return setHeadersWithStorages(ctx, storages, repo, true) +} + func setHeaders(ctx context.Context, repo *gitalypb.Repository, mustExist bool) (context.Context, error) { - storagePath, err := helper.GetStorageByName(repo.GetStorageName()) - if err != nil { - return nil, err + return setHeadersWithStorages(ctx, config.Config.Storages, repo, mustExist) +} + +func setHeadersWithStorages(ctx context.Context, storages config.Storages, repo *gitalypb.Repository, mustExist bool) (context.Context, error) { + storagePath, ok := storages.GetPath(repo.GetStorageName()) + if !ok { + return nil, status.Errorf(codes.InvalidArgument, "Storage can not be found by name '%s'", repo.GetStorageName()) } + var err error var repoPath string if mustExist { - repoPath, err = helper.GetRepoPath(repo) + repoPath, err = helper.GetValidatedRepoPath(repo, storages) } else { - repoPath, err = helper.GetPath(repo) + repoPath, err = helper.GetRepositoryPath(repo, storages) } if err != nil { return nil, err diff --git a/internal/service/register.go b/internal/service/register.go index 4015f99fc..14fef4469 100644 --- a/internal/service/register.go +++ b/internal/service/register.go @@ -60,7 +60,7 @@ func RegisterAll(grpcServer *grpc.Server, cfg config.Cfg, rubyServer *rubyserver gitalypb.RegisterNamespaceServiceServer(grpcServer, namespace.NewServer()) gitalypb.RegisterOperationServiceServer(grpcServer, operations.NewServer(rubyServer)) gitalypb.RegisterRefServiceServer(grpcServer, ref.NewServer()) - gitalypb.RegisterRepositoryServiceServer(grpcServer, repository.NewServer(rubyServer, config.GitalyInternalSocketPath())) + gitalypb.RegisterRepositoryServiceServer(grpcServer, repository.NewServer(rubyServer, cfg.Storages, config.GitalyInternalSocketPath())) gitalypb.RegisterSSHServiceServer(grpcServer, ssh.NewServer( ssh.WithPackfileNegotiationMetrics(sshPackfileNegotiationMetrics), )) @@ -69,11 +69,11 @@ func RegisterAll(grpcServer *grpc.Server, cfg config.Cfg, rubyServer *rubyserver )) gitalypb.RegisterWikiServiceServer(grpcServer, wiki.NewServer(rubyServer)) gitalypb.RegisterConflictsServiceServer(grpcServer, conflicts.NewServer(rubyServer)) - gitalypb.RegisterRemoteServiceServer(grpcServer, remote.NewServer(rubyServer)) + gitalypb.RegisterRemoteServiceServer(grpcServer, remote.NewServer(rubyServer, cfg.Storages)) gitalypb.RegisterServerServiceServer(grpcServer, server.NewServer(cfg.Storages)) gitalypb.RegisterObjectPoolServiceServer(grpcServer, objectpool.NewServer()) gitalypb.RegisterHookServiceServer(grpcServer, hook.NewServer()) - gitalypb.RegisterInternalGitalyServer(grpcServer, internalgitaly.NewServer(config.Config.Storages)) + gitalypb.RegisterInternalGitalyServer(grpcServer, internalgitaly.NewServer(cfg.Storages)) healthpb.RegisterHealthServer(grpcServer, health.NewServer()) } diff --git a/internal/service/remote/fetch_internal_remote.go b/internal/service/remote/fetch_internal_remote.go index 47ba315d8..ae9a76c44 100644 --- a/internal/service/remote/fetch_internal_remote.go +++ b/internal/service/remote/fetch_internal_remote.go @@ -35,7 +35,7 @@ func (s *server) FetchInternalRemote(ctx context.Context, req *gitalypb.FetchInt return nil, err } - repoPath, err := helper.GetRepoPath(req.Repository) + repoPath, err := helper.GetValidatedRepoPath(req.Repository, s.storages) if err != nil { return nil, err } @@ -66,7 +66,7 @@ func (s *server) rubyFetchInternalRemote(ctx context.Context, req *gitalypb.Fetc return nil, err } - clientCtx, err := rubyserver.SetHeaders(ctx, req.GetRepository()) + clientCtx, err := rubyserver.SetHeadersWithStorages(ctx, s.storages, req.GetRepository()) if err != nil { return nil, err } diff --git a/internal/service/remote/find_remote_root_ref_test.go b/internal/service/remote/find_remote_root_ref_test.go index b26037ea5..e44b79748 100644 --- a/internal/service/remote/find_remote_root_ref_test.go +++ b/internal/service/remote/find_remote_root_ref_test.go @@ -4,13 +4,14 @@ import ( "testing" "github.com/stretchr/testify/require" + "gitlab.com/gitlab-org/gitaly/internal/config" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" "google.golang.org/grpc/codes" ) func TestFindRemoteRootRefSuccess(t *testing.T) { - serverSocketPath, stop := runRemoteServiceServer(t) + serverSocketPath, stop := runRemoteServiceServer(t, config.Config.Storages) defer stop() client, conn := NewRemoteClient(t, serverSocketPath) @@ -29,7 +30,7 @@ func TestFindRemoteRootRefSuccess(t *testing.T) { } func TestFindRemoteRootRefFailedDueToValidation(t *testing.T) { - serverSocketPath, stop := runRemoteServiceServer(t) + serverSocketPath, stop := runRemoteServiceServer(t, config.Config.Storages) defer stop() client, conn := NewRemoteClient(t, serverSocketPath) @@ -77,7 +78,7 @@ func TestFindRemoteRootRefFailedDueToValidation(t *testing.T) { } func TestFindRemoteRootRefFailedDueToInvalidRemote(t *testing.T) { - serverSocketPath, stop := runRemoteServiceServer(t) + serverSocketPath, stop := runRemoteServiceServer(t, config.Config.Storages) defer stop() client, conn := NewRemoteClient(t, serverSocketPath) diff --git a/internal/service/remote/remotes_test.go b/internal/service/remote/remotes_test.go index da16e0759..63d4f1dd8 100644 --- a/internal/service/remote/remotes_test.go +++ b/internal/service/remote/remotes_test.go @@ -10,13 +10,14 @@ import ( "testing" "github.com/stretchr/testify/require" + "gitlab.com/gitlab-org/gitaly/internal/config" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" "google.golang.org/grpc/codes" ) func TestSuccessfulAddRemote(t *testing.T) { - serverSocketPath, stop := runRemoteServiceServer(t) + serverSocketPath, stop := runRemoteServiceServer(t, config.Config.Storages) defer stop() client, conn := NewRemoteClient(t, serverSocketPath) @@ -100,7 +101,7 @@ func TestSuccessfulAddRemote(t *testing.T) { } func TestFailedAddRemoteDueToValidation(t *testing.T) { - serverSocketPath, stop := runRemoteServiceServer(t) + serverSocketPath, stop := runRemoteServiceServer(t, config.Config.Storages) defer stop() client, conn := NewRemoteClient(t, serverSocketPath) @@ -147,7 +148,7 @@ func TestFailedAddRemoteDueToValidation(t *testing.T) { } func TestSuccessfulRemoveRemote(t *testing.T) { - serverSocketPath, stop := runRemoteServiceServer(t) + serverSocketPath, stop := runRemoteServiceServer(t, config.Config.Storages) defer stop() client, conn := NewRemoteClient(t, serverSocketPath) @@ -197,7 +198,7 @@ func TestSuccessfulRemoveRemote(t *testing.T) { } func TestFailedRemoveRemoteDueToValidation(t *testing.T) { - serverSocketPath, stop := runRemoteServiceServer(t) + serverSocketPath, stop := runRemoteServiceServer(t, config.Config.Storages) defer stop() client, conn := NewRemoteClient(t, serverSocketPath) @@ -216,7 +217,7 @@ func TestFailedRemoveRemoteDueToValidation(t *testing.T) { } func TestFindRemoteRepository(t *testing.T) { - serverSocketPath, stop := runRemoteServiceServer(t) + serverSocketPath, stop := runRemoteServiceServer(t, config.Config.Storages) defer stop() client, conn := NewRemoteClient(t, serverSocketPath) @@ -239,7 +240,7 @@ func TestFindRemoteRepository(t *testing.T) { } func TestFailedFindRemoteRepository(t *testing.T) { - serverSocketPath, stop := runRemoteServiceServer(t) + serverSocketPath, stop := runRemoteServiceServer(t, config.Config.Storages) defer stop() client, conn := NewRemoteClient(t, serverSocketPath) @@ -272,7 +273,7 @@ func TestFailedFindRemoteRepository(t *testing.T) { } func TestListDifferentPushUrlRemote(t *testing.T) { - serverSocketPath, stop := runRemoteServiceServer(t) + serverSocketPath, stop := runRemoteServiceServer(t, config.Config.Storages) defer stop() client, conn := NewRemoteClient(t, serverSocketPath) @@ -319,7 +320,7 @@ func TestListDifferentPushUrlRemote(t *testing.T) { } func TestListRemotes(t *testing.T) { - serverSocketPath, stop := runRemoteServiceServer(t) + serverSocketPath, stop := runRemoteServiceServer(t, config.Config.Storages) defer stop() client, conn := NewRemoteClient(t, serverSocketPath) diff --git a/internal/service/remote/server.go b/internal/service/remote/server.go index 8f052578b..0a87763a5 100644 --- a/internal/service/remote/server.go +++ b/internal/service/remote/server.go @@ -1,6 +1,7 @@ package remote import ( + "gitlab.com/gitlab-org/gitaly/internal/config" "gitlab.com/gitlab-org/gitaly/internal/rubyserver" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" ) @@ -8,9 +9,10 @@ import ( type server struct { ruby *rubyserver.Server gitalypb.UnimplementedRemoteServiceServer + storages config.Storages } // NewServer creates a new instance of a grpc RemoteServiceServer -func NewServer(rs *rubyserver.Server) gitalypb.RemoteServiceServer { - return &server{ruby: rs} +func NewServer(rs *rubyserver.Server, storages config.Storages) gitalypb.RemoteServiceServer { + return &server{ruby: rs, storages: storages} } diff --git a/internal/service/remote/testhelper_test.go b/internal/service/remote/testhelper_test.go index 1d07353e7..46a4379d9 100644 --- a/internal/service/remote/testhelper_test.go +++ b/internal/service/remote/testhelper_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/stretchr/testify/require" + "gitlab.com/gitlab-org/gitaly/internal/config" "gitlab.com/gitlab-org/gitaly/internal/rubyserver" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" @@ -33,10 +34,10 @@ func testMain(m *testing.M) int { return m.Run() } -func runRemoteServiceServer(t *testing.T) (string, func()) { +func runRemoteServiceServer(t *testing.T, storages config.Storages) (string, func()) { srv := testhelper.NewServer(t, nil, nil) - gitalypb.RegisterRemoteServiceServer(srv.GrpcServer(), &server{ruby: RubyServer}) + gitalypb.RegisterRemoteServiceServer(srv.GrpcServer(), NewServer(RubyServer, storages)) reflection.Register(srv.GrpcServer()) require.NoError(t, srv.Start()) diff --git a/internal/service/remote/update_remote_mirror_test.go b/internal/service/remote/update_remote_mirror_test.go index 885abe9e0..165f2bb7f 100644 --- a/internal/service/remote/update_remote_mirror_test.go +++ b/internal/service/remote/update_remote_mirror_test.go @@ -6,13 +6,14 @@ import ( "testing" "github.com/stretchr/testify/require" + "gitlab.com/gitlab-org/gitaly/internal/config" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" "google.golang.org/grpc/codes" ) func TestSuccessfulUpdateRemoteMirrorRequest(t *testing.T) { - serverSocketPath, stop := runRemoteServiceServer(t) + serverSocketPath, stop := runRemoteServiceServer(t, config.Config.Storages) defer stop() client, conn := NewRemoteClient(t, serverSocketPath) @@ -99,7 +100,7 @@ func TestSuccessfulUpdateRemoteMirrorRequest(t *testing.T) { } func TestSuccessfulUpdateRemoteMirrorRequestWithWildcards(t *testing.T) { - serverSocketPath, stop := runRemoteServiceServer(t) + serverSocketPath, stop := runRemoteServiceServer(t, config.Config.Storages) defer stop() client, conn := NewRemoteClient(t, serverSocketPath) @@ -179,7 +180,7 @@ func TestSuccessfulUpdateRemoteMirrorRequestWithWildcards(t *testing.T) { } func TestSuccessfulUpdateRemoteMirrorRequestWithKeepDivergentRefs(t *testing.T) { - serverSocketPath, stop := runRemoteServiceServer(t) + serverSocketPath, stop := runRemoteServiceServer(t, config.Config.Storages) defer stop() client, conn := NewRemoteClient(t, serverSocketPath) @@ -262,7 +263,7 @@ func TestSuccessfulUpdateRemoteMirrorRequestWithKeepDivergentRefs(t *testing.T) } func TestFailedUpdateRemoteMirrorRequestDueToValidation(t *testing.T) { - serverSocketPath, stop := runRemoteServiceServer(t) + serverSocketPath, stop := runRemoteServiceServer(t, config.Config.Storages) defer stop() client, conn := NewRemoteClient(t, serverSocketPath) diff --git a/internal/service/repository/apply_gitattributes.go b/internal/service/repository/apply_gitattributes.go index e60919cd9..feae59971 100644 --- a/internal/service/repository/apply_gitattributes.go +++ b/internal/service/repository/apply_gitattributes.go @@ -79,9 +79,9 @@ func applyGitattributes(c *catfile.Batch, repoPath string, revision []byte) erro return os.Rename(tempFile.Name(), attributesPath) } -func (*server) ApplyGitattributes(ctx context.Context, in *gitalypb.ApplyGitattributesRequest) (*gitalypb.ApplyGitattributesResponse, error) { +func (s *server) ApplyGitattributes(ctx context.Context, in *gitalypb.ApplyGitattributesRequest) (*gitalypb.ApplyGitattributesResponse, error) { repo := in.GetRepository() - repoPath, err := helper.GetRepoPath(repo) + repoPath, err := helper.GetValidatedRepoPath(repo, s.storages) if err != nil { return nil, err } diff --git a/internal/service/repository/apply_gitattributes_test.go b/internal/service/repository/apply_gitattributes_test.go index b07fa4e4c..08fb8b1d3 100644 --- a/internal/service/repository/apply_gitattributes_test.go +++ b/internal/service/repository/apply_gitattributes_test.go @@ -8,13 +8,14 @@ import ( "testing" "github.com/stretchr/testify/assert" + "gitlab.com/gitlab-org/gitaly/internal/config" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" "google.golang.org/grpc/codes" ) func TestApplyGitattributesSuccess(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -66,7 +67,7 @@ func TestApplyGitattributesSuccess(t *testing.T) { } func TestApplyGitattributesFailure(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) diff --git a/internal/service/repository/archive_test.go b/internal/service/repository/archive_test.go index f6a7e2bad..e7ffa6e8c 100644 --- a/internal/service/repository/archive_test.go +++ b/internal/service/repository/archive_test.go @@ -9,6 +9,7 @@ import ( "testing" "github.com/stretchr/testify/require" + "gitlab.com/gitlab-org/gitaly/internal/config" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" "gitlab.com/gitlab-org/gitaly/streamio" @@ -16,7 +17,7 @@ import ( ) func TestGetArchiveSuccess(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -120,7 +121,7 @@ func TestGetArchiveSuccess(t *testing.T) { } func TestGetArchiveFailure(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -232,7 +233,7 @@ func TestGetArchiveFailure(t *testing.T) { } func TestGetArchivePathInjection(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) diff --git a/internal/service/repository/backup_custom_hooks.go b/internal/service/repository/backup_custom_hooks.go index c30fe935a..6a8ac76df 100644 --- a/internal/service/repository/backup_custom_hooks.go +++ b/internal/service/repository/backup_custom_hooks.go @@ -16,7 +16,7 @@ import ( const customHooksDir = "custom_hooks" func (s *server) BackupCustomHooks(in *gitalypb.BackupCustomHooksRequest, stream gitalypb.RepositoryService_BackupCustomHooksServer) error { - repoPath, err := helper.GetPath(in.Repository) + repoPath, err := helper.GetRepositoryPath(in.Repository, s.storages) if err != nil { return status.Errorf(codes.Internal, "BackupCustomHooks: getting repo path failed %v", err) } diff --git a/internal/service/repository/backup_custom_hooks_test.go b/internal/service/repository/backup_custom_hooks_test.go index 6494f7d81..35e1f1c3e 100644 --- a/internal/service/repository/backup_custom_hooks_test.go +++ b/internal/service/repository/backup_custom_hooks_test.go @@ -11,6 +11,7 @@ import ( "testing" "github.com/stretchr/testify/require" + "gitlab.com/gitlab-org/gitaly/internal/config" "gitlab.com/gitlab-org/gitaly/internal/helper" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" @@ -18,7 +19,7 @@ import ( ) func TestSuccessfullBackupCustomHooksRequest(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -30,7 +31,7 @@ func TestSuccessfullBackupCustomHooksRequest(t *testing.T) { testRepo, _, cleanupFn := testhelper.NewTestRepo(t) defer cleanupFn() - repoPath, err := helper.GetPath(testRepo) + repoPath, err := helper.GetRepositoryPath(testRepo, config.Config.Storages) require.NoError(t, err) expectedTarResponse := []string{ @@ -67,7 +68,7 @@ func TestSuccessfullBackupCustomHooksRequest(t *testing.T) { } func TestSuccessfullBackupCustomHooksSymlink(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -79,7 +80,7 @@ func TestSuccessfullBackupCustomHooksSymlink(t *testing.T) { testRepo, _, cleanupFn := testhelper.NewTestRepo(t) defer cleanupFn() - repoPath, err := helper.GetPath(testRepo) + repoPath, err := helper.GetRepositoryPath(testRepo, config.Config.Storages) require.NoError(t, err) linkTarget := "/var/empty" @@ -106,7 +107,7 @@ func TestSuccessfullBackupCustomHooksSymlink(t *testing.T) { } func TestSuccessfullBackupCustomHooksRequestWithNoHooks(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) diff --git a/internal/service/repository/calculate_checksum.go b/internal/service/repository/calculate_checksum.go index 6dc051e6f..80e9e6d4e 100644 --- a/internal/service/repository/calculate_checksum.go +++ b/internal/service/repository/calculate_checksum.go @@ -25,7 +25,7 @@ var refWhitelist = regexp.MustCompile(`HEAD|(refs/(heads|tags|keep-around|merge- func (s *server) CalculateChecksum(ctx context.Context, in *gitalypb.CalculateChecksumRequest) (*gitalypb.CalculateChecksumResponse, error) { repo := in.GetRepository() - repoPath, err := helper.GetRepoPath(repo) + repoPath, err := helper.GetValidatedRepoPath(repo, s.storages) if err != nil { return nil, err } diff --git a/internal/service/repository/calculate_checksum_test.go b/internal/service/repository/calculate_checksum_test.go index 450127165..f1321b9db 100644 --- a/internal/service/repository/calculate_checksum_test.go +++ b/internal/service/repository/calculate_checksum_test.go @@ -7,13 +7,14 @@ import ( "testing" "github.com/stretchr/testify/require" + "gitlab.com/gitlab-org/gitaly/internal/config" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" "google.golang.org/grpc/codes" ) func TestSuccessfulCalculateChecksum(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -70,7 +71,7 @@ func TestRefWhitelist(t *testing.T) { } func TestEmptyRepositoryCalculateChecksum(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -89,7 +90,7 @@ func TestEmptyRepositoryCalculateChecksum(t *testing.T) { } func TestBrokenRepositoryCalculateChecksum(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -110,7 +111,7 @@ func TestBrokenRepositoryCalculateChecksum(t *testing.T) { } func TestFailedCalculateChecksum(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -145,7 +146,7 @@ func TestFailedCalculateChecksum(t *testing.T) { } func TestInvalidRefsCalculateChecksum(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) diff --git a/internal/service/repository/cleanup.go b/internal/service/repository/cleanup.go index ec8518516..3bf7355c3 100644 --- a/internal/service/repository/cleanup.go +++ b/internal/service/repository/cleanup.go @@ -17,16 +17,16 @@ import ( var lockFiles = []string{"config.lock", "HEAD.lock"} -func (*server) Cleanup(ctx context.Context, in *gitalypb.CleanupRequest) (*gitalypb.CleanupResponse, error) { - if err := cleanupRepo(ctx, in.GetRepository()); err != nil { +func (s *server) Cleanup(ctx context.Context, in *gitalypb.CleanupRequest) (*gitalypb.CleanupResponse, error) { + if err := s.cleanupRepo(ctx, in.GetRepository()); err != nil { return nil, err } return &gitalypb.CleanupResponse{}, nil } -func cleanupRepo(ctx context.Context, repo *gitalypb.Repository) error { - repoPath, err := helper.GetRepoPath(repo) +func (s *server) cleanupRepo(ctx context.Context, repo *gitalypb.Repository) error { + repoPath, err := helper.GetValidatedRepoPath(repo, s.storages) if err != nil { return err } diff --git a/internal/service/repository/cleanup_test.go b/internal/service/repository/cleanup_test.go index 6b36eae92..0b5c91939 100644 --- a/internal/service/repository/cleanup_test.go +++ b/internal/service/repository/cleanup_test.go @@ -9,13 +9,14 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "gitlab.com/gitlab-org/gitaly/internal/config" "gitlab.com/gitlab-org/gitaly/internal/git" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" ) func TestCleanupDeletesRefsLocks(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -58,7 +59,7 @@ func TestCleanupDeletesRefsLocks(t *testing.T) { } func TestCleanupDeletesPackedRefsLock(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -127,7 +128,7 @@ func TestCleanupDeletesPackedRefsLock(t *testing.T) { // TODO: replace emulated rebase RPC with actual // https://gitlab.com/gitlab-org/gitaly/issues/1750 func TestCleanupDeletesStaleWorktrees(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -199,7 +200,7 @@ func TestCleanupDisconnectedWorktrees(t *testing.T) { worktreeAdminDir = "worktrees" ) - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -258,7 +259,7 @@ func TestCleanupDisconnectedWorktrees(t *testing.T) { } func TestCleanupFileLocks(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) diff --git a/internal/service/repository/clone_from_pool.go b/internal/service/repository/clone_from_pool.go index 3f0716239..ef928b3f9 100644 --- a/internal/service/repository/clone_from_pool.go +++ b/internal/service/repository/clone_from_pool.go @@ -16,11 +16,11 @@ func (s *server) CloneFromPool(ctx context.Context, req *gitalypb.CloneFromPoolR return nil, helper.ErrInvalidArgument(err) } - if err := validateCloneFromPoolRequestRepositoryState(req); err != nil { + if err := s.validateCloneFromPoolRequestRepositoryState(req); err != nil { return nil, helper.ErrInternal(err) } - if err := cloneFromPool(ctx, req.GetPool(), req.GetRepository()); err != nil { + if err := s.cloneFromPool(ctx, req.GetPool(), req.GetRepository()); err != nil { return nil, helper.ErrInternal(err) } @@ -44,8 +44,8 @@ func (s *server) CloneFromPool(ctx context.Context, req *gitalypb.CloneFromPoolR return &gitalypb.CloneFromPoolResponse{}, nil } -func validateCloneFromPoolRequestRepositoryState(req *gitalypb.CloneFromPoolRequest) error { - targetRepositoryFullPath, err := helper.GetPath(req.GetRepository()) +func (s *server) validateCloneFromPoolRequestRepositoryState(req *gitalypb.CloneFromPoolRequest) error { + targetRepositoryFullPath, err := helper.GetRepositoryPath(req.GetRepository(), s.storages) if err != nil { return fmt.Errorf("getting target repository path: %v", err) } diff --git a/internal/service/repository/clone_from_pool_internal.go b/internal/service/repository/clone_from_pool_internal.go index ed661088b..70d7d0bd4 100644 --- a/internal/service/repository/clone_from_pool_internal.go +++ b/internal/service/repository/clone_from_pool_internal.go @@ -19,11 +19,11 @@ func (s *server) CloneFromPoolInternal(ctx context.Context, req *gitalypb.CloneF return nil, helper.ErrInvalidArgument(err) } - if err := validateCloneFromPoolInternalRequestRepositoryState(req); err != nil { + if err := s.validateCloneFromPoolInternalRequestRepositoryState(req); err != nil { return nil, helper.ErrInternal(err) } - if err := cloneFromPool(ctx, req.GetPool(), req.GetRepository()); err != nil { + if err := s.cloneFromPool(ctx, req.GetPool(), req.GetRepository()); err != nil { return nil, helper.ErrInternal(err) } @@ -58,8 +58,8 @@ func (s *server) CloneFromPoolInternal(ctx context.Context, req *gitalypb.CloneF return &gitalypb.CloneFromPoolInternalResponse{}, nil } -func validateCloneFromPoolInternalRequestRepositoryState(req *gitalypb.CloneFromPoolInternalRequest) error { - targetRepositoryFullPath, err := helper.GetPath(req.GetRepository()) +func (s *server) validateCloneFromPoolInternalRequestRepositoryState(req *gitalypb.CloneFromPoolInternalRequest) error { + targetRepositoryFullPath, err := helper.GetRepositoryPath(req.GetRepository(), s.storages) if err != nil { return fmt.Errorf("getting target repository path: %v", err) } @@ -109,12 +109,12 @@ func validateCloneFromPoolInternalRequestArgs(req *gitalypb.CloneFromPoolInterna return nil } -func cloneFromPool(ctx context.Context, objectPoolRepo *gitalypb.ObjectPool, repo repository.GitRepo) error { - objectPoolPath, err := helper.GetPath(objectPoolRepo.GetRepository()) +func (s *server) cloneFromPool(ctx context.Context, objectPoolRepo *gitalypb.ObjectPool, repo repository.GitRepo) error { + objectPoolPath, err := helper.GetRepositoryPath(objectPoolRepo.GetRepository(), s.storages) if err != nil { return fmt.Errorf("could not get object pool path: %v", err) } - repositoryPath, err := helper.GetPath(repo) + repositoryPath, err := helper.GetRepositoryPath(repo, s.storages) if err != nil { return fmt.Errorf("could not get object pool path: %v", err) } diff --git a/internal/service/repository/clone_from_pool_internal_test.go b/internal/service/repository/clone_from_pool_internal_test.go index c32453ee9..cc7aa64b3 100644 --- a/internal/service/repository/clone_from_pool_internal_test.go +++ b/internal/service/repository/clone_from_pool_internal_test.go @@ -8,6 +8,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "gitlab.com/gitlab-org/gitaly/internal/config" "gitlab.com/gitlab-org/gitaly/internal/git/objectpool" "gitlab.com/gitlab-org/gitaly/internal/helper/text" "gitlab.com/gitlab-org/gitaly/internal/service/repository" @@ -38,7 +39,7 @@ func getForkDestination(t *testing.T) (*gitalypb.Repository, string, func()) { } func TestCloneFromPoolInternal(t *testing.T) { - server, serverSocketPath := runFullServer(t) + server, serverSocketPath := runFullServer(t, config.Config.Storages) defer server.Stop() ctxOuter, cancel := testhelper.Context() diff --git a/internal/service/repository/clone_from_pool_test.go b/internal/service/repository/clone_from_pool_test.go index e51bffad0..a7b5d3ae4 100644 --- a/internal/service/repository/clone_from_pool_test.go +++ b/internal/service/repository/clone_from_pool_test.go @@ -6,6 +6,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "gitlab.com/gitlab-org/gitaly/internal/config" "gitlab.com/gitlab-org/gitaly/internal/git/gittest" "gitlab.com/gitlab-org/gitaly/internal/service/repository" "gitlab.com/gitlab-org/gitaly/internal/testhelper" @@ -14,7 +15,7 @@ import ( ) func TestCloneFromPoolHTTP(t *testing.T) { - server, serverSocketPath := runFullServer(t) + server, serverSocketPath := runFullServer(t, config.Config.Storages) defer server.Stop() ctxOuter, cancel := testhelper.Context() diff --git a/internal/service/repository/config_test.go b/internal/service/repository/config_test.go index 9cc0fcea1..a6826d4c9 100644 --- a/internal/service/repository/config_test.go +++ b/internal/service/repository/config_test.go @@ -7,6 +7,7 @@ import ( "testing" "github.com/stretchr/testify/require" + "gitlab.com/gitlab-org/gitaly/internal/config" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" "google.golang.org/grpc/codes" @@ -14,7 +15,7 @@ import ( ) func TestDeleteConfig(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -74,7 +75,7 @@ func TestDeleteConfig(t *testing.T) { } func TestSetConfig(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) diff --git a/internal/service/repository/create.go b/internal/service/repository/create.go index 241a26e05..11b6ddea5 100644 --- a/internal/service/repository/create.go +++ b/internal/service/repository/create.go @@ -10,7 +10,7 @@ import ( ) func (s *server) CreateRepository(ctx context.Context, req *gitalypb.CreateRepositoryRequest) (*gitalypb.CreateRepositoryResponse, error) { - diskPath, err := helper.GetPath(req.GetRepository()) + diskPath, err := helper.GetRepositoryPath(req.GetRepository(), s.storages) if err != nil { return nil, helper.ErrInvalidArgument(err) } diff --git a/internal/service/repository/create_bundle_test.go b/internal/service/repository/create_bundle_test.go index 966eead17..67b215277 100644 --- a/internal/service/repository/create_bundle_test.go +++ b/internal/service/repository/create_bundle_test.go @@ -7,6 +7,7 @@ import ( "testing" "github.com/stretchr/testify/require" + "gitlab.com/gitlab-org/gitaly/internal/config" "gitlab.com/gitlab-org/gitaly/internal/tempdir" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" @@ -15,7 +16,7 @@ import ( ) func TestSuccessfulCreateBundleRequest(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -53,7 +54,7 @@ func TestSuccessfulCreateBundleRequest(t *testing.T) { } func TestFailedCreateBundleRequestDueToValidations(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) diff --git a/internal/service/repository/create_from_bundle.go b/internal/service/repository/create_from_bundle.go index 60d4a54c8..bff1975d1 100644 --- a/internal/service/repository/create_from_bundle.go +++ b/internal/service/repository/create_from_bundle.go @@ -28,7 +28,7 @@ func (s *server) CreateRepositoryFromBundle(stream gitalypb.RepositoryService_Cr return status.Errorf(codes.InvalidArgument, "CreateRepositoryFromBundle: empty Repository") } - repoPath, err := helper.GetPath(repo) + repoPath, err := helper.GetRepositoryPath(repo, s.storages) if err != nil { return helper.ErrInternal(err) } diff --git a/internal/service/repository/create_from_bundle_test.go b/internal/service/repository/create_from_bundle_test.go index f866192f2..f2f4d4b6e 100644 --- a/internal/service/repository/create_from_bundle_test.go +++ b/internal/service/repository/create_from_bundle_test.go @@ -8,6 +8,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "gitlab.com/gitlab-org/gitaly/internal/config" "gitlab.com/gitlab-org/gitaly/internal/git/log" "gitlab.com/gitlab-org/gitaly/internal/helper" "gitlab.com/gitlab-org/gitaly/internal/tempdir" @@ -18,7 +19,7 @@ import ( ) func TestSuccessfulCreateRepositoryFromBundleRequest(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -46,7 +47,7 @@ func TestSuccessfulCreateRepositoryFromBundleRequest(t *testing.T) { StorageName: testhelper.DefaultStorageName, RelativePath: "a-repo-from-bundle", } - importedRepoPath, err := helper.GetPath(importedRepo) + importedRepoPath, err := helper.GetRepositoryPath(importedRepo, config.Config.Storages) require.NoError(t, err) defer os.RemoveAll(importedRepoPath) @@ -85,7 +86,7 @@ func TestSuccessfulCreateRepositoryFromBundleRequest(t *testing.T) { } func TestFailedCreateRepositoryFromBundleRequestDueToValidations(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -104,7 +105,7 @@ func TestFailedCreateRepositoryFromBundleRequestDueToValidations(t *testing.T) { } func TestFailedCreateRepositoryFromBundle_ExistingDirectory(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() testRepo, _, cleanup := testhelper.NewTestRepo(t) diff --git a/internal/service/repository/create_from_snapshot.go b/internal/service/repository/create_from_snapshot.go index e2cf89758..cc4746a8e 100644 --- a/internal/service/repository/create_from_snapshot.go +++ b/internal/service/repository/create_from_snapshot.go @@ -75,7 +75,7 @@ func untar(ctx context.Context, path string, in *gitalypb.CreateRepositoryFromSn } func (s *server) CreateRepositoryFromSnapshot(ctx context.Context, in *gitalypb.CreateRepositoryFromSnapshotRequest) (*gitalypb.CreateRepositoryFromSnapshotResponse, error) { - realPath, err := helper.GetPath(in.Repository) + realPath, err := helper.GetRepositoryPath(in.Repository, s.storages) if err != nil { return nil, err } @@ -87,7 +87,7 @@ func (s *server) CreateRepositoryFromSnapshot(ctx context.Context, in *gitalypb. // Perform all operations against a temporary directory, only moving it to // the canonical location if retrieving and unpacking the snapshot is a // success - tempRepo, tempPath, err := tempdir.NewAsRepository(ctx, in.Repository) + tempRepo, tempPath, err := tempdir.NewAsRepository(ctx, s.storages, in.Repository) if err != nil { return nil, status.Errorf(codes.Internal, "couldn't create temporary directory: %v", err) } diff --git a/internal/service/repository/create_from_snapshot_test.go b/internal/service/repository/create_from_snapshot_test.go index 912432759..400d59a0e 100644 --- a/internal/service/repository/create_from_snapshot_test.go +++ b/internal/service/repository/create_from_snapshot_test.go @@ -12,6 +12,7 @@ import ( "github.com/stretchr/testify/require" "gitlab.com/gitlab-org/gitaly/internal/archive" + "gitlab.com/gitlab-org/gitaly/internal/config" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" "google.golang.org/grpc/codes" @@ -55,7 +56,7 @@ func generateTarFile(t *testing.T, path string) ([]byte, []string) { } func createFromSnapshot(t *testing.T, req *gitalypb.CreateRepositoryFromSnapshotRequest) (*gitalypb.CreateRepositoryFromSnapshotResponse, error) { - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) diff --git a/internal/service/repository/create_from_url.go b/internal/service/repository/create_from_url.go index 0c03d7c99..041167dda 100644 --- a/internal/service/repository/create_from_url.go +++ b/internal/service/repository/create_from_url.go @@ -51,7 +51,7 @@ func (s *server) CreateRepositoryFromURL(ctx context.Context, req *gitalypb.Crea repository := req.Repository - repositoryFullPath, err := helper.GetPath(repository) + repositoryFullPath, err := helper.GetRepositoryPath(repository, s.storages) if err != nil { return nil, err } diff --git a/internal/service/repository/create_from_url_test.go b/internal/service/repository/create_from_url_test.go index 26c84a4c5..9d5a04dbd 100644 --- a/internal/service/repository/create_from_url_test.go +++ b/internal/service/repository/create_from_url_test.go @@ -11,6 +11,7 @@ import ( "testing" "github.com/stretchr/testify/require" + "gitlab.com/gitlab-org/gitaly/internal/config" "gitlab.com/gitlab-org/gitaly/internal/helper" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" @@ -18,7 +19,7 @@ import ( ) func TestSuccessfulCreateRepositoryFromURLRequest(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -50,7 +51,7 @@ func TestSuccessfulCreateRepositoryFromURLRequest(t *testing.T) { _, err := client.CreateRepositoryFromURL(ctx, req) require.NoError(t, err) - importedRepoPath, err := helper.GetRepoPath(importedRepo) + importedRepoPath, err := helper.GetValidatedRepoPath(importedRepo, config.Config.Storages) require.NoError(t, err) defer os.RemoveAll(importedRepoPath) @@ -86,7 +87,7 @@ func TestCloneRepositoryFromUrlCommand(t *testing.T) { } func TestFailedCreateRepositoryFromURLRequestDueToExistingTarget(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -119,7 +120,7 @@ func TestFailedCreateRepositoryFromURLRequestDueToExistingTarget(t *testing.T) { StorageName: testhelper.DefaultStorageName, } - importedRepoPath, err := helper.GetPath(importedRepo) + importedRepoPath, err := helper.GetRepositoryPath(importedRepo, config.Config.Storages) require.NoError(t, err) if testCase.isDir { @@ -141,7 +142,7 @@ func TestFailedCreateRepositoryFromURLRequestDueToExistingTarget(t *testing.T) { } func TestPreventingRedirect(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) diff --git a/internal/service/repository/create_test.go b/internal/service/repository/create_test.go index 9fe052bb5..22e684bec 100644 --- a/internal/service/repository/create_test.go +++ b/internal/service/repository/create_test.go @@ -9,6 +9,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "gitlab.com/gitlab-org/gitaly/internal/config" "gitlab.com/gitlab-org/gitaly/internal/helper" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" @@ -16,7 +17,7 @@ import ( ) func TestCreateRepositorySuccess(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -49,7 +50,7 @@ func TestCreateRepositorySuccess(t *testing.T) { } func TestCreateRepositoryFailure(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -74,7 +75,7 @@ func TestCreateRepositoryFailure(t *testing.T) { } func TestCreateRepositoryFailureInvalidArgs(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -104,7 +105,7 @@ func TestCreateRepositoryFailureInvalidArgs(t *testing.T) { } func TestCreateRepositoryIdempotent(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) diff --git a/internal/service/repository/fetch_remote_test.go b/internal/service/repository/fetch_remote_test.go index 943fc5816..ffb4d2848 100644 --- a/internal/service/repository/fetch_remote_test.go +++ b/internal/service/repository/fetch_remote_test.go @@ -21,7 +21,7 @@ import ( ) func copyRepoWithNewRemote(t *testing.T, repo *gitalypb.Repository, remote string) *gitalypb.Repository { - repoPath, err := helper.GetRepoPath(repo) + repoPath, err := helper.GetRepositoryPath(repo, config.Config.Storages) require.NoError(t, err) cloneRepo := &gitalypb.Repository{StorageName: repo.GetStorageName(), RelativePath: "fetch-remote-clone.git"} @@ -44,14 +44,14 @@ func TestFetchRemoteSuccess(t *testing.T) { testRepo, _, cleanupFn := testhelper.NewTestRepo(t) defer cleanupFn() - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, _ := newRepositoryClient(t, serverSocketPath) cloneRepo := copyRepoWithNewRemote(t, testRepo, "my-remote") defer func(r *gitalypb.Repository) { - path, err := helper.GetRepoPath(r) + path, err := helper.GetValidatedRepoPath(r, config.Config.Storages) if err != nil { panic(err) } @@ -68,7 +68,7 @@ func TestFetchRemoteSuccess(t *testing.T) { } func TestFetchRemoteFailure(t *testing.T) { - server := NewServer(RubyServer, config.GitalyInternalSocketPath()) + server := NewServer(RubyServer, config.Config.Storages, config.GitalyInternalSocketPath()) tests := []struct { desc string @@ -130,7 +130,7 @@ func getRefnames(t *testing.T, repoPath string) []string { } func TestFetchRemoteOverHTTP(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -186,7 +186,7 @@ func TestFetchRemoteOverHTTP(t *testing.T) { } func TestFetchRemoteOverHTTPWithRedirect(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -217,7 +217,7 @@ func TestFetchRemoteOverHTTPWithRedirect(t *testing.T) { } func TestFetchRemoteOverHTTPError(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) diff --git a/internal/service/repository/fetch_test.go b/internal/service/repository/fetch_test.go index 9257f1a90..b031de143 100644 --- a/internal/service/repository/fetch_test.go +++ b/internal/service/repository/fetch_test.go @@ -20,7 +20,7 @@ import ( ) func TestFetchSourceBranchSourceRepositorySuccess(t *testing.T) { - server, serverSocketPath := runFullServer(t) + server, serverSocketPath := runFullServer(t, config.Config.Storages) defer server.Stop() client, conn := repository.NewRepositoryClient(t, serverSocketPath) @@ -59,7 +59,7 @@ func TestFetchSourceBranchSourceRepositorySuccess(t *testing.T) { } func TestFetchSourceBranchSameRepositorySuccess(t *testing.T) { - server, serverSocketPath := runFullServer(t) + server, serverSocketPath := runFullServer(t, config.Config.Storages) defer server.Stop() client, conn := repository.NewRepositoryClient(t, serverSocketPath) @@ -95,7 +95,7 @@ func TestFetchSourceBranchSameRepositorySuccess(t *testing.T) { } func TestFetchSourceBranchBranchNotFound(t *testing.T) { - server, serverSocketPath := runFullServer(t) + server, serverSocketPath := runFullServer(t, config.Config.Storages) defer server.Stop() client, conn := repository.NewRepositoryClient(t, serverSocketPath) @@ -156,7 +156,7 @@ func TestFetchFullServerRequiresAuthentication(t *testing.T) { // we want to be sure that authentication is handled correctly. If the // tests in this file were using a server without authentication we could // not be confident that authentication is done right. - server, serverSocketPath := runFullServer(t) + server, serverSocketPath := runFullServer(t, config.Config.Storages) defer server.Stop() connOpts := []grpc.DialOption{ @@ -181,7 +181,7 @@ func newTestRepo(t *testing.T, relativePath string) (*gitalypb.Repository, strin repo := &gitalypb.Repository{StorageName: "default", RelativePath: relativePath} - repoPath, err := helper.GetPath(repo) + repoPath, err := helper.GetRepositoryPath(repo, config.Config.Storages) require.NoError(t, err) require.NoError(t, os.RemoveAll(repoPath)) @@ -190,8 +190,11 @@ func newTestRepo(t *testing.T, relativePath string) (*gitalypb.Repository, strin return repo, repoPath, func() { require.NoError(t, os.RemoveAll(repoPath)) } } -func runFullServer(t *testing.T) (*grpc.Server, string) { - server := serverPkg.NewInsecure(repository.RubyServer, config.Config) +func runFullServer(t *testing.T, storages config.Storages) (*grpc.Server, string) { + cfg := config.Config + cfg.Storages = storages + + server := serverPkg.NewInsecure(repository.RubyServer, cfg) serverSocketPath := testhelper.GetTemporaryGitalySocketFileName() listener, err := net.Listen("unix", serverSocketPath) diff --git a/internal/service/repository/fork.go b/internal/service/repository/fork.go index c379e835a..e5fcafb00 100644 --- a/internal/service/repository/fork.go +++ b/internal/service/repository/fork.go @@ -26,7 +26,7 @@ func (s *server) CreateFork(ctx context.Context, req *gitalypb.CreateForkRequest return nil, status.Errorf(codes.InvalidArgument, "CreateFork: empty Repository") } - targetRepositoryFullPath, err := helper.GetPath(targetRepository) + targetRepositoryFullPath, err := helper.GetRepositoryPath(targetRepository, s.storages) if err != nil { return nil, err } diff --git a/internal/service/repository/fork_test.go b/internal/service/repository/fork_test.go index 7f603823b..13f39dda4 100644 --- a/internal/service/repository/fork_test.go +++ b/internal/service/repository/fork_test.go @@ -54,7 +54,7 @@ func TestSuccessfulCreateForkRequest(t *testing.T) { client, conn = repository.NewSecureRepoClient(t, serverSocketPath, testPool) defer conn.Close() } else { - server, serverSocketPath = runFullServer(t) + server, serverSocketPath = runFullServer(t, config.Config.Storages) defer server.Stop() client, conn = repository.NewRepositoryClient(t, serverSocketPath) @@ -75,7 +75,7 @@ func TestSuccessfulCreateForkRequest(t *testing.T) { StorageName: testRepo.StorageName, } - forkedRepoPath, err := helper.GetPath(forkedRepo) + forkedRepoPath, err := helper.GetRepositoryPath(forkedRepo, config.Config.Storages) require.NoError(t, err) require.NoError(t, os.RemoveAll(forkedRepoPath)) @@ -101,7 +101,7 @@ func TestSuccessfulCreateForkRequest(t *testing.T) { } func TestFailedCreateForkRequestDueToExistingTarget(t *testing.T) { - server, serverSocketPath := runFullServer(t) + server, serverSocketPath := runFullServer(t, config.Config.Storages) defer server.Stop() client, conn := repository.NewRepositoryClient(t, serverSocketPath) @@ -140,7 +140,7 @@ func TestFailedCreateForkRequestDueToExistingTarget(t *testing.T) { StorageName: testRepo.StorageName, } - forkedRepoPath, err := helper.GetPath(forkedRepo) + forkedRepoPath, err := helper.GetRepositoryPath(forkedRepo, config.Config.Storages) require.NoError(t, err) if testCase.isDir { diff --git a/internal/service/repository/fsck_test.go b/internal/service/repository/fsck_test.go index 05727d9ea..3b04235a5 100644 --- a/internal/service/repository/fsck_test.go +++ b/internal/service/repository/fsck_test.go @@ -8,6 +8,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "gitlab.com/gitlab-org/gitaly/internal/config" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" ) @@ -16,7 +17,7 @@ func TestFsckSuccess(t *testing.T) { ctx, cancel := testhelper.Context() defer cancel() - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -35,7 +36,7 @@ func TestFsckFailureSeverelyBrokenRepo(t *testing.T) { ctx, cancel := testhelper.Context() defer cancel() - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -61,7 +62,7 @@ func TestFsckFailureSlightlyBrokenRepo(t *testing.T) { ctx, cancel := testhelper.Context() defer cancel() - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) diff --git a/internal/service/repository/gc.go b/internal/service/repository/gc.go index ab4099855..97a5afcd0 100644 --- a/internal/service/repository/gc.go +++ b/internal/service/repository/gc.go @@ -19,23 +19,23 @@ import ( "google.golang.org/grpc/status" ) -func (*server) GarbageCollect(ctx context.Context, in *gitalypb.GarbageCollectRequest) (*gitalypb.GarbageCollectResponse, error) { +func (s *server) GarbageCollect(ctx context.Context, in *gitalypb.GarbageCollectRequest) (*gitalypb.GarbageCollectResponse, error) { ctxlogger := ctxlogrus.Extract(ctx) ctxlogger.WithFields(log.Fields{ "WriteBitmaps": in.GetCreateBitmap(), }).Debug("GarbageCollect") repo := in.GetRepository() - repoPath, err := helper.GetRepoPath(repo) + repoPath, err := helper.GetValidatedRepoPath(repo, s.storages) if err != nil { return nil, err } - if err := cleanupRepo(ctx, in.GetRepository()); err != nil { + if err := s.cleanupRepo(ctx, in.GetRepository()); err != nil { return nil, err } - if err := cleanupKeepArounds(ctx, in.GetRepository()); err != nil { + if err := s.cleanupKeepArounds(ctx, in.GetRepository()); err != nil { return nil, err } @@ -109,8 +109,8 @@ func configureCommitGraph(ctx context.Context, in *gitalypb.GarbageCollectReques return nil } -func cleanupKeepArounds(ctx context.Context, repo *gitalypb.Repository) error { - repoPath, err := helper.GetRepoPath(repo) +func (s *server) cleanupKeepArounds(ctx context.Context, repo *gitalypb.Repository) error { + repoPath, err := helper.GetValidatedRepoPath(repo, s.storages) if err != nil { return nil } diff --git a/internal/service/repository/gc_test.go b/internal/service/repository/gc_test.go index c3823bc38..22597d8bc 100644 --- a/internal/service/repository/gc_test.go +++ b/internal/service/repository/gc_test.go @@ -15,6 +15,7 @@ import ( "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "gitlab.com/gitlab-org/gitaly/internal/config" "gitlab.com/gitlab-org/gitaly/internal/git/gittest" "gitlab.com/gitlab-org/gitaly/internal/helper/text" "gitlab.com/gitlab-org/gitaly/internal/testhelper" @@ -30,7 +31,7 @@ var ( ) func TestGarbageCollectCommitGraph(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -66,7 +67,7 @@ func TestGarbageCollectCommitGraph(t *testing.T) { } func TestGarbageCollectSuccess(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -137,7 +138,7 @@ func TestGarbageCollectLogStatistics(t *testing.T) { defer cancel() ctx = ctxlogrus.ToContext(ctx, log.WithField("test", "logging")) - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -153,7 +154,7 @@ func TestGarbageCollectLogStatistics(t *testing.T) { } func TestGarbageCollectDeletesRefsLocks(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -201,7 +202,7 @@ func TestGarbageCollectDeletesRefsLocks(t *testing.T) { } func TestGarbageCollectFailure(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -231,7 +232,7 @@ func TestGarbageCollectFailure(t *testing.T) { } func TestCleanupInvalidKeepAroundRefs(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -328,7 +329,7 @@ func createFileWithTimes(path string, mTime time.Time) { } func TestGarbageCollectDeltaIslands(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) diff --git a/internal/service/repository/info_attributes.go b/internal/service/repository/info_attributes.go index b5399fce8..a8f171bab 100644 --- a/internal/service/repository/info_attributes.go +++ b/internal/service/repository/info_attributes.go @@ -1,6 +1,7 @@ package repository import ( + "fmt" "io" "os" "path" @@ -13,8 +14,9 @@ import ( ) func (s *server) GetInfoAttributes(in *gitalypb.GetInfoAttributesRequest, stream gitalypb.RepositoryService_GetInfoAttributesServer) error { - repoPath, err := helper.GetRepoPath(in.GetRepository()) + repoPath, err := helper.GetValidatedRepoPath(in.GetRepository(), s.storages) if err != nil { + fmt.Printf("\n WHA??? %v\n", err) return err } diff --git a/internal/service/repository/info_attributes_test.go b/internal/service/repository/info_attributes_test.go index 86096dc03..cb1c4c538 100644 --- a/internal/service/repository/info_attributes_test.go +++ b/internal/service/repository/info_attributes_test.go @@ -8,13 +8,14 @@ import ( "testing" "github.com/stretchr/testify/require" + "gitlab.com/gitlab-org/gitaly/internal/config" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" "gitlab.com/gitlab-org/gitaly/streamio" ) func TestGetInfoAttributesExisting(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -49,7 +50,7 @@ func TestGetInfoAttributesExisting(t *testing.T) { } func TestGetInfoAttributesNonExisting(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) diff --git a/internal/service/repository/license_test.go b/internal/service/repository/license_test.go index 63886c5f6..ed3a060a7 100644 --- a/internal/service/repository/license_test.go +++ b/internal/service/repository/license_test.go @@ -5,13 +5,14 @@ import ( "testing" "github.com/stretchr/testify/require" + "gitlab.com/gitlab-org/gitaly/internal/config" "gitlab.com/gitlab-org/gitaly/internal/helper" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" ) func TestSuccessfulFindLicenseRequest(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -32,7 +33,7 @@ func TestSuccessfulFindLicenseRequest(t *testing.T) { } func TestFindLicenseRequestEmptyRepo(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -49,7 +50,7 @@ func TestFindLicenseRequestEmptyRepo(t *testing.T) { _, err := client.CreateRepository(ctx, &gitalypb.CreateRepositoryRequest{Repository: emptyRepo}) require.NoError(t, err) - emptyRepoPath, err := helper.GetRepoPath(emptyRepo) + emptyRepoPath, err := helper.GetValidatedRepoPath(emptyRepo, config.Config.Storages) require.NoError(t, err) defer os.RemoveAll(emptyRepoPath) diff --git a/internal/service/repository/merge_base_test.go b/internal/service/repository/merge_base_test.go index 35b394f8c..da45e257b 100644 --- a/internal/service/repository/merge_base_test.go +++ b/internal/service/repository/merge_base_test.go @@ -4,13 +4,14 @@ import ( "testing" "github.com/stretchr/testify/require" + "gitlab.com/gitlab-org/gitaly/internal/config" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" "google.golang.org/grpc/codes" ) func TestSuccessfulFindFindMergeBaseRequest(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -86,7 +87,7 @@ func TestSuccessfulFindFindMergeBaseRequest(t *testing.T) { } func TestFailedFindMergeBaseRequestDueToValidations(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) diff --git a/internal/service/repository/raw_changes_test.go b/internal/service/repository/raw_changes_test.go index 07cc8f975..62d9f49bc 100644 --- a/internal/service/repository/raw_changes_test.go +++ b/internal/service/repository/raw_changes_test.go @@ -7,13 +7,14 @@ import ( "unicode/utf8" "github.com/stretchr/testify/require" + "gitlab.com/gitlab-org/gitaly/internal/config" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" "google.golang.org/grpc/codes" ) func TestGetRawChanges(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -130,7 +131,7 @@ func TestGetRawChangesSpecialCharacters(t *testing.T) { // This test looks for a specific path known to contain special // characters. - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -174,7 +175,7 @@ func collectChanges(t *testing.T, stream gitalypb.RepositoryService_GetRawChange } func TestGetRawChangesFailures(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -236,7 +237,7 @@ func TestGetRawChangesFailures(t *testing.T) { } func TestGetRawChangesManyFiles(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -264,7 +265,7 @@ func TestGetRawChangesManyFiles(t *testing.T) { } func TestGetRawChangesMappingOperations(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -315,7 +316,7 @@ func TestGetRawChangesMappingOperations(t *testing.T) { } func TestGetRawChangesInvalidUTF8Paths(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) diff --git a/internal/service/repository/rebase_in_progress.go b/internal/service/repository/rebase_in_progress.go index d129741e0..108cb8191 100644 --- a/internal/service/repository/rebase_in_progress.go +++ b/internal/service/repository/rebase_in_progress.go @@ -26,7 +26,7 @@ func (s *server) IsRebaseInProgress(ctx context.Context, req *gitalypb.IsRebaseI return nil, status.Errorf(codes.InvalidArgument, "IsRebaseInProgress: %v", err) } - repoPath, err := helper.GetRepoPath(req.GetRepository()) + repoPath, err := helper.GetValidatedRepoPath(req.GetRepository(), s.storages) if err != nil { return nil, err } diff --git a/internal/service/repository/rebase_in_progress_test.go b/internal/service/repository/rebase_in_progress_test.go index 9f99b678c..0974f8c99 100644 --- a/internal/service/repository/rebase_in_progress_test.go +++ b/internal/service/repository/rebase_in_progress_test.go @@ -8,13 +8,14 @@ import ( "time" "github.com/stretchr/testify/require" + "gitlab.com/gitlab-org/gitaly/internal/config" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" "google.golang.org/grpc/codes" ) func TestSuccessfulIsRebaseInProgressRequest(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -94,7 +95,7 @@ func TestSuccessfulIsRebaseInProgressRequest(t *testing.T) { } func TestFailedIsRebaseInProgressRequestDueToValidations(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) diff --git a/internal/service/repository/remove.go b/internal/service/repository/remove.go index 387d8d341..9e2779b35 100644 --- a/internal/service/repository/remove.go +++ b/internal/service/repository/remove.go @@ -12,7 +12,7 @@ import ( ) func (s *server) RemoveRepository(ctx context.Context, in *gitalypb.RemoveRepositoryRequest) (*gitalypb.RemoveRepositoryResponse, error) { - path, err := helper.GetPath(in.Repository) + path, err := helper.GetRepositoryPath(in.Repository, s.storages) if err != nil { return nil, helper.ErrInternal(err) } diff --git a/internal/service/repository/remove_test.go b/internal/service/repository/remove_test.go index 24b31f1cd..07916f795 100644 --- a/internal/service/repository/remove_test.go +++ b/internal/service/repository/remove_test.go @@ -4,12 +4,13 @@ import ( "testing" "github.com/stretchr/testify/require" + "gitlab.com/gitlab-org/gitaly/internal/config" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" ) func TestRemoveRepository(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -28,7 +29,7 @@ func TestRemoveRepository(t *testing.T) { } func TestRemoveRepositoryDoesNotExist(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) diff --git a/internal/service/repository/rename.go b/internal/service/repository/rename.go index 10bbee028..1ea124c92 100644 --- a/internal/service/repository/rename.go +++ b/internal/service/repository/rename.go @@ -15,12 +15,12 @@ func (s *server) RenameRepository(ctx context.Context, in *gitalypb.RenameReposi return nil, helper.ErrInvalidArgument(err) } - fromFullPath, err := helper.GetRepoPath(in.GetRepository()) + fromFullPath, err := helper.GetValidatedRepoPath(in.GetRepository(), s.storages) if err != nil { return nil, helper.ErrInvalidArgument(err) } - toFullPath, err := helper.GetPath(&gitalypb.Repository{StorageName: in.GetRepository().GetStorageName(), RelativePath: in.GetRelativePath()}) + toFullPath, err := helper.GetRepositoryPath(&gitalypb.Repository{StorageName: in.GetRepository().GetStorageName(), RelativePath: in.GetRelativePath()}, s.storages) if err != nil { return nil, helper.ErrInvalidArgument(err) } diff --git a/internal/service/repository/rename_test.go b/internal/service/repository/rename_test.go index 2727f243a..39fa894cc 100644 --- a/internal/service/repository/rename_test.go +++ b/internal/service/repository/rename_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/stretchr/testify/require" + "gitlab.com/gitlab-org/gitaly/internal/config" "gitlab.com/gitlab-org/gitaly/internal/helper" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" @@ -12,7 +13,7 @@ import ( ) func TestRenameRepositorySuccess(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -29,7 +30,7 @@ func TestRenameRepositorySuccess(t *testing.T) { _, err := client.RenameRepository(ctx, req) require.NoError(t, err) - newDirectory, err := helper.GetPath(&gitalypb.Repository{StorageName: "default", RelativePath: req.RelativePath}) + newDirectory, err := helper.GetRepositoryPath(&gitalypb.Repository{StorageName: "default", RelativePath: req.RelativePath}, config.Config.Storages) require.NoError(t, err) require.DirExists(t, newDirectory) defer func() { require.NoError(t, os.RemoveAll(newDirectory)) }() @@ -41,7 +42,7 @@ func TestRenameRepositorySuccess(t *testing.T) { } func TestRenameRepositoryDestinationExists(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -68,7 +69,7 @@ func TestRenameRepositoryDestinationExists(t *testing.T) { } func TestRenameRepositoryInvalidRequest(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) diff --git a/internal/service/repository/repack_test.go b/internal/service/repository/repack_test.go index b3b0d584d..47588a828 100644 --- a/internal/service/repository/repack_test.go +++ b/internal/service/repository/repack_test.go @@ -15,6 +15,7 @@ import ( "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "gitlab.com/gitlab-org/gitaly/internal/config" "gitlab.com/gitlab-org/gitaly/internal/git/gittest" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" @@ -23,7 +24,7 @@ import ( ) func TestRepackIncrementalSuccess(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -63,7 +64,7 @@ func TestRepackIncrementalCollectLogStatistics(t *testing.T) { defer cancel() ctx = ctxlogrus.ToContext(ctx, log.WithField("test", "logging")) - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -79,7 +80,7 @@ func TestRepackIncrementalCollectLogStatistics(t *testing.T) { } func TestRepackLocal(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -118,7 +119,7 @@ func TestRepackLocal(t *testing.T) { } func TestRepackIncrementalFailure(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -146,7 +147,7 @@ func TestRepackIncrementalFailure(t *testing.T) { } func TestRepackFullSuccess(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -212,7 +213,7 @@ func TestRepackFullCollectLogStatistics(t *testing.T) { defer cancel() ctx = ctxlogrus.ToContext(ctx, log.WithField("test", "logging")) - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -254,7 +255,7 @@ func doBitmapsContainHashCache(t *testing.T, bitmapPaths []string) { } func TestRepackFullFailure(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -282,7 +283,7 @@ func TestRepackFullFailure(t *testing.T) { } func TestRepackFullDeltaIslands(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) diff --git a/internal/service/repository/replicate.go b/internal/service/repository/replicate.go index 3952bd242..1505b8033 100644 --- a/internal/service/repository/replicate.go +++ b/internal/service/repository/replicate.go @@ -31,7 +31,7 @@ func (s *server) ReplicateRepository(ctx context.Context, in *gitalypb.Replicate s.syncInfoAttributes, } - repoPath, err := helper.GetPath(in.GetRepository()) + repoPath, err := helper.GetRepositoryPath(in.GetRepository(), s.storages) if err != nil { return nil, helper.ErrInternal(err) } @@ -82,7 +82,7 @@ func validateReplicateRepository(in *gitalypb.ReplicateRepositoryRequest) error func (s *server) create(ctx context.Context, in *gitalypb.ReplicateRepositoryRequest, repoPath string) error { // if the directory exists, remove it if _, err := os.Stat(repoPath); err == nil { - tempDir, err := tempdir.ForDeleteAllRepositories(in.GetRepository().GetStorageName()) + tempDir, err := tempdir.ForDeleteAllRepositories(s.storages, in.GetRepository().GetStorageName()) if err != nil { return err } @@ -102,7 +102,7 @@ func (s *server) create(ctx context.Context, in *gitalypb.ReplicateRepositoryReq } func (s *server) createFromSnapshot(ctx context.Context, in *gitalypb.ReplicateRepositoryRequest) error { - tempRepo, tempPath, err := tempdir.NewAsRepository(ctx, in.GetRepository()) + tempRepo, tempPath, err := tempdir.NewAsRepository(ctx, s.storages, in.GetRepository()) if err != nil { return err } @@ -137,7 +137,7 @@ func (s *server) createFromSnapshot(ctx context.Context, in *gitalypb.ReplicateR return err } - targetPath, err := helper.GetPath(in.GetRepository()) + targetPath, err := helper.GetRepositoryPath(in.GetRepository(), s.storages) if err != nil { return err } @@ -180,7 +180,7 @@ func (s *server) syncInfoAttributes(ctx context.Context, in *gitalypb.ReplicateR return err } - repoPath, err := helper.GetRepoPath(in.GetRepository()) + repoPath, err := helper.GetValidatedRepoPath(in.GetRepository(), s.storages) if err != nil { return err } diff --git a/internal/service/repository/replicate_test.go b/internal/service/repository/replicate_test.go index a17b3988d..7be217921 100644 --- a/internal/service/repository/replicate_test.go +++ b/internal/service/repository/replicate_test.go @@ -31,11 +31,7 @@ func TestReplicateRepository(t *testing.T) { replicaPath := filepath.Join(tmpPath, "replica") require.NoError(t, os.MkdirAll(replicaPath, 0755)) - defer func(storages []config.Storage) { - config.Config.Storages = storages - }(config.Config.Storages) - - config.Config.Storages = []config.Storage{ + storages := []config.Storage{ config.Storage{ Name: "default", Path: testhelper.GitlabTestStoragePath(), @@ -46,7 +42,7 @@ func TestReplicateRepository(t *testing.T) { }, } - server, serverSocketPath := runFullServer(t) + server, serverSocketPath := runFullServer(t, storages) defer server.Stop() testRepo, testRepoPath, cleanupRepo := testhelper.NewTestRepo(t) @@ -81,7 +77,7 @@ func TestReplicateRepository(t *testing.T) { }) require.NoError(t, err) - targetRepoPath, err := helper.GetRepoPath(&targetRepo) + targetRepoPath, err := helper.GetValidatedRepoPath(&targetRepo, storages) require.NoError(t, err) testhelper.MustRunCommand(t, nil, "git", "-C", targetRepoPath, "fsck") @@ -179,7 +175,7 @@ func TestReplicateRepositoryInvalidArguments(t *testing.T) { }, } - serverSocketPath, stop := repository.RunRepoServer(t) + serverSocketPath, stop := repository.RunRepoServer(t, config.Config.Storages) defer stop() client, conn := repository.NewRepositoryClient(t, serverSocketPath) @@ -203,11 +199,7 @@ func TestReplicateRepository_BadRepository(t *testing.T) { replicaPath := filepath.Join(tmpPath, "replica") require.NoError(t, os.MkdirAll(replicaPath, 0755)) - defer func(storages []config.Storage) { - config.Config.Storages = storages - }(config.Config.Storages) - - config.Config.Storages = []config.Storage{ + storages := []config.Storage{ config.Storage{ Name: "default", Path: testhelper.GitlabTestStoragePath(), @@ -218,7 +210,7 @@ func TestReplicateRepository_BadRepository(t *testing.T) { }, } - server, serverSocketPath := runFullServer(t) + server, serverSocketPath := runFullServer(t, storages) defer server.Stop() testRepo, _, cleanupRepo := testhelper.NewTestRepo(t) @@ -232,7 +224,7 @@ func TestReplicateRepository_BadRepository(t *testing.T) { targetRepo := *testRepo targetRepo.StorageName = "replica" - targetRepoPath, err := helper.GetPath(&targetRepo) + targetRepoPath, err := helper.GetRepositoryPath(&targetRepo, storages) require.NoError(t, err) require.NoError(t, os.MkdirAll(targetRepoPath, 0755)) @@ -260,11 +252,7 @@ func TestReplicateRepository_FailedFetchInternalRemote(t *testing.T) { replicaPath := filepath.Join(tmpPath, "replica") require.NoError(t, os.MkdirAll(replicaPath, 0755)) - defer func(storages []config.Storage) { - config.Config.Storages = storages - }(config.Config.Storages) - - config.Config.Storages = []config.Storage{ + storages := []config.Storage{ config.Storage{ Name: "default", Path: testhelper.GitlabTestStoragePath(), @@ -275,7 +263,7 @@ func TestReplicateRepository_FailedFetchInternalRemote(t *testing.T) { }, } - server, serverSocketPath := runServerWithBadFetchInternalRemote(t) + server, serverSocketPath := runServerWithBadFetchInternalRemote(t, storages) defer server.Stop() testRepo, _, cleanupRepo := testhelper.NewTestRepo(t) @@ -289,7 +277,7 @@ func TestReplicateRepository_FailedFetchInternalRemote(t *testing.T) { targetRepo := *testRepo targetRepo.StorageName = "replica" - targetRepoPath, err := helper.GetPath(&targetRepo) + targetRepoPath, err := helper.GetRepositoryPath(&targetRepo, storages) require.NoError(t, err) require.NoError(t, os.MkdirAll(targetRepoPath, 0755)) @@ -315,7 +303,7 @@ func TestReplicateRepository_FailedFetchInternalRemote(t *testing.T) { require.Error(t, err) } -func runServerWithBadFetchInternalRemote(t *testing.T) (*grpc.Server, string) { +func runServerWithBadFetchInternalRemote(t *testing.T, storages config.Storages) (*grpc.Server, string) { server := testhelper.NewTestGrpcServer(t, nil, nil) serverSocketPath := testhelper.GetTemporaryGitalySocketFileName() @@ -325,7 +313,7 @@ func runServerWithBadFetchInternalRemote(t *testing.T) (*grpc.Server, string) { internalListener, err := net.Listen("unix", config.GitalyInternalSocketPath()) require.NoError(t, err) - gitalypb.RegisterRepositoryServiceServer(server, repository.NewServer(repository.RubyServer, config.GitalyInternalSocketPath())) + gitalypb.RegisterRepositoryServiceServer(server, repository.NewServer(repository.RubyServer, storages, config.GitalyInternalSocketPath())) gitalypb.RegisterRemoteServiceServer(server, &mockRemoteServer{}) reflection.Register(server) diff --git a/internal/service/repository/repository.go b/internal/service/repository/repository.go index e0282e994..f682675e1 100644 --- a/internal/service/repository/repository.go +++ b/internal/service/repository/repository.go @@ -17,7 +17,7 @@ func (s *server) Exists(ctx context.Context, in *gitalypb.RepositoryExistsReques } func (s *server) RepositoryExists(ctx context.Context, in *gitalypb.RepositoryExistsRequest) (*gitalypb.RepositoryExistsResponse, error) { - path, err := helper.GetPath(in.Repository) + path, err := helper.GetRepositoryPath(in.Repository, s.storages) if err != nil { return nil, err } diff --git a/internal/service/repository/repository_test.go b/internal/service/repository/repository_test.go index 0a50c0883..71bd74435 100644 --- a/internal/service/repository/repository_test.go +++ b/internal/service/repository/repository_test.go @@ -16,27 +16,22 @@ import ( ) func TestRepositoryExists(t *testing.T) { - serverSocketPath, stop := runRepoServer(t, testhelper.WithStorages([]string{"default", "other", "broken"})) - defer stop() - + // Setup storage paths storageOtherDir, err := ioutil.TempDir("", "gitaly-repository-exists-test") require.NoError(t, err, "tempdir") defer os.Remove(storageOtherDir) - client, conn := newRepositoryClient(t, serverSocketPath) - defer conn.Close() - - // Setup storage paths testStorages := []config.Storage{ {Name: "default", Path: testhelper.GitlabTestStoragePath()}, {Name: "other", Path: storageOtherDir}, {Name: "broken", Path: "/does/not/exist"}, } - defer func(oldStorages []config.Storage) { - config.Config.Storages = oldStorages - }(config.Config.Storages) - config.Config.Storages = testStorages + serverSocketPath, stop := runRepoServer(t, testStorages) + defer stop() + + client, conn := newRepositoryClient(t, serverSocketPath) + defer conn.Close() queries := []struct { desc string @@ -122,7 +117,7 @@ func TestRepositoryExists(t *testing.T) { } func TestSuccessfulHasLocalBranches(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -177,7 +172,7 @@ func TestSuccessfulHasLocalBranches(t *testing.T) { } func TestFailedHasLocalBranches(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) diff --git a/internal/service/repository/restore_custom_hooks.go b/internal/service/repository/restore_custom_hooks.go index 0b7dbdf21..bf5ad311c 100644 --- a/internal/service/repository/restore_custom_hooks.go +++ b/internal/service/repository/restore_custom_hooks.go @@ -33,7 +33,7 @@ func (s *server) RestoreCustomHooks(stream gitalypb.RepositoryService_RestoreCus return request.GetData(), err }) - repoPath, err := helper.GetPath(repo) + repoPath, err := helper.GetRepositoryPath(repo, s.storages) if err != nil { return status.Errorf(codes.Internal, "RestoreCustomHooks: getting repo path failed %v", err) } diff --git a/internal/service/repository/restore_custom_hooks_test.go b/internal/service/repository/restore_custom_hooks_test.go index f8e6ea806..74aaad6e0 100644 --- a/internal/service/repository/restore_custom_hooks_test.go +++ b/internal/service/repository/restore_custom_hooks_test.go @@ -7,6 +7,7 @@ import ( "testing" "github.com/stretchr/testify/require" + "gitlab.com/gitlab-org/gitaly/internal/config" "gitlab.com/gitlab-org/gitaly/internal/helper" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" @@ -15,7 +16,7 @@ import ( ) func TestSuccessfullRestoreCustomHooksRequest(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -32,7 +33,7 @@ func TestSuccessfullRestoreCustomHooksRequest(t *testing.T) { require.NoError(t, err) - repoPath, err := helper.GetPath(testRepo) + repoPath, err := helper.GetRepositoryPath(testRepo, config.Config.Storages) require.NoError(t, err) defer os.RemoveAll(repoPath) request := &gitalypb.RestoreCustomHooksRequest{Repository: testRepo} @@ -59,7 +60,7 @@ func TestSuccessfullRestoreCustomHooksRequest(t *testing.T) { } func TestFailedRestoreCustomHooksDueToValidations(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -78,7 +79,7 @@ func TestFailedRestoreCustomHooksDueToValidations(t *testing.T) { } func TestFailedRestoreCustomHooksDueToBadTar(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -95,7 +96,7 @@ func TestFailedRestoreCustomHooksDueToBadTar(t *testing.T) { require.NoError(t, err) - repoPath, err := helper.GetPath(testRepo) + repoPath, err := helper.GetRepositoryPath(testRepo, config.Config.Storages) require.NoError(t, err) defer os.RemoveAll(repoPath) request := &gitalypb.RestoreCustomHooksRequest{Repository: testRepo} diff --git a/internal/service/repository/search_files_test.go b/internal/service/repository/search_files_test.go index 26504fb20..86be0c0d9 100644 --- a/internal/service/repository/search_files_test.go +++ b/internal/service/repository/search_files_test.go @@ -80,7 +80,7 @@ func TestSearchFilesByContentSuccessful(t *testing.T) { ctx, cancel := testhelper.Context() defer cancel() - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -152,7 +152,7 @@ func TestSearchFilesByContentLargeFile(t *testing.T) { ctx, cancel := testhelper.Context() defer cancel() - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -209,7 +209,7 @@ func TestSearchFilesByContentLargeFile(t *testing.T) { } func TestSearchFilesByContentFailure(t *testing.T) { - server := NewServer(RubyServer, config.GitalyInternalSocketPath()) + server := NewServer(RubyServer, config.Config.Storages, config.GitalyInternalSocketPath()) testRepo, _, cleanupRepo := testhelper.NewTestRepo(t) defer cleanupRepo() @@ -268,7 +268,7 @@ func TestSearchFilesByNameSuccessful(t *testing.T) { ctx, cancel := testhelper.Context() defer cancel() - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -315,7 +315,7 @@ func TestSearchFilesByNameSuccessful(t *testing.T) { } func TestSearchFilesByNameFailure(t *testing.T) { - server := NewServer(RubyServer, config.GitalyInternalSocketPath()) + server := NewServer(RubyServer, config.Config.Storages, config.GitalyInternalSocketPath()) testCases := []struct { desc string diff --git a/internal/service/repository/server.go b/internal/service/repository/server.go index 563b9c2a1..037d432be 100644 --- a/internal/service/repository/server.go +++ b/internal/service/repository/server.go @@ -4,6 +4,7 @@ import ( "context" "sync" + "gitlab.com/gitlab-org/gitaly/internal/config" "gitlab.com/gitlab-org/gitaly/internal/helper" "gitlab.com/gitlab-org/gitaly/internal/rubyserver" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" @@ -16,11 +17,12 @@ type server struct { connsByAddress map[string]*grpc.ClientConn connsMtx sync.RWMutex internalGitalySocket string + storages config.Storages } // NewServer creates a new instance of a gRPC repo server -func NewServer(rs *rubyserver.Server, internalGitalySocket string) gitalypb.RepositoryServiceServer { - return &server{ruby: rs, connsByAddress: make(map[string]*grpc.ClientConn), internalGitalySocket: internalGitalySocket} +func NewServer(rs *rubyserver.Server, storages config.Storages, internalGitalySocket string) gitalypb.RepositoryServiceServer { + return &server{ruby: rs, connsByAddress: make(map[string]*grpc.ClientConn), storages: storages, internalGitalySocket: internalGitalySocket} } func (*server) FetchHTTPRemote(context.Context, *gitalypb.FetchHTTPRemoteRequest) (*gitalypb.FetchHTTPRemoteResponse, error) { diff --git a/internal/service/repository/size.go b/internal/service/repository/size.go index b966f4bd8..e5d80cf73 100644 --- a/internal/service/repository/size.go +++ b/internal/service/repository/size.go @@ -15,7 +15,7 @@ import ( ) func (s *server) RepositorySize(ctx context.Context, in *gitalypb.RepositorySizeRequest) (*gitalypb.RepositorySizeResponse, error) { - path, err := helper.GetPath(in.Repository) + path, err := helper.GetRepositoryPath(in.Repository, s.storages) if err != nil { return nil, err } diff --git a/internal/service/repository/size_test.go b/internal/service/repository/size_test.go index c227f82c7..b91fe5379 100644 --- a/internal/service/repository/size_test.go +++ b/internal/service/repository/size_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/stretchr/testify/require" + "gitlab.com/gitlab-org/gitaly/internal/config" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" "google.golang.org/grpc/codes" @@ -15,7 +16,7 @@ import ( const testRepoMinSizeKB = 10000 func TestSuccessfulRepositorySizeRequest(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -37,7 +38,7 @@ func TestSuccessfulRepositorySizeRequest(t *testing.T) { } func TestFailedRepositorySizeRequest(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -67,7 +68,7 @@ func TestFailedRepositorySizeRequest(t *testing.T) { } func TestSuccessfulGetObjectDirectorySizeRequest(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) diff --git a/internal/service/repository/snapshot.go b/internal/service/repository/snapshot.go index acfd833af..7859b5102 100644 --- a/internal/service/repository/snapshot.go +++ b/internal/service/repository/snapshot.go @@ -21,7 +21,7 @@ var objectFiles = []*regexp.Regexp{ } func (s *server) GetSnapshot(in *gitalypb.GetSnapshotRequest, stream gitalypb.RepositoryService_GetSnapshotServer) error { - path, err := helper.GetRepoPath(in.Repository) + path, err := helper.GetValidatedRepoPath(in.Repository, s.storages) if err != nil { return err } @@ -66,7 +66,7 @@ func (s *server) GetSnapshot(in *gitalypb.GetSnapshotRequest, stream gitalypb.Re // safe than sorry. builder.FileIfExist("shallow") - if err := addAlternateFiles(stream.Context(), in.GetRepository(), builder); err != nil { + if err := s.addAlternateFiles(stream.Context(), in.GetRepository(), builder); err != nil { return helper.ErrInternal(err) } @@ -77,13 +77,13 @@ func (s *server) GetSnapshot(in *gitalypb.GetSnapshotRequest, stream gitalypb.Re return nil } -func addAlternateFiles(ctx context.Context, repository *gitalypb.Repository, builder *archive.TarBuilder) error { +func (s *server) addAlternateFiles(ctx context.Context, repository *gitalypb.Repository, builder *archive.TarBuilder) error { storageRoot, err := helper.GetStorageByName(repository.GetStorageName()) if err != nil { return err } - repoPath, err := helper.GetRepoPath(repository) + repoPath, err := helper.GetValidatedRepoPath(repository, s.storages) if err != nil { return err } diff --git a/internal/service/repository/snapshot_test.go b/internal/service/repository/snapshot_test.go index c36af632c..2640aac9d 100644 --- a/internal/service/repository/snapshot_test.go +++ b/internal/service/repository/snapshot_test.go @@ -16,6 +16,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "gitlab.com/gitlab-org/gitaly/internal/archive" + "gitlab.com/gitlab-org/gitaly/internal/config" "gitlab.com/gitlab-org/gitaly/internal/git" "gitlab.com/gitlab-org/gitaly/internal/git/catfile" "gitlab.com/gitlab-org/gitaly/internal/helper" @@ -26,7 +27,7 @@ import ( ) func getSnapshot(t *testing.T, req *gitalypb.GetSnapshotRequest) ([]byte, error) { - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) diff --git a/internal/service/repository/squash_in_progress.go b/internal/service/repository/squash_in_progress.go index 20e25641a..27a483421 100644 --- a/internal/service/repository/squash_in_progress.go +++ b/internal/service/repository/squash_in_progress.go @@ -20,7 +20,7 @@ func (s *server) IsSquashInProgress(ctx context.Context, req *gitalypb.IsSquashI return nil, status.Errorf(codes.InvalidArgument, "IsSquashInProgress: %v", err) } - repoPath, err := helper.GetRepoPath(req.GetRepository()) + repoPath, err := helper.GetValidatedRepoPath(req.GetRepository(), s.storages) if err != nil { return nil, err } diff --git a/internal/service/repository/squash_in_progress_test.go b/internal/service/repository/squash_in_progress_test.go index dda700870..1e5550075 100644 --- a/internal/service/repository/squash_in_progress_test.go +++ b/internal/service/repository/squash_in_progress_test.go @@ -5,13 +5,14 @@ import ( "testing" "github.com/stretchr/testify/require" + "gitlab.com/gitlab-org/gitaly/internal/config" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" "google.golang.org/grpc/codes" ) func TestSuccessfulIsSquashInProgressRequest(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -62,7 +63,7 @@ func TestSuccessfulIsSquashInProgressRequest(t *testing.T) { } func TestFailedIsSquashInProgressRequestDueToValidations(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) diff --git a/internal/service/repository/testhelper_test.go b/internal/service/repository/testhelper_test.go index ae61359dc..5a0295f7e 100644 --- a/internal/service/repository/testhelper_test.go +++ b/internal/service/repository/testhelper_test.go @@ -65,7 +65,7 @@ func newSecureRepoClient(t *testing.T, serverSocketPath string, pool *x509.CertP var NewSecureRepoClient = newSecureRepoClient -func runRepoServer(t *testing.T, opts ...testhelper.TestServerOpt) (string, func()) { +func runRepoServer(t *testing.T, storages config.Storages) (string, func()) { streamInt := []grpc.StreamServerInterceptor{ mcache.StreamInvalidator(dcache.LeaseKeyer{}, protoregistry.GitalyProtoPreregistered), } @@ -73,9 +73,9 @@ func runRepoServer(t *testing.T, opts ...testhelper.TestServerOpt) (string, func mcache.UnaryInvalidator(dcache.LeaseKeyer{}, protoregistry.GitalyProtoPreregistered), } - srv := testhelper.NewServerWithAuth(t, streamInt, unaryInt, config.Config.Auth.Token, opts...) + srv := testhelper.NewServerWithAuth(t, streamInt, unaryInt, config.Config.Auth.Token, testhelper.WithStorages(storages)) - gitalypb.RegisterRepositoryServiceServer(srv.GrpcServer(), NewServer(RubyServer, config.GitalyInternalSocketPath())) + gitalypb.RegisterRepositoryServiceServer(srv.GrpcServer(), NewServer(RubyServer, storages, config.GitalyInternalSocketPath())) reflection.Register(srv.GrpcServer()) require.NoError(t, srv.Start()) @@ -84,7 +84,7 @@ func runRepoServer(t *testing.T, opts ...testhelper.TestServerOpt) (string, func } func TestRepoNoAuth(t *testing.T) { - socket, stop := runRepoServer(t) + socket, stop := runRepoServer(t, config.Config.Storages) defer stop() connOpts := []grpc.DialOption{ diff --git a/internal/service/repository/write_ref_test.go b/internal/service/repository/write_ref_test.go index 9d3890a81..e85c21535 100644 --- a/internal/service/repository/write_ref_test.go +++ b/internal/service/repository/write_ref_test.go @@ -6,13 +6,14 @@ import ( "testing" "github.com/stretchr/testify/require" + "gitlab.com/gitlab-org/gitaly/internal/config" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" "google.golang.org/grpc/codes" ) func TestWriteRefSuccessful(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -78,7 +79,7 @@ func TestWriteRefSuccessful(t *testing.T) { } func TestWriteRefValidationError(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + serverSocketPath, stop := runRepoServer(t, config.Config.Storages) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) diff --git a/internal/tempdir/tempdir.go b/internal/tempdir/tempdir.go index ba2481e85..55f53bdac 100644 --- a/internal/tempdir/tempdir.go +++ b/internal/tempdir/tempdir.go @@ -62,9 +62,9 @@ func TempDir(storage config.Storage) string { return AppendTempDir(storage.Path) func AppendTempDir(storagePath string) string { return filepath.Join(storagePath, tmpRootPrefix) } // ForDeleteAllRepositories returns a temporary directory for the given storage. It is not context-scoped but it will get removed eventuall (after MaxAge). -func ForDeleteAllRepositories(storageName string) (string, error) { +func ForDeleteAllRepositories(storages config.Storages, storageName string) (string, error) { prefix := fmt.Sprintf("%s-repositories.old.%d.", storageName, time.Now().Unix()) - _, path, err := newAsRepository(context.Background(), storageName, prefix) + _, path, err := newAsRepository(context.Background(), storages, storageName, prefix) return path, err } @@ -73,7 +73,7 @@ func ForDeleteAllRepositories(storageName string) (string, error) { // repository. The directory is removed with os.RemoveAll when ctx // expires. func New(ctx context.Context, repo *gitalypb.Repository) (string, error) { - _, path, err := NewAsRepository(ctx, repo) + _, path, err := NewAsRepository(ctx, config.Config.Storages, repo) if err != nil { return "", err } @@ -83,12 +83,12 @@ func New(ctx context.Context, repo *gitalypb.Repository) (string, error) { // NewAsRepository is the same as New, but it returns a *gitalypb.Repository for the // created directory as well as the bare path as a string -func NewAsRepository(ctx context.Context, repo *gitalypb.Repository) (*gitalypb.Repository, string, error) { - return newAsRepository(ctx, repo.StorageName, "repo") +func NewAsRepository(ctx context.Context, storages config.Storages, repo *gitalypb.Repository) (*gitalypb.Repository, string, error) { + return newAsRepository(ctx, storages, repo.GetStorageName(), "repo") } -func newAsRepository(ctx context.Context, storageName string, prefix string) (*gitalypb.Repository, string, error) { - storage, ok := config.Config.Storage(storageName) +func newAsRepository(ctx context.Context, storages config.Storages, storageName string, prefix string) (*gitalypb.Repository, string, error) { + storage, ok := storages.Get(storageName) if !ok { return nil, "", fmt.Errorf("storage not found: %v", storageName) } diff --git a/internal/tempdir/tempdir_test.go b/internal/tempdir/tempdir_test.go index 8c62a3515..d78291fc6 100644 --- a/internal/tempdir/tempdir_test.go +++ b/internal/tempdir/tempdir_test.go @@ -8,6 +8,7 @@ import ( "time" "github.com/stretchr/testify/require" + "gitlab.com/gitlab-org/gitaly/internal/config" "gitlab.com/gitlab-org/gitaly/internal/helper" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" @@ -18,7 +19,7 @@ func TestNewAsRepositorySuccess(t *testing.T) { defer cancel() repo := testhelper.TestRepository() - tempRepo, tempDir, err := NewAsRepository(ctx, repo) + tempRepo, tempDir, err := NewAsRepository(ctx, config.Config.Storages, repo) require.NoError(t, err) require.NotEqual(t, repo, tempRepo) require.Equal(t, repo.StorageName, tempRepo.StorageName) diff --git a/internal/testhelper/testserver.go b/internal/testhelper/testserver.go index efdf1dbe5..054aa2b14 100644 --- a/internal/testhelper/testserver.go +++ b/internal/testhelper/testserver.go @@ -55,6 +55,7 @@ func WithToken(token string) TestServerOpt { } } +/* // WithStorages is a TestServerOpt that sets the storages for a TestServer func WithStorages(storages []string) TestServerOpt { return func(t *TestServer) { @@ -62,11 +63,19 @@ func WithStorages(storages []string) TestServerOpt { } } +*/ + +func WithStorages(storages config.Storages) TestServerOpt { + return func(t *TestServer) { + t.storages = storages + } +} + // NewTestServer instantiates a new TestServer func NewTestServer(srv *grpc.Server, opts ...TestServerOpt) *TestServer { ts := &TestServer{ grpcServer: srv, - storages: []string{"default"}, + storages: config.Config.Storages, } for _, opt := range opts { @@ -101,7 +110,7 @@ type TestServer struct { socket string process *os.Process token string - storages []string + storages config.Storages waitCh chan struct{} } @@ -165,10 +174,10 @@ func (p *TestServer) Start() error { for _, storage := range p.storages { c.VirtualStorages = append(c.VirtualStorages, &praefectconfig.VirtualStorage{ - Name: storage, + Name: storage.Name, Nodes: []*models.Node{ { - Storage: storage, + Storage: storage.Name, Address: "unix:/" + gitalyServerSocketPath, DefaultPrimary: true, Token: p.token, -- cgit v1.2.3