8000 chore(coderd): extract fileszip to its own package for reuse by johnstcn · Pull Request #15229 · coder/coder · GitHub
[go: up one dir, main page]

Skip to content

chore(coderd): extract fileszip to its own package for reuse #15229

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
export HTTPFileMaxBytes, reference in cli test
  • Loading branch information
johnstcn committed Oct 25, 2024
commit 2c1d3d60f32820eb99040d1f3438034f80b39ce8
3 changes: 2 additions & 1 deletion cli/templatepull_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (

"github.com/coder/coder/v2/archive"
"github.com/coder/coder/v2/cli/clitest"
"github.com/coder/coder/v2/coderd"
"github.com/coder/coder/v2/coderd/coderdtest"
"github.com/coder/coder/v2/coderd/rbac"
"github.com/coder/coder/v2/provisioner/echo"
Expand Down Expand Up @@ -95,7 +96,7 @@ func TestTemplatePull_Stdout(t *testing.T) {

// Verify .zip format
tarReader := tar.NewReader(bytes.NewReader(expected))
expectedZip, err := archive.CreateZipFromTar(tarReader, int64(len(expected)))
expectedZip, err := archive.CreateZipFromTar(tarReader, coderd.HTTPFileMaxBytes)
require.NoError(t, err)

inv, root = clitest.New(t, "templates", "pull", "--zip", template.Name)
Expand Down
8 changes: 4 additions & 4 deletions coderd/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const (
tarMimeType = "application/x-tar"
zipMimeType = "application/zip"

httpFileMaxBytes = 10 * (10 << 20)
HTTPFileMaxBytes = 10 * (10 << 20)
)

// @Summary Upload file
Expand Down Expand Up @@ -56,7 +56,7 @@ func (api *API) postFile(rw http.ResponseWriter, r *http.Request) {
return
}

r.Body = http.MaxBytesReader(rw, r.Body, httpFileMaxBytes)
r.Body = http.MaxBytesReader(rw, r.Body, HTTPFileMaxBytes)
data, err := io.ReadAll(r.Body)
if err != nil {
httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
Expand All @@ -76,7 +76,7 @@ func (api *API) postFile(rw http.ResponseWriter, r *http.Request) {
return
}

data, err = archive.CreateTarFromZip(zipReader, httpFileMaxBytes)
data, err = archive.CreateTarFromZip(zipReader, HTTPFileMaxBytes)
if err != nil {
httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
Message: "Internal error processing .zip archive.",
Expand Down Expand Up @@ -182,7 +182,7 @@ func (api *API) fileByID(rw http.ResponseWriter, r *http.Request) {

rw.Header().Set("Content-Type", codersdk.ContentTypeZip)
rw.WriteHeader(http.StatusOK)
err = archive.WriteZip(rw, tar.NewReader(bytes.NewReader(file.Data)), httpFileMaxBytes)
err = archive.WriteZip(rw, tar.NewReader(bytes.NewReader(file.Data)), HTTPFileMaxBytes)
if err != nil {
api.Logger.Error(ctx, "invalid .zip archive", slog.F("file_id", fileID), slog.F("mimetype", file.Mimetype), slog.Error(err))
}
Expand Down
Loading
0