Skip to content

Commit

Permalink
use csvvalue package for parsing csv inputs
Browse files Browse the repository at this point in the history
This package is better suited for parsing single-line
CSV strings.

Signed-off-by: Tonis Tiigi <[email protected]>
  • Loading branch information
tonistiigi committed Jun 28, 2024
1 parent af902ca commit a1f522e
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 25 deletions.
5 changes: 2 additions & 3 deletions bake/bake.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package bake

import (
"context"
"encoding/csv"
"io"
"os"
"path"
Expand All @@ -27,6 +26,7 @@ import (
"github.com/moby/buildkit/client/llb"
"github.com/moby/buildkit/session/auth/authprovider"
"github.com/pkg/errors"
"github.com/tonistiigi/go-csvvalue"
"github.com/zclconf/go-cty/cty"
"github.com/zclconf/go-cty/cty/convert"
)
Expand Down Expand Up @@ -1393,8 +1393,7 @@ func removeAttestDupes(s []string) []string {
}

func parseOutput(str string) map[string]string {
csvReader := csv.NewReader(strings.NewReader(str))
fields, err := csvReader.Read()
fields, err := csvvalue.Fields(str, nil)
if err != nil {
return nil
}
Expand Down
5 changes: 2 additions & 3 deletions builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package builder

import (
"context"
"encoding/csv"
"encoding/json"
"net/url"
"os"
Expand All @@ -27,6 +26,7 @@ import (
"github.com/moby/buildkit/util/progress/progressui"
"github.com/pkg/errors"
"github.com/spf13/pflag"
"github.com/tonistiigi/go-csvvalue"
"golang.org/x/sync/errgroup"
)

Expand Down Expand Up @@ -601,8 +601,7 @@ func csvToMap(in []string) (map[string]string, error) {
}
m := make(map[string]string, len(in))
for _, s := range in {
csvReader := csv.NewReader(strings.NewReader(s))
fields, err := csvReader.Read()
fields, err := csvvalue.Fields(s, nil)
if err != nil {
return nil, err
}
Expand Down
8 changes: 4 additions & 4 deletions commands/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"context"
"crypto/sha256"
"encoding/base64"
"encoding/csv"
"encoding/hex"
"encoding/json"
"fmt"
Expand Down Expand Up @@ -59,6 +58,7 @@ import (
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/tonistiigi/go-csvvalue"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric"
"google.golang.org/grpc/codes"
Expand Down Expand Up @@ -982,9 +982,9 @@ func (cfg *invokeConfig) parseInvokeConfig(invoke, on string) error {
return nil
}

csvReader := csv.NewReader(strings.NewReader(invoke))
csvReader.LazyQuotes = true
fields, err := csvReader.Read()
csvParser := csvvalue.NewParser()
csvParser.LazyQuotes = true
fields, err := csvParser.Fields(invoke, nil)
if err != nil {
return err
}
Expand Down
5 changes: 2 additions & 3 deletions util/buildflags/attests.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package buildflags

import (
"encoding/csv"
"fmt"
"strconv"
"strings"

controllerapi "github.com/docker/buildx/controller/pb"
"github.com/pkg/errors"
"github.com/tonistiigi/go-csvvalue"
)

func CanonicalizeAttest(attestType string, in string) string {
Expand Down Expand Up @@ -45,8 +45,7 @@ func ParseAttest(in string) (*controllerapi.Attest, error) {
return nil, nil
}

csvReader := csv.NewReader(strings.NewReader(in))
fields, err := csvReader.Read()
fields, err := csvvalue.Fields(in, nil)
if err != nil {
return nil, err
}
Expand Down
5 changes: 2 additions & 3 deletions util/buildflags/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,19 @@ package buildflags

import (
"context"
"encoding/csv"
"os"
"strings"

awsconfig "github.com/aws/aws-sdk-go-v2/config"
controllerapi "github.com/docker/buildx/controller/pb"
"github.com/pkg/errors"
"github.com/tonistiigi/go-csvvalue"
)

func ParseCacheEntry(in []string) ([]*controllerapi.CacheOptionsEntry, error) {
outs := make([]*controllerapi.CacheOptionsEntry, 0, len(in))
for _, in := range in {
csvReader := csv.NewReader(strings.NewReader(in))
fields, err := csvReader.Read()
fields, err := csvvalue.Fields(in, nil)
if err != nil {
return nil, err
}
Expand Down
5 changes: 2 additions & 3 deletions util/buildflags/export.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package buildflags

import (
"encoding/csv"
"regexp"
"strings"

Expand All @@ -11,6 +10,7 @@ import (
"github.com/moby/buildkit/exporter/containerimage/exptypes"
ocispecs "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors"
"github.com/tonistiigi/go-csvvalue"
)

func ParseExports(inp []string) ([]*controllerapi.ExportEntry, error) {
Expand All @@ -19,8 +19,7 @@ func ParseExports(inp []string) ([]*controllerapi.ExportEntry, error) {
return nil, nil
}
for _, s := range inp {
csvReader := csv.NewReader(strings.NewReader(s))
fields, err := csvReader.Read()
fields, err := csvvalue.Fields(s, nil)
if err != nil {
return nil, err
}
Expand Down
5 changes: 2 additions & 3 deletions util/buildflags/printfunc.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package buildflags

import (
"encoding/csv"
"strconv"
"strings"

controllerapi "github.com/docker/buildx/controller/pb"
"github.com/pkg/errors"
"github.com/tonistiigi/go-csvvalue"
)

const defaultPrintFunc = "build"
Expand All @@ -16,8 +16,7 @@ func ParsePrintFunc(str string) (*controllerapi.PrintFunc, error) {
return nil, nil
}

csvReader := csv.NewReader(strings.NewReader(str))
fields, err := csvReader.Read()
fields, err := csvvalue.Fields(str, nil)
if err != nil {
return nil, err
}
Expand Down
5 changes: 2 additions & 3 deletions util/buildflags/secrets.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package buildflags

import (
"encoding/csv"
"strings"

controllerapi "github.com/docker/buildx/controller/pb"
"github.com/pkg/errors"
"github.com/tonistiigi/go-csvvalue"
)

func ParseSecretSpecs(sl []string) ([]*controllerapi.Secret, error) {
Expand All @@ -21,8 +21,7 @@ func ParseSecretSpecs(sl []string) ([]*controllerapi.Secret, error) {
}

func parseSecret(value string) (*controllerapi.Secret, error) {
csvReader := csv.NewReader(strings.NewReader(value))
fields, err := csvReader.Read()
fields, err := csvvalue.Fields(value, nil)
if err != nil {
return nil, errors.Wrap(err, "failed to parse csv secret")
}
Expand Down

0 comments on commit a1f522e

Please sign in to comment.