diff --git a/go.mod b/go.mod index 5417631b38..53495f7a00 100644 --- a/go.mod +++ b/go.mod @@ -62,7 +62,6 @@ require ( github.com/golangci/golangci-lint v1.60.3 github.com/google/go-github/v48 v48.2.0 github.com/google/go-querystring v1.1.0 - github.com/gorilla/mux v1.8.1 github.com/hashicorp/go-hclog v1.6.3 github.com/hashicorp/go-plugin v1.6.2 github.com/iancoleman/strcase v0.3.0 @@ -71,7 +70,6 @@ require ( github.com/lib/pq v1.10.9 github.com/manifoldco/promptui v0.9.0 github.com/mitchellh/mapstructure v1.5.0 - github.com/moby/moby v26.1.0+incompatible github.com/muesli/reflow v0.3.0 github.com/nqd/flat v0.2.0 github.com/otiai10/copy v1.14.0 @@ -186,8 +184,6 @@ require ( github.com/cockroachdb/redact v1.1.5 // indirect github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect github.com/cometbft/cometbft-db v1.0.1 // indirect - github.com/containerd/containerd v1.7.11 // indirect - github.com/containerd/log v0.1.0 // indirect github.com/containerd/stargz-snapshotter/estargz v0.15.1 // indirect github.com/cosiner/argv v0.1.0 // indirect github.com/cosmos/btcutil v1.0.5 // indirect @@ -289,6 +285,7 @@ require ( github.com/gordonklaus/ineffassign v0.1.0 // indirect github.com/gorilla/css v1.0.0 // indirect github.com/gorilla/handlers v1.5.2 // indirect + github.com/gorilla/mux v1.8.1 // indirect github.com/gorilla/websocket v1.5.3 // indirect github.com/gostaticanalysis/analysisutil v0.7.1 // indirect github.com/gostaticanalysis/comment v1.4.2 // indirect @@ -296,6 +293,7 @@ require ( github.com/gostaticanalysis/nilerr v0.1.1 // indirect github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 // indirect github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect + github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 // indirect github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect github.com/hashicorp/go-immutable-radix v1.3.1 // indirect github.com/hashicorp/go-metrics v0.5.3 // indirect @@ -356,9 +354,6 @@ require ( github.com/mikesmitty/edkey v0.0.0-20170222072505-3356ea4e686a // indirect github.com/mitchellh/go-homedir v1.1.0 // indirect github.com/moby/docker-image-spec v1.3.1 // indirect - github.com/moby/patternmatcher v0.6.0 // indirect - github.com/moby/sys/sequential v0.5.0 // indirect - github.com/moby/sys/user v0.1.0 // indirect github.com/moby/term v0.5.0 // indirect github.com/moricho/tparallel v0.3.2 // indirect github.com/morikuni/aec v1.0.0 // indirect @@ -467,6 +462,7 @@ require ( go.opencensus.io v0.24.0 // indirect go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.51.0 // indirect go.opentelemetry.io/otel v1.26.0 // indirect + go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.19.0 // indirect go.opentelemetry.io/otel/metric v1.26.0 // indirect go.opentelemetry.io/otel/sdk v1.24.0 // indirect go.opentelemetry.io/otel/trace v1.26.0 // indirect diff --git a/go.sum b/go.sum index 4239c0ca1d..c7b15f36be 100644 --- a/go.sum +++ b/go.sum @@ -66,8 +66,6 @@ github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 h1:/vQbFIOMb github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4/go.mod h1:hN7oaIRCjzsZ2dE+yG5k+rsdt3qcwykqK6HVGcKwsw4= github.com/Abirdcfly/dupword v0.0.14 h1:3U4ulkc8EUo+CaT105/GJ1BQwtgyj6+VaBVbAX11Ba8= github.com/Abirdcfly/dupword v0.0.14/go.mod h1:VKDAbxdY8YbKUByLGg8EETzYSuC4crm9WwI6Y3S0cLI= -github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24 h1:bvDV9vkmnHYOMsOr4WLk+Vo07yKIzd94sVoIqshQ4bU= -github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24/go.mod h1:8o94RPi1/7XTJvwPpRSzSUedZrtlirdB3r9Z20bi2f8= github.com/AlecAivazis/survey/v2 v2.3.7 h1:6I/u8FvytdGsgonrYsVn2t8t4QiRnh6QSTqkkhIiSjQ= github.com/AlecAivazis/survey/v2 v2.3.7/go.mod h1:xUTIdE4KCOIjsBAE1JYsUPoCqYdZ1reCfTwbto0Fduo= github.com/Antonboom/errname v0.1.13 h1:JHICqsewj/fNckzrfVSe+T33svwQxmjC+1ntDsHOVvM= @@ -100,8 +98,6 @@ github.com/Masterminds/semver/v3 v3.3.1/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lpr github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v8QkMxJ6pZY= github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow= github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM= -github.com/Microsoft/hcsshim v0.11.4 h1:68vKo2VN8DE9AdN4tnkWnmdhqdbpUFM8OF3Airm7fz8= -github.com/Microsoft/hcsshim v0.11.4/go.mod h1:smjE4dvqPX9Zldna+t5FG3rnoHhaB7QYxPRqGcpAD9w= github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2 h1:+vx7roKuyA63nhn5WAunQHLTznkw5W8b1Xc0dNjp83s= github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2/go.mod h1:HBCaDeC1lPdgDeDbhX8XFpy1jqjK0IBG8W5K+xYqA0w= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= @@ -301,8 +297,6 @@ github.com/cometbft/cometbft-db v1.0.1/go.mod h1:EBrFs1GDRiTqrWXYi4v90Awf/gcdD5E github.com/cometbft/cometbft/api v1.0.0-rc2 h1:ThzvNaJq37htjzfSsohhDoEebW94p0lEjA39CMDJ4xs= github.com/cometbft/cometbft/api v1.0.0-rc2/go.mod h1:EkQiqVSu/p2ebrZEnB2z6Re7r8XNe//M7ylR0qEwWm0= github.com/containerd/console v1.0.1/go.mod h1:XUsP6YE/mKtz6bxc+I8UiKKTP04qjQL4qcS3XoQ5xkw= -github.com/containerd/containerd v1.7.11 h1:lfGKw3eU35sjV0aG2eYZTiwFEY1pCzxdzicHP3SZILw= -github.com/containerd/containerd v1.7.11/go.mod h1:5UluHxHTX2rdvYuZ5OJTC5m/KJNs0Zs9wVoJm9zf5ZE= github.com/containerd/log v0.1.0 h1:TCJt7ioM2cr/tfR8GPbGf9/VRAX8D2B4PjzCpfX540I= github.com/containerd/log v0.1.0/go.mod h1:VRRf09a7mHDIRezVKTRCrOq78v577GXq3bSa3EhrzVo= github.com/containerd/stargz-snapshotter/estargz v0.15.1 h1:eXJjw9RbkLFgioVaTG+G/ZW/0kEe2oEKCdS/ZxIyoCU= @@ -959,14 +953,6 @@ github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyua github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/moby/docker-image-spec v1.3.1 h1:jMKff3w6PgbfSa69GfNg+zN/XLhfXJGnEx3Nl2EsFP0= github.com/moby/docker-image-spec v1.3.1/go.mod h1:eKmb5VW8vQEh/BAr2yvVNvuiJuY6UIocYsFu/DxxRpo= -github.com/moby/moby v26.1.0+incompatible h1:mjepCwMH0KpCgPvrXjqqyCeTCHgzO7p9TwZ2nQMI2qU= -github.com/moby/moby v26.1.0+incompatible/go.mod h1:fDXVQ6+S340veQPv35CzDahGBmHsiclFwfEygB/TWMc= -github.com/moby/patternmatcher v0.6.0 h1:GmP9lR19aU5GqSSFko+5pRqHi+Ohk1O69aFiKkVGiPk= -github.com/moby/patternmatcher v0.6.0/go.mod h1:hDPoyOpDY7OrrMDLaYoY3hf52gNCR/YOUYxkhApJIxc= -github.com/moby/sys/sequential v0.5.0 h1:OPvI35Lzn9K04PBbCLW0g4LcFAJgHsvXsRyewg5lXtc= -github.com/moby/sys/sequential v0.5.0/go.mod h1:tH2cOOs5V9MlPiXcQzRC+eEyab644PWKGRYaaV5ZZlo= -github.com/moby/sys/user v0.1.0 h1:WmZ93f5Ux6het5iituh9x2zAG7NFY9Aqi49jjE1PaQg= -github.com/moby/sys/user v0.1.0/go.mod h1:fKJhFOnsCN6xZ5gSfbM6zaHGgDJMrqt9/reuj4T7MmU= github.com/moby/term v0.5.0 h1:xt8Q1nalod/v7BqbG21f8mQPqH+xAaC9C3N3wfWbVP0= github.com/moby/term v0.5.0/go.mod h1:8FzsFHVUBGZdbDsJw/ot+X+d5HLUbvklYLJ9uGfcI3Y= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= diff --git a/ignite/pkg/archive/tar_gz.go b/ignite/pkg/archive/tar_gz.go new file mode 100644 index 0000000000..c4500d86f5 --- /dev/null +++ b/ignite/pkg/archive/tar_gz.go @@ -0,0 +1,109 @@ +package archive + +import ( + "archive/tar" + "compress/gzip" + "io" + "os" + "path/filepath" + + "github.com/ignite/cli/v29/ignite/pkg/errors" +) + +// CreateArchive creates a tar.gz archive from a list of files. +func CreateArchive(dir string, buf io.Writer) error { + // Create new Writers for gzip and tar + // These writers are chained. Writing to the tar writer will + // write to the gzip writer which in turn will write to + // the "buf" writer + gw := gzip.NewWriter(buf) + defer gw.Close() + tw := tar.NewWriter(gw) + defer tw.Close() + + return filepath.WalkDir(dir, func(path string, _ os.DirEntry, _ error) error { + return addToArchive(tw, path) + }) +} + +func addToArchive(tw *tar.Writer, filename string) error { + // Open the file which will be written into the archive + file, err := os.Open(filename) + if err != nil { + return err + } + defer file.Close() + + // Get FileInfo about our file providing file size, mode, etc. + info, err := file.Stat() + if err != nil { + return err + } + + // Create a tar Header from the FileInfo data + header, err := tar.FileInfoHeader(info, info.Name()) + if err != nil { + return err + } + + // Use full path as name (FileInfoHeader only takes the basename) + // If we don't do this the directory strucuture would + // not be preserved + // https://golang.org/src/archive/tar/common.go?#L626 + header.Name = filename + + // Write file header to the tar archive + err = tw.WriteHeader(header) + if err != nil { + return err + } + + _, err = io.Copy(tw, file) + if err != nil { + return err + } + + return nil +} + +// ExtractArchive extracts a tar.gz archive to the specified directory. +func ExtractArchive(outDir string, gzipStream io.Reader) error { + uncompressedStream, err := gzip.NewReader(gzipStream) + if err != nil { + return err + } + + tarReader := tar.NewReader(uncompressedStream) + + for { + header, err := tarReader.Next() + if err == io.EOF { + break + } else if err != nil { + return err + } + + targetPath := filepath.Join(outDir, header.Name) //nolint:gosec // We trust the tar file + + switch header.Typeflag { + case tar.TypeDir: + if err := os.MkdirAll(targetPath, 0o755); err != nil { + return err + } + case tar.TypeReg: + outFile, err := os.Create(targetPath) + if err != nil { + return err + } + if _, err := io.Copy(outFile, tarReader); err != nil { //nolint:gosec // We trust the tar file + return err + } + outFile.Close() + + default: + return errors.Errorf("unknown type: %s in %s", string(header.Typeflag), header.Name) + } + } + + return nil +} diff --git a/ignite/pkg/cosmosfaucet/http.go b/ignite/pkg/cosmosfaucet/http.go index 8db36f3566..a14a313b34 100644 --- a/ignite/pkg/cosmosfaucet/http.go +++ b/ignite/pkg/cosmosfaucet/http.go @@ -3,7 +3,6 @@ package cosmosfaucet import ( "net/http" - "github.com/gorilla/mux" "github.com/rs/cors" "github.com/ignite/cli/v29/ignite/pkg/openapiconsole" @@ -12,23 +11,34 @@ import ( // ServeHTTP implements http.Handler to expose the functionality of Faucet.Transfer() via HTTP. // request/response payloads are compatible with the previous implementation at allinbits/cosmos-faucet. func (f Faucet) ServeHTTP(w http.ResponseWriter, r *http.Request) { - router := mux.NewRouter() - - router. - Handle("/", cors.Default().Handler(http.HandlerFunc(f.faucetHandler))). - Methods(http.MethodPost, http.MethodOptions) - - router. - Handle("/info", cors.Default().Handler(http.HandlerFunc(f.faucetInfoHandler))). - Methods(http.MethodGet, http.MethodOptions) - - router. - HandleFunc("/", openapiconsole.Handler("Faucet", "openapi.yml")). - Methods(http.MethodGet) - - router. - HandleFunc("/openapi.yml", f.openAPISpecHandler). - Methods(http.MethodGet) - - router.ServeHTTP(w, r) + mux := http.NewServeMux() + + mux.Handle("/", cors.Default().Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + switch { + case r.Method == http.MethodPost || r.Method == http.MethodOptions: + f.faucetHandler(w, r) + case r.Method == http.MethodGet: + openapiconsole.Handler("Faucet", "openapi.yml")(w, r) + default: + http.NotFound(w, r) + } + }))) + + mux.Handle("/info", cors.Default().Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method == http.MethodGet || r.Method == http.MethodOptions { + f.faucetInfoHandler(w, r) + } else { + http.NotFound(w, r) + } + }))) + + mux.HandleFunc("/openapi.yml", func(w http.ResponseWriter, r *http.Request) { + if r.Method == http.MethodGet { + f.openAPISpecHandler(w, r) + } else { + http.NotFound(w, r) + } + }) + + mux.ServeHTTP(w, r) } diff --git a/ignite/services/chain/build.go b/ignite/services/chain/build.go index 97848d9e19..3cc286e69d 100644 --- a/ignite/services/chain/build.go +++ b/ignite/services/chain/build.go @@ -3,14 +3,12 @@ package chain import ( "context" "fmt" - "io" "os" "path/filepath" "runtime" "strings" - "github.com/moby/moby/pkg/archive" - + "github.com/ignite/cli/v29/ignite/pkg/archive" "github.com/ignite/cli/v29/ignite/pkg/cache" "github.com/ignite/cli/v29/ignite/pkg/checksum" "github.com/ignite/cli/v29/ignite/pkg/cmdrunner" @@ -181,11 +179,6 @@ func (c *Chain) BuildRelease( return "", err } - tarr, err := archive.Tar(out, archive.Gzip) - if err != nil { - return "", err - } - tarName := fmt.Sprintf("%s_%s_%s.tar.gz", prefix, goos, goarch) tarPath := filepath.Join(releasePath, tarName) @@ -195,10 +188,9 @@ func (c *Chain) BuildRelease( } defer tarf.Close() - if _, err := io.Copy(tarf, tarr); err != nil { + if err := archive.CreateArchive(out, tarf); err != nil { return "", err } - tarf.Close() } checksumPath := filepath.Join(releasePath, releaseChecksumKey) diff --git a/ignite/services/chain/chain_test.go b/ignite/services/chain/chain_test.go index a62c627e48..4583522ff9 100644 --- a/ignite/services/chain/chain_test.go +++ b/ignite/services/chain/chain_test.go @@ -5,9 +5,10 @@ import ( "path/filepath" "testing" - "github.com/moby/moby/pkg/archive" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + + "github.com/ignite/cli/v29/ignite/pkg/archive" ) func TestSourceVersion(t *testing.T) { @@ -38,7 +39,7 @@ func tempSource(t *testing.T, tarPath string) (path string) { dir := t.TempDir() - require.NoError(t, archive.Untar(f, dir, &archive.TarOptions{NoLchown: true})) + require.NoError(t, archive.ExtractArchive(dir, f)) dirs, err := os.ReadDir(dir) require.NoError(t, err)