diff options
author | Paul Okstad <pokstad@gitlab.com> | 2020-01-24 23:02:04 +0300 |
---|---|---|
committer | John Cai <jcai@gitlab.com> | 2020-01-24 23:02:04 +0300 |
commit | f8f3ffe071afc402f91fd7a2fd61513ee5adf678 (patch) | |
tree | 7006c88e583c563055bc20cfe8d4d18c2c65817c | |
parent | 1747a15990b323e62e1b1a1314e83926010ab513 (diff) |
Unexport dangerous command functions
-rw-r--r-- | internal/git/command.go | 28 | ||||
-rw-r--r-- | internal/git/command_test.go | 2 | ||||
-rw-r--r-- | internal/git/proto.go | 2 | ||||
-rw-r--r-- | internal/git/ref.go | 2 | ||||
-rw-r--r-- | internal/git/safecmd.go | 8 |
5 files changed, 18 insertions, 24 deletions
diff --git a/internal/git/command.go b/internal/git/command.go index 219b10dd6..dc4fb37ea 100644 --- a/internal/git/command.go +++ b/internal/git/command.go @@ -10,29 +10,25 @@ import ( "gitlab.com/gitlab-org/gitaly/internal/git/repository" ) -// Command creates a git.Command with the given args and Repository -// -// Deprecated: use git.SafeCmd instead -func Command(ctx context.Context, repo repository.GitRepo, args ...string) (*command.Command, error) { +// unsafeCmd creates a git.unsafeCmd with the given args and Repository +func unsafeCmd(ctx context.Context, repo repository.GitRepo, args ...string) (*command.Command, error) { args, env, err := argsAndEnv(repo, args...) if err != nil { return nil, err } - return BareCommand(ctx, nil, nil, nil, env, args...) + return unsafeBareCmd(ctx, nil, nil, nil, env, args...) } -// StdinCommand creates a git.Command with the given args and Repository that is +// unsafeStdinCmd creates a git.Command with the given args and Repository that is // suitable for Write()ing to -// -// Deprecated: Use git.SafeStdinCmd instead -func StdinCommand(ctx context.Context, repo repository.GitRepo, args ...string) (*command.Command, error) { +func unsafeStdinCmd(ctx context.Context, repo repository.GitRepo, args ...string) (*command.Command, error) { args, env, err := argsAndEnv(repo, args...) if err != nil { return nil, err } - return BareCommand(ctx, command.SetupStdin, nil, nil, env, args...) + return unsafeBareCmd(ctx, command.SetupStdin, nil, nil, env, args...) } func argsAndEnv(repo repository.GitRepo, args ...string) ([]string, []string, error) { @@ -46,16 +42,14 @@ func argsAndEnv(repo repository.GitRepo, args ...string) ([]string, []string, er return args, env, nil } -// BareCommand creates a git.Command with the given args, stdin/stdout/stderr, and env -// -// Deprecated: use git.SafeBareCmd -func BareCommand(ctx context.Context, stdin io.Reader, stdout, stderr io.Writer, env []string, args ...string) (*command.Command, error) { +// unsafeBareCmd creates a git.Command with the given args, stdin/stdout/stderr, and env +func unsafeBareCmd(ctx context.Context, stdin io.Reader, stdout, stderr io.Writer, env []string, args ...string) (*command.Command, error) { env = append(env, command.GitEnv...) return command.New(ctx, exec.Command(command.GitPath(), args...), stdin, stdout, stderr, env...) } -// CommandWithoutRepo works like Command but without a git repository -func CommandWithoutRepo(ctx context.Context, args ...string) (*command.Command, error) { - return BareCommand(ctx, nil, nil, nil, nil, args...) +// unsafeCmdWithoutRepo works like Command but without a git repository +func unsafeCmdWithoutRepo(ctx context.Context, args ...string) (*command.Command, error) { + return unsafeBareCmd(ctx, nil, nil, nil, nil, args...) } diff --git a/internal/git/command_test.go b/internal/git/command_test.go index f915d3e73..cf7ce0c68 100644 --- a/internal/git/command_test.go +++ b/internal/git/command_test.go @@ -30,7 +30,7 @@ func TestGitCommandProxy(t *testing.T) { require.NoError(t, err) defer os.RemoveAll(dir) - cmd, err := CommandWithoutRepo(ctx, "clone", "http://gitlab.com/bogus-repo", dir) + cmd, err := unsafeCmdWithoutRepo(ctx, "clone", "http://gitlab.com/bogus-repo", dir) require.NoError(t, err) err = cmd.Wait() diff --git a/internal/git/proto.go b/internal/git/proto.go index d8d6a5f96..5bc5a587d 100644 --- a/internal/git/proto.go +++ b/internal/git/proto.go @@ -54,7 +54,7 @@ func Version() (string, error) { defer cancel() var buf bytes.Buffer - cmd, err := BareCommand(ctx, nil, &buf, nil, nil, "version") + cmd, err := unsafeBareCmd(ctx, nil, &buf, nil, nil, "version") if err != nil { return "", err } diff --git a/internal/git/ref.go b/internal/git/ref.go index e8f80c68a..b802229e8 100644 --- a/internal/git/ref.go +++ b/internal/git/ref.go @@ -12,7 +12,7 @@ func IsValidRef(ctx context.Context, repo *gitalypb.Repository, ref string) bool return false } - cmd, err := Command(ctx, repo, "log", "--max-count=1", ref) + cmd, err := unsafeCmd(ctx, repo, "log", "--max-count=1", ref) if err != nil { return false } diff --git a/internal/git/safecmd.go b/internal/git/safecmd.go index bb98cf7c9..eaee4f5be 100644 --- a/internal/git/safecmd.go +++ b/internal/git/safecmd.go @@ -200,7 +200,7 @@ func SafeCmd(ctx context.Context, repo repository.GitRepo, globals []Option, sc return nil, err } - return Command(ctx, repo, args...) + return unsafeCmd(ctx, repo, args...) } // SafeBareCmd creates a git.Command with the given args, stdin/stdout/stderr, @@ -211,7 +211,7 @@ func SafeBareCmd(ctx context.Context, stdin io.Reader, stdout, stderr io.Writer, return nil, err } - return BareCommand(ctx, stdin, stdout, stderr, env, args...) + return unsafeBareCmd(ctx, stdin, stdout, stderr, env, args...) } // SafeStdinCmd creates a git.Command with the given args and Repository that is @@ -223,7 +223,7 @@ func SafeStdinCmd(ctx context.Context, repo repository.GitRepo, globals []Option return nil, err } - return StdinCommand(ctx, repo, args...) + return unsafeStdinCmd(ctx, repo, args...) } // SafeCmdWithoutRepo works like Command but without a git repository. It @@ -234,7 +234,7 @@ func SafeCmdWithoutRepo(ctx context.Context, globals []Option, sc SubCmd) (*comm return nil, err } - return CommandWithoutRepo(ctx, args...) + return unsafeCmdWithoutRepo(ctx, args...) } func combineArgs(globals []Option, sc Cmd) (_ []string, err error) { |