diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2022-05-25 06:41:43 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2022-05-30 09:09:53 +0300 |
commit | ad32b7e79e841a372fe3254aab2159cfc77e3419 (patch) | |
tree | b0608bd5f0a619f1c460b16969fad628b3c8b1ee | |
parent | 0bc5c6dd945972ffa0b118ce00ca14a6123e09a4 (diff) |
repository: Convert GetArchive to use new smudge configuration
The `GetArchive()` RPC can optionally convert LFS pointers to their
actual contents via the gitaly-lfs-smudge filter. The configuration of
this filter happens via a set of environment variables, which we have
replaced with a single structure in this commit series.
Convert `GetArchive()` to use the new `smudge.Config` to inject the
environment.
-rw-r--r-- | internal/gitaly/service/repository/archive.go | 32 | ||||
-rw-r--r-- | internal/gitaly/service/repository/archive_test.go | 16 |
2 files changed, 21 insertions, 27 deletions
diff --git a/internal/gitaly/service/repository/archive.go b/internal/gitaly/service/repository/archive.go index 66899c7ff..f08ee71a7 100644 --- a/internal/gitaly/service/repository/archive.go +++ b/internal/gitaly/service/repository/archive.go @@ -4,7 +4,6 @@ import ( "context" "crypto/sha256" "encoding/hex" - "encoding/json" "fmt" "io" "os" @@ -16,6 +15,7 @@ import ( "gitlab.com/gitlab-org/gitaly/v15/internal/command" "gitlab.com/gitlab-org/gitaly/v15/internal/git" "gitlab.com/gitlab-org/gitaly/v15/internal/git/catfile" + "gitlab.com/gitlab-org/gitaly/v15/internal/git/smudge" "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/storage" "gitlab.com/gitlab-org/gitaly/v15/internal/helper" "gitlab.com/gitlab-org/gitaly/v15/internal/log" @@ -33,8 +33,6 @@ type archiveParams struct { format string archivePath string exclude []string - internalCfg []byte - tlsCfg []byte binDir string loggingDir string } @@ -86,16 +84,6 @@ func (s *server) GetArchive(in *gitalypb.GetArchiveRequest, stream gitalypb.Repo return stream.Send(&gitalypb.GetArchiveResponse{Data: p}) }) - gitlabConfig, err := json.Marshal(s.cfg.Gitlab) - if err != nil { - return err - } - - tlsCfg, err := json.Marshal(s.cfg.TLS) - if err != nil { - return err - } - ctxlogrus.Extract(ctx).WithField("request_hash", requestHash(in)).Info("request details") return s.handleArchive(archiveParams{ @@ -106,8 +94,6 @@ func (s *server) GetArchive(in *gitalypb.GetArchiveRequest, stream gitalypb.Repo format: format, archivePath: path, exclude: exclude, - internalCfg: gitlabConfig, - tlsCfg: tlsCfg, binDir: s.binDir, loggingDir: s.loggingCfg.Dir, }) @@ -210,11 +196,19 @@ func (s *server) handleArchive(p archiveParams) error { pathspecs = append(pathspecs, ":(exclude)"+exclude) } + smudgeCfg := smudge.Config{ + GlRepository: p.in.GetRepository().GetGlRepository(), + Gitlab: s.cfg.Gitlab, + TLS: s.cfg.TLS, + } + + smudgeEnv, err := smudgeCfg.Environment() + if err != nil { + return fmt.Errorf("setting up smudge environment: %w", err) + } + env := []string{ - fmt.Sprintf("GL_REPOSITORY=%s", p.in.GetRepository().GetGlRepository()), - fmt.Sprintf("GL_PROJECT_PATH=%s", p.in.GetRepository().GetGlProjectPath()), - fmt.Sprintf("GL_INTERNAL_CONFIG=%s", p.internalCfg), - fmt.Sprintf("GITALY_TLS=%s", p.tlsCfg), + smudgeEnv, fmt.Sprintf("CORRELATION_ID=%s", correlation.ExtractFromContext(p.ctx)), fmt.Sprintf("%s=%s", log.GitalyLogDirEnvKey, p.loggingDir), } diff --git a/internal/gitaly/service/repository/archive_test.go b/internal/gitaly/service/repository/archive_test.go index 75fb00837..995189aaf 100644 --- a/internal/gitaly/service/repository/archive_test.go +++ b/internal/gitaly/service/repository/archive_test.go @@ -3,7 +3,6 @@ package repository import ( "archive/zip" "bytes" - "encoding/json" "fmt" "io" "os" @@ -14,6 +13,7 @@ import ( "github.com/stretchr/testify/require" "gitlab.com/gitlab-org/gitaly/v15/internal/git" "gitlab.com/gitlab-org/gitaly/v15/internal/git/gittest" + "gitlab.com/gitlab-org/gitaly/v15/internal/git/smudge" "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/config" "gitlab.com/gitlab-org/gitaly/v15/internal/gitlab" "gitlab.com/gitlab-org/gitaly/v15/internal/testhelper" @@ -502,10 +502,13 @@ func TestGetArchiveEnv(t *testing.T) { CommitId: commitID, } - cfgData, err := json.Marshal(cfg.Gitlab) - require.NoError(t, err) + smudgeCfg := smudge.Config{ + GlRepository: gittest.GlRepository, + Gitlab: cfg.Gitlab, + TLS: cfg.TLS, + } - tlsCfgData, err := json.Marshal(cfg.TLS) + smudgeEnv, err := smudgeCfg.Environment() require.NoError(t, err) stream, err := client.GetArchive(ctx, req) @@ -513,12 +516,9 @@ func TestGetArchiveEnv(t *testing.T) { data, err := consumeArchive(stream) require.NoError(t, err) - require.Contains(t, string(data), "GL_REPOSITORY="+gittest.GlRepository) - require.Contains(t, string(data), "GL_PROJECT_PATH="+gittest.GlProjectPath) - require.Contains(t, string(data), "GL_INTERNAL_CONFIG="+string(cfgData)) - require.Contains(t, string(data), "GITALY_TLS="+string(tlsCfgData)) require.Contains(t, string(data), "CORRELATION_ID="+correlationID) require.Contains(t, string(data), "GITALY_LOG_DIR="+cfg.Logging.Dir) + require.Contains(t, string(data), smudgeEnv) } func compressedFileContents(t *testing.T, format gitalypb.GetArchiveRequest_Format, name string) []byte { |