Skip to content

Commit 2c1b3a9

Browse files
committedFeb 24, 2025
Avoid marshaling/unmarshaling to yaml
Instead, use the `gob` package to encode/decode the bytes. This is to avoid errors that might arise from the marshaling/unmarshaling to YAML. Signed-off-by: Peter Engelbert <pmengelbert@gmail.com>
1 parent e3f4c31 commit 2c1b3a9

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed
 

‎cmd/frontend/git_credential_gomod.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bufio"
55
"bytes"
66
"encoding/base64"
7+
"encoding/gob"
78
"errors"
89
"fmt"
910
"io"
@@ -12,7 +13,6 @@ import (
1213
"strings"
1314

1415
"github.com/Azure/dalec"
15-
"github.com/goccy/go-yaml"
1616
)
1717

1818
const (
@@ -210,7 +210,10 @@ func getHostAuthFromConfigFile(configFile, hostname string) (*dalec.GomodGitAuth
210210
return nil, err
211211
}
212212

213-
if err := yaml.Unmarshal(b, &m); err != nil {
213+
buf := bytes.NewBuffer(b)
214+
dec := gob.NewDecoder(buf)
215+
216+
if err := dec.Decode(&m); err != nil {
214217
return nil, err
215218
}
216219

‎generator_gomod.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ package dalec
22

33
import (
44
"bytes"
5+
"encoding/gob"
56
"fmt"
67
"path/filepath"
78
"sort"
89

9-
"github.com/goccy/go-yaml"
1010
"github.com/moby/buildkit/client/llb"
1111
"github.com/pkg/errors"
1212
)
@@ -89,12 +89,13 @@ func (g *SourceGenerator) mountGitAuthConfig(mountPoint, basename string) llb.Ru
8989
return
9090
}
9191

92-
b, err := yaml.Marshal(&g.Gomod.Auth)
93-
if err != nil {
94-
panic("cannot marshal dalec spec yaml")
92+
var b bytes.Buffer
93+
enc := gob.NewEncoder(&b)
94+
if err := enc.Encode(g.Gomod.Auth); err != nil {
95+
panic("cannot marshal dalec spec bytes")
9596
}
9697

97-
st := llb.Scratch().File(llb.Mkfile("/"+basename, 0o644, b))
98+
st := llb.Scratch().File(llb.Mkfile("/"+basename, 0o644, b.Bytes()))
9899
llb.AddMount(mountPoint, st).SetRunOption(ei)
99100
})
100101
}

‎source_test.go

-3
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,6 @@ func TestSourceGitHTTP(t *testing.T) {
228228
}
229229

230230
func getGomodLLBOps(ctx context.Context, t *testing.T, spec Spec) (map[string]*pb.Op, []*pb.Op) {
231-
type currentFrontend interface {
232-
CurrentFrontend() (*llb.State, error)
233-
}
234231
sOpt := SourceOpts{
235232
GetContext: func(name string, opts ...llb.LocalOption) (*llb.State, error) {
236233
st := llb.Local(name, opts...)

0 commit comments

Comments
 (0)