From f0f66a5d5beb483c230b3b516f742b9e5f9a2363 Mon Sep 17 00:00:00 2001 From: Ammar Bandukwala Date: Tue, 21 Feb 2023 00:37:01 +0000 Subject: [PATCH 1/8] cli: extract tar in template pull --- cli/templatepull.go | 46 +++++++++++++-------------------------- cli/templatepull_test.go | 34 +++++++++++++++++------------ go.mod | 6 +++++ go.sum | 6 +++++ provisioner/echo/serve.go | 1 + 5 files changed, 48 insertions(+), 45 deletions(-) diff --git a/cli/templatepull.go b/cli/templatepull.go index 72a69de39e49b..4ed994f7bd0a8 100644 --- a/cli/templatepull.go +++ b/cli/templatepull.go @@ -1,11 +1,13 @@ package cli import ( + "bytes" "fmt" "io/fs" "os" "sort" + "github.com/codeclysm/extract" "github.com/spf13/cobra" "golang.org/x/xerrors" @@ -14,6 +16,7 @@ import ( ) func templatePull() *cobra.Command { + var tarMode bool cmd := &cobra.Command{ Use: "pull [destination]", Short: "Download the latest version of a template to a path.", @@ -75,48 +78,29 @@ func templatePull() *cobra.Command { return xerrors.Errorf("unexpected Content-Type %q, expecting %q", ctype, codersdk.ContentTypeTar) } - // If the destination is empty then we write to stdout - // and bail early. - if dest == "" { + if tarMode { _, err = cmd.OutOrStdout().Write(raw) - if err != nil { - return xerrors.Errorf("write stdout: %w", err) - } - return nil - } - - // Stat the destination to ensure nothing exists already. - fi, err := os.Stat(dest) - if err != nil && !xerrors.Is(err, fs.ErrNotExist) { - return xerrors.Errorf("stat destination: %w", err) + return err } - if fi != nil && fi.IsDir() { - // If the destination is a directory we just bail. - return xerrors.Errorf("%q already exists.", dest) + if dest == "" { + dest = templateName + "/" } - // If a file exists at the destination prompt the user - // to ensure we don't overwrite something valuable. - if fi != nil { - _, err = cliui.Prompt(cmd, cliui.PromptOptions{ - Text: fmt.Sprintf("%q already exists, do you want to overwrite it?", dest), - IsConfirm: true, - }) - if err != nil { - return xerrors.Errorf("parse prompt: %w", err) - } - } + _, _ = fmt.Fprintf(cmd.OutOrStderr(), "Extracting template to %q\n", dest) - err = os.WriteFile(dest, raw, 0o600) - if err != nil { - return xerrors.Errorf("write to path: %w", err) + // Stat the destination to ensure nothing exists already. + _, err = os.Stat(dest) + if err != nil && !xerrors.Is(err, fs.ErrNotExist) { + return xerrors.Errorf("stat destination: %w", err) } - return nil + err = extract.Tar(ctx, bytes.NewReader(raw), dest, nil) + return err }, } + cmd.Flags().BoolVar(&tarMode, "tar", false, "output the template as a tar archive to stdout") cliui.AllowSkipPrompt(cmd) return cmd diff --git a/cli/templatepull_test.go b/cli/templatepull_test.go index f19725c21fe8a..d88e9df96c662 100644 --- a/cli/templatepull_test.go +++ b/cli/templatepull_test.go @@ -2,11 +2,14 @@ package cli_test import ( "bytes" - "os" + "context" + "io" "path/filepath" "testing" + "github.com/codeclysm/extract" "github.com/google/uuid" + "github.com/ory/dockertest/v3/docker/pkg/archive" "github.com/stretchr/testify/require" "github.com/coder/coder/cli/clitest" @@ -53,7 +56,7 @@ func TestTemplatePull(t *testing.T) { // are being sorted correctly. _ = coderdtest.UpdateTemplateVersion(t, client, user.OrganizationID, source2, template.ID) - cmd, root := clitest.New(t, "templates", "pull", template.Name) + cmd, root := clitest.New(t, "templates", "pull", "--tar", template.Name) clitest.SetupConfig(t, client, root) var buf bytes.Buffer @@ -93,15 +96,14 @@ func TestTemplatePull(t *testing.T) { dir := t.TempDir() - dest := filepath.Join(dir, "actual.tar") + expectedDest := filepath.Join(dir, "expected") + actualDest := filepath.Join(dir, "actual") + ctx := context.Background() - // Create the file so that we can test that the command - // warns the user before overwriting a preexisting file. - fi, err := os.OpenFile(dest, os.O_CREATE|os.O_RDONLY, 0o600) + err = extract.Tar(ctx, bytes.NewReader(expected), expectedDest, nil) require.NoError(t, err) - _ = fi.Close() - cmd, root := clitest.New(t, "templates", "pull", template.Name, dest) + cmd, root := clitest.New(t, "templates", "pull", template.Name, actualDest) clitest.SetupConfig(t, client, root) pty := ptytest.New(t) @@ -114,16 +116,20 @@ func TestTemplatePull(t *testing.T) { errChan <- cmd.Execute() }() - // We expect to be prompted that a file already exists. - pty.ExpectMatch("already exists") - pty.WriteLine("yes") - require.NoError(t, <-errChan) - actual, err := os.ReadFile(dest) + expectedTarRd, err := archive.Tar(expectedDest, archive.Uncompressed) + require.NoError(t, err) + expectedTar, err := io.ReadAll(expectedTarRd) + require.NoError(t, err) + + actualTarRd, err := archive.Tar(actualDest, archive.Uncompressed) + require.NoError(t, err) + + actualTar, err := io.ReadAll(actualTarRd) require.NoError(t, err) - require.True(t, bytes.Equal(actual, expected), "tar files differ") + require.True(t, bytes.Equal(expectedTar, actualTar), "tar files differ") }) } diff --git a/go.mod b/go.mod index 29e0b5bf12a5a..91b15ddb9d1bf 100644 --- a/go.mod +++ b/go.mod @@ -173,6 +173,12 @@ require ( tailscale.com v1.32.2 ) +require ( + github.com/codeclysm/extract v2.2.0+incompatible // indirect + github.com/h2non/filetype v1.1.3 // indirect + github.com/juju/errors v1.0.0 // indirect +) + require ( cloud.google.com/go/compute v1.12.1 // indirect cloud.google.com/go/longrunning v0.3.0 // indirect diff --git a/go.sum b/go.sum index d8393e41792d1..ab162526e6a99 100644 --- a/go.sum +++ b/go.sum @@ -362,6 +362,8 @@ github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:z github.com/cockroachdb/datadriven v0.0.0-20200714090401-bf6692d28da5/go.mod h1:h6jFvWxBdQXxjopDMZyH2UVceIRfR84bdzbkoKrsWNo= github.com/cockroachdb/errors v1.2.4/go.mod h1:rQD95gz6FARkaKkQXUksEje/d9a6wBJoCr5oaCLELYA= github.com/cockroachdb/logtags v0.0.0-20190617123548-eb05cc24525f/go.mod h1:i/u985jwjWRlyHXQbwatDASoW0RMlZ/3i9yJHE2xLkI= +github.com/codeclysm/extract v2.2.0+incompatible h1:q3wyckoA30bhUSiwdQezMqVhwd8+WGE64/GL//LtUhI= +github.com/codeclysm/extract v2.2.0+incompatible/go.mod h1:2nhFMPHiU9At61hz+12bfrlpXSUrOnK+wR+KlGO4Uks= github.com/coder/glog v1.0.1-0.20220322161911-7365fe7f2cd1 h1:UqBrPWSYvRI2s5RtOul20JukUEpu4ip9u7biBL+ntgk= github.com/coder/glog v1.0.1-0.20220322161911-7365fe7f2cd1/go.mod h1:EWib/APOK0SL3dFbYqvxE3UYd8E6s1ouQ7iEp/0LWV4= github.com/coder/retry v1.3.1-0.20230210155434-e90a2e1e091d h1:09JG37IgTB6n3ouX9BXdUiibGzkGGbslFuDZO9Ru9aw= @@ -984,6 +986,8 @@ github.com/grpc-ecosystem/grpc-gateway v1.12.1/go.mod h1:8XEsbTttt/W+VvjtQhLACqC github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= github.com/grpc-ecosystem/grpc-gateway/v2 v2.7.0 h1:BZHcxBETFHIdVyhyEfOvn/RdU/QGdLI4y34qQGjGWO0= github.com/grpc-ecosystem/grpc-gateway/v2 v2.7.0/go.mod h1:hgWBS7lorOAVIJEQMi4ZsPv9hVvWI6+ch50m39Pf2Ks= +github.com/h2non/filetype v1.1.3 h1:FKkx9QbD7HR/zjK1Ia5XiBsq9zdLi5Kf3zGyFTAFkGg= +github.com/h2non/filetype v1.1.3/go.mod h1:319b3zT68BvV+WRj7cwy856M2ehB3HqNOt6sy1HndBY= github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed/go.mod h1:tMWxXQ9wFIaZeTI9F+hmhFiGpFmhOHzyShyFUhRm0H4= github.com/hashicorp/consul/api v1.1.0/go.mod h1:VmuI/Lkw1nC05EYQWNKwWGbkg+FbDBtguAZLlVdkD9Q= github.com/hashicorp/consul/api v1.10.1/go.mod h1:XjsvQN+RJGWI2TWy1/kqaE16HrR2J/FWgkYjdZQsX9M= @@ -1188,6 +1192,8 @@ github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHm github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= +github.com/juju/errors v1.0.0 h1:yiq7kjCLll1BiaRuNY53MGI0+EQ3rF6GB+wvboZDefM= +github.com/juju/errors v1.0.0/go.mod h1:B5x9thDqx0wIMH3+aLIMP9HjItInYWObRovoCFM5Qe8= github.com/juju/ratelimit v1.0.1/go.mod h1:qapgC/Gy+xNh9UxzV13HGGl/6UXNN+ct+vwSgWNm/qk= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= diff --git a/provisioner/echo/serve.go b/provisioner/echo/serve.go index 705fb0a3be2ae..2f005a54a4398 100644 --- a/provisioner/echo/serve.go +++ b/provisioner/echo/serve.go @@ -207,6 +207,7 @@ func Tar(responses *Responses) ([]byte, error) { err = writer.WriteHeader(&tar.Header{ Name: fmt.Sprintf("%d.parse.protobuf", index), Size: int64(len(data)), + Mode: 0o777, }) if err != nil { return nil, err From e1cbf828a2dacb06db96b5645391efd590690008 Mon Sep 17 00:00:00 2001 From: Ammar Bandukwala Date: Tue, 21 Feb 2023 17:59:23 +0000 Subject: [PATCH 2/8] Make some progress... --- cli/templatepull.go | 26 +++++++++++---- cli/templatepull_test.go | 71 ++++++++++++++++++++++++++++++++++++++-- go.mod | 12 ++++--- go.sum | 19 ++++++++--- 4 files changed, 110 insertions(+), 18 deletions(-) diff --git a/cli/templatepull.go b/cli/templatepull.go index 4ed994f7bd0a8..efcaa559e9595 100644 --- a/cli/templatepull.go +++ b/cli/templatepull.go @@ -3,7 +3,6 @@ package cli import ( "bytes" "fmt" - "io/fs" "os" "sort" @@ -87,14 +86,29 @@ func templatePull() *cobra.Command { dest = templateName + "/" } - _, _ = fmt.Fprintf(cmd.OutOrStderr(), "Extracting template to %q\n", dest) + err = os.MkdirAll(dest, 0o750) + if err != nil { + return xerrors.Errorf("mkdirall %q: %w", dest, err) + } - // Stat the destination to ensure nothing exists already. - _, err = os.Stat(dest) - if err != nil && !xerrors.Is(err, fs.ErrNotExist) { - return xerrors.Errorf("stat destination: %w", err) + ents, err := os.ReadDir(dest) + if err != nil { + return xerrors.Errorf("read dir %q: %w", dest, err) } + if len(ents) > 0 { + _, err = cliui.Prompt(cmd, cliui.PromptOptions{ + Text: fmt.Sprintf("Directory %q is not empty, existing files may be overwritten.\nContinue extracting?", dest), + Default: "No", + Secret: false, + IsConfirm: true, + }) + if err != nil { + return err + } + } + + _, _ = fmt.Fprintf(cmd.OutOrStderr(), "Extracting template to %q\n", dest) err = extract.Tar(ctx, bytes.NewReader(raw), dest, nil) return err }, diff --git a/cli/templatepull_test.go b/cli/templatepull_test.go index d88e9df96c662..684e263a9bcee 100644 --- a/cli/templatepull_test.go +++ b/cli/templatepull_test.go @@ -4,6 +4,7 @@ import ( "bytes" "context" "io" + "os" "path/filepath" "testing" @@ -68,9 +69,9 @@ func TestTemplatePull(t *testing.T) { require.True(t, bytes.Equal(expected, buf.Bytes()), "tar files differ") }) - // ToFile tests that 'templates pull' pulls down the latest template + // ToDir tests that 'templates pull' pulls down the latest template // and writes it to the correct directory. - t.Run("ToFile", func(t *testing.T) { + t.Run("ToDir", func(t *testing.T) { t.Parallel() client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerDaemon: true}) @@ -131,9 +132,73 @@ func TestTemplatePull(t *testing.T) { require.True(t, bytes.Equal(expectedTar, actualTar), "tar files differ") }) + + // FolderConflict tests that 'templates pull' fails when a folder with has + // existing + t.Run("FolderConflict", func(t *testing.T) { + t.Parallel() + + client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerDaemon: true}) + user := coderdtest.CreateFirstUser(t, client) + + // Create an initial template bundle. + source1 := genTemplateVersionSource() + // Create an updated template bundle. This will be used to ensure + // that templates are correctly returned in order from latest to oldest. + source2 := genTemplateVersionSource() + + expected, err := echo.Tar(source2) + require.NoError(t, err) + + version1 := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, source1) + _ = coderdtest.AwaitTemplateVersionJob(t, client, version1.ID) + + template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version1.ID) + + // Update the template version so that we can assert that templates + // are being sorted correctly. + _ = coderdtest.UpdateTemplateVersion(t, client, user.OrganizationID, source2, template.ID) + + dir := t.TempDir() + + expectedDest := filepath.Join(dir, "expected") + conflictDest := filepath.Join(dir, "conflict") + + err = os.MkdirAll(conflictDest, 0o700) + require.NoError(t, err) + + err = os.WriteFile( + filepath.Join(conflictDest, "conflict-file"), + []byte("conflict"), 0o600, + ) + require.NoError(t, err) + + ctx := context.Background() + + err = extract.Tar(ctx, bytes.NewReader(expected), expectedDest, nil) + require.NoError(t, err) + + cmd, root := clitest.New(t, "templates", "pull", template.Name, conflictDest) + clitest.SetupConfig(t, client, root) + + pty := ptytest.New(t) + cmd.SetIn(pty.Input()) + cmd.SetOut(pty.Output()) + + errChan := make(chan error) + go func() { + defer close(errChan) + errChan <- cmd.Execute() + }() + + pty.ExpectMatch("not empty") + pty.WriteLine("no") + + require.NoError(t, <-errChan) + }) } -// genTemplateVersionSource returns a unique bundle that can be used to create +// genTemplateVersionSource returnS a unique bundle that can be used to create // a template version source. func genTemplateVersionSource() *echo.Responses { return &echo.Responses{ diff --git a/go.mod b/go.mod index 91b15ddb9d1bf..4d23861bbb75e 100644 --- a/go.mod +++ b/go.mod @@ -68,6 +68,7 @@ require ( github.com/charmbracelet/glamour v0.6.0 github.com/charmbracelet/lipgloss v0.6.0 github.com/cli/safeexec v1.0.0 + github.com/codeclysm/extract v2.2.0+incompatible github.com/coder/retry v1.3.1-0.20230210155434-e90a2e1e091d github.com/coder/terraform-provider-coder v0.6.11 github.com/coreos/go-oidc/v3 v3.4.0 @@ -111,7 +112,7 @@ require ( github.com/kirsle/configdir v0.0.0-20170128060238-e45d2f54772f github.com/klauspost/compress v1.15.9 github.com/lib/pq v1.10.6 - github.com/mattn/go-isatty v0.0.16 + github.com/mattn/go-isatty v0.0.17 github.com/mitchellh/go-wordwrap v1.0.1 github.com/mitchellh/mapstructure v1.5.0 github.com/moby/moby v20.10.23+incompatible @@ -125,6 +126,7 @@ require ( github.com/prometheus/client_golang v1.14.0 github.com/quasilyte/go-ruleguard/dsl v0.3.21 github.com/robfig/cron/v3 v3.0.1 + github.com/schollz/progressbar/v3 v3.13.0 github.com/spf13/afero v1.9.3 github.com/spf13/cobra v1.6.1 github.com/spf13/pflag v1.0.5 @@ -153,8 +155,8 @@ require ( golang.org/x/mod v0.7.0 golang.org/x/oauth2 v0.3.0 golang.org/x/sync v0.1.0 - golang.org/x/sys v0.4.1-0.20230131160137-e7d7f63158de - golang.org/x/term v0.4.0 + golang.org/x/sys v0.5.0 + golang.org/x/term v0.5.0 golang.org/x/text v0.6.0 golang.org/x/tools v0.4.1-0.20221208213631-3f74d914ae6d golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 @@ -174,9 +176,9 @@ require ( ) require ( - github.com/codeclysm/extract v2.2.0+incompatible // indirect github.com/h2non/filetype v1.1.3 // indirect github.com/juju/errors v1.0.0 // indirect + github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect ) require ( @@ -299,7 +301,7 @@ require ( github.com/prometheus/common v0.39.0 github.com/prometheus/procfs v0.8.0 // indirect github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0 // indirect - github.com/rivo/uniseg v0.2.0 // indirect + github.com/rivo/uniseg v0.4.4 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/satori/go.uuid v1.2.0 // indirect github.com/sirupsen/logrus v1.9.0 // indirect diff --git a/go.sum b/go.sum index ab162526e6a99..0d3cfa09e179b 100644 --- a/go.sum +++ b/go.sum @@ -1203,6 +1203,7 @@ github.com/jung-kurt/gofpdf v1.0.3-0.20190309125859-24315acbbda5/go.mod h1:7Id9E github.com/justinas/nosurf v1.1.1 h1:92Aw44hjSK4MxJeMSyDa7jwuI9GR2J/JCQiaKvXXSlk= github.com/justinas/nosurf v1.1.1/go.mod h1:ALpWdSbuNGy2lZWtyXdjkYv4edL23oSEgfBT1gPJ5BQ= github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88/go.mod h1:3w7q1U84EfirKl04SVQ/s7nPm1ZPhiXd34z40TNz36k= +github.com/k0kubun/go-ansi v0.0.0-20180517002512-3bf9e2903213/go.mod h1:vNUNkEQ1e29fT/6vq2aBdFsgNPmy8qMdSay1npru+Sw= github.com/k0kubun/pp v2.3.0+incompatible/go.mod h1:GWse8YhT0p8pT4ir3ZgBbfZild3tgzSScAn6HmfYukg= github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0/go.mod h1:1NbS8ALrpOvjt0rHPNLyCIeMtbizbir8U//inJ+zuB8= github.com/karrick/godirwalk v1.8.0/go.mod h1:H5KPZjojv4lE+QYImBI8xVtrBRgYrIVsaRPx4tDPEn4= @@ -1330,8 +1331,9 @@ github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOA github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= github.com/mattn/go-isatty v0.0.13/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= -github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ= github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= +github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng= +github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/mattn/go-runewidth v0.0.6/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= @@ -1388,6 +1390,8 @@ github.com/mistifyio/go-zfs v2.1.2-0.20190413222219-f784269be439+incompatible/go github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc= github.com/mitchellh/cli v1.1.0/go.mod h1:xcISNoH86gajksDmfB23e/pu+B+GeFRMYmoHXxx3xhI= github.com/mitchellh/cli v1.1.4/go.mod h1:vTLESy5mRhKOs9KDp0/RATawxP1UqBmdrpVRMnpcvKQ= +github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db h1:62I3jR2EmQ4l5rM/4FEfDWcRD+abF5XlKShorW5LRoQ= +github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db/go.mod h1:l0dey0ia/Uv7NcFFVbCLtqEBQbrT4OCwCSKTEv6enCw= github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw= github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw= github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HKCj9FbZEVFJRxO9s= @@ -1651,8 +1655,10 @@ github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0/go.mod h1:bCqn github.com/remyoudompheng/bigfft v0.0.0-20190728182440-6a916e37a237/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo= github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo= github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= -github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= +github.com/rivo/uniseg v0.4.3/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= +github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis= +github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs= github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro= github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= @@ -1684,6 +1690,8 @@ github.com/sahilm/fuzzy v0.1.0/go.mod h1:VFvziUEIMCrT6A6tw2RFIXPXXmzXbOsSHF0DOI8 github.com/sanposhiho/wastedassign/v2 v2.0.6/go.mod h1:KyZ0MWTwxxBmfwn33zh3k1dmsbF2ud9pAAGfoLfjhtI= github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww= github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= +github.com/schollz/progressbar/v3 v3.13.0 h1:9TeeWRcjW2qd05I8Kf9knPkW4vLM/hYoa6z9ABvxje8= +github.com/schollz/progressbar/v3 v3.13.0/go.mod h1:ZBYnSuLAX2LU8P8UiKN/KgF2DY58AJC8yfVYLPC8Ly4= github.com/sclevine/agouti v3.0.0+incompatible/go.mod h1:b4WX9W9L1sfQKXeJf1mUTLZKJ48R1S7H23Ji7oFO5Bw= github.com/sclevine/spec v1.2.0/go.mod h1:W4J29eT/Kzv7/b9IWLB055Z+qvVC9vt0Arko24q7p+U= github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= @@ -2411,8 +2419,10 @@ golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.4.1-0.20230131160137-e7d7f63158de h1:VO/n/VqVQnSnxYKbExOquQRm9FLLepZKkpYyXf1+6l8= +golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.4.1-0.20230131160137-e7d7f63158de/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU= +golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= @@ -2420,8 +2430,9 @@ golang.org/x/term v0.0.0-20210422114643-f5beecf764ed/go.mod h1:bj7SfCRtBDWHUb9sn golang.org/x/term v0.0.0-20210503060354-a79de5458b56/go.mod h1:tfny5GFUkzUvx4ps4ajbZsCe5lw1metzhBm9T3x7oIY= golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/term v0.4.0 h1:O7UWfv5+A2qiuulQk30kVinPoMtoIPeVaKLEgLpVkvg= golang.org/x/term v0.4.0/go.mod h1:9P2UbLfCdcvo3p/nzKvsmas4TnlujnuoV9hGgYzW1lQ= +golang.org/x/term v0.5.0 h1:n2a8QNdAb0sZNpU9R1ALUXBbY+w51fCQDN+7EdxNBsY= +golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= From b39628a5c50df4ccb90f13ecd25f184d9a1cfcbe Mon Sep 17 00:00:00 2001 From: Ammar Bandukwala Date: Wed, 22 Feb 2023 18:26:21 +0000 Subject: [PATCH 3/8] fixup! Make some progress... --- cli/templatepull_test.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cli/templatepull_test.go b/cli/templatepull_test.go index 684e263a9bcee..b4ec235110d3d 100644 --- a/cli/templatepull_test.go +++ b/cli/templatepull_test.go @@ -194,7 +194,12 @@ func TestTemplatePull(t *testing.T) { pty.ExpectMatch("not empty") pty.WriteLine("no") - require.NoError(t, <-errChan) + require.Error(t, <-errChan) + + ents, err := os.ReadDir(conflictDest) + require.NoError(t, err) + + require.Len(t, ents, 1, "conflict folder should have single conflict file") }) } From fcd767ddb018d7fe9137be4a8e1b24e1203ad815 Mon Sep 17 00:00:00 2001 From: Ammar Bandukwala Date: Wed, 22 Feb 2023 18:28:17 +0000 Subject: [PATCH 4/8] fixup! Merge remote-tracking branch 'origin/main' into pull-tar --- provisioner/echo/serve.go | 1 - 1 file changed, 1 deletion(-) diff --git a/provisioner/echo/serve.go b/provisioner/echo/serve.go index 2f005a54a4398..705fb0a3be2ae 100644 --- a/provisioner/echo/serve.go +++ b/provisioner/echo/serve.go @@ -207,7 +207,6 @@ func Tar(responses *Responses) ([]byte, error) { err = writer.WriteHeader(&tar.Header{ Name: fmt.Sprintf("%d.parse.protobuf", index), Size: int64(len(data)), - Mode: 0o777, }) if err != nil { return nil, err From 6d81fa187e94a7383362f68137b394c86ec12e87 Mon Sep 17 00:00:00 2001 From: Ammar Bandukwala Date: Wed, 22 Feb 2023 18:29:39 +0000 Subject: [PATCH 5/8] fixup! Merge remote-tracking branch 'origin/main' into pull-tar --- cli/templatepull_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/templatepull_test.go b/cli/templatepull_test.go index b4ec235110d3d..d586b95a4593c 100644 --- a/cli/templatepull_test.go +++ b/cli/templatepull_test.go @@ -203,7 +203,7 @@ func TestTemplatePull(t *testing.T) { }) } -// genTemplateVersionSource returnS a unique bundle that can be used to create +// genTemplateVersionSource returns a unique bundle that can be used to create // a template version source. func genTemplateVersionSource() *echo.Responses { return &echo.Responses{ From 233375f0184f4f35e0c3fc33d2ed031b6f425020 Mon Sep 17 00:00:00 2001 From: Ammar Bandukwala Date: Wed, 22 Feb 2023 18:38:00 +0000 Subject: [PATCH 6/8] update golden files --- cli/testdata/coder_templates_pull_--help.golden | 1 + 1 file changed, 1 insertion(+) diff --git a/cli/testdata/coder_templates_pull_--help.golden b/cli/testdata/coder_templates_pull_--help.golden index af214b70ed954..b3c6df36ca9f8 100644 --- a/cli/testdata/coder_templates_pull_--help.golden +++ b/cli/testdata/coder_templates_pull_--help.golden @@ -5,6 +5,7 @@ Usage: Flags: -h, --help help for pull + --tar output the template as a tar archive to stdout -y, --yes Bypass prompts Global Flags: From e75892a5f4375dbb7b4c22718bf225c4be122bf0 Mon Sep 17 00:00:00 2001 From: Ammar Bandukwala Date: Wed, 22 Feb 2023 19:06:58 +0000 Subject: [PATCH 7/8] fix perms --- provisioner/echo/serve.go | 1 + 1 file changed, 1 insertion(+) diff --git a/provisioner/echo/serve.go b/provisioner/echo/serve.go index 705fb0a3be2ae..774873f53d93c 100644 --- a/provisioner/echo/serve.go +++ b/provisioner/echo/serve.go @@ -207,6 +207,7 @@ func Tar(responses *Responses) ([]byte, error) { err = writer.WriteHeader(&tar.Header{ Name: fmt.Sprintf("%d.parse.protobuf", index), Size: int64(len(data)), + Mode: 0o644, }) if err != nil { return nil, err From d0922763fccf59481ff9626ff6f45051b346f4a7 Mon Sep 17 00:00:00 2001 From: Ammar Bandukwala Date: Wed, 22 Feb 2023 19:14:37 +0000 Subject: [PATCH 8/8] make gen --- docs/cli/coder_templates_pull.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/cli/coder_templates_pull.md b/docs/cli/coder_templates_pull.md index f43ad6a2f3aea..909695ec5a9c1 100644 --- a/docs/cli/coder_templates_pull.md +++ b/docs/cli/coder_templates_pull.md @@ -10,6 +10,7 @@ coder templates pull [destination] [flags] ``` -h, --help help for pull + --tar output the template as a tar archive to stdout -y, --yes Bypass prompts ```