1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
package repository
import (
"context"
"gitlab.com/gitlab-org/gitaly-proto/go/gitalypb"
"gitlab.com/gitlab-org/gitaly/internal/command"
"gitlab.com/gitlab-org/gitaly/internal/git"
"gitlab.com/gitlab-org/gitaly/internal/rubyserver"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
func (*server) DeleteConfig(ctx context.Context, req *gitalypb.DeleteConfigRequest) (*gitalypb.DeleteConfigResponse, error) {
for _, k := range req.Keys {
// We assume k does not contain any secrets; it is leaked via 'ps'.
cmd, err := git.Command(ctx, req.Repository, "config", "--unset-all", k)
if err != nil {
return nil, err
}
if err := cmd.Wait(); err != nil {
if code, ok := command.ExitStatus(err); ok && code == 5 {
// Status code 5 means 'key not in config', see 'git help config'
continue
}
return nil, status.Errorf(codes.Internal, "command failed: %v", err)
}
}
return &gitalypb.DeleteConfigResponse{}, nil
}
func (s *server) SetConfig(ctx context.Context, req *gitalypb.SetConfigRequest) (*gitalypb.SetConfigResponse, error) {
// We use gitaly-ruby here because in gitaly-ruby we can use Rugged, and
// Rugged lets us set config values without leaking secrets via 'ps'. We
// can't use `git config foo.bar secret` because that leaks secrets.
client, err := s.RepositoryServiceClient(ctx)
if err != nil {
return nil, err
}
clientCtx, err := rubyserver.SetHeaders(ctx, req.GetRepository())
if err != nil {
return nil, err
}
return client.SetConfig(clientCtx, req)
}
|