Skip to content

Commit

Permalink
fix: fail on static directories
Browse files Browse the repository at this point in the history
  • Loading branch information
sweatybridge committed Feb 11, 2025
1 parent 1c1b9d2 commit 4b9b7b3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
15 changes: 9 additions & 6 deletions cmd/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ var (

useApi bool
useDocker bool
noVerifyJWT = new(bool)
useLegacyBundle bool
noVerifyJWT = new(bool)
importMapPath string

functionsDeployCmd = &cobra.Command{
Expand All @@ -67,6 +67,9 @@ var (
if !cmd.Flags().Changed("no-verify-jwt") {
noVerifyJWT = nil
}
if useApi {
useDocker = false
}
return deploy.Run(cmd.Context(), args, useDocker, noVerifyJWT, importMapPath, afero.NewOsFs())
},
}
Expand Down Expand Up @@ -126,14 +129,14 @@ func init() {
functionsListCmd.Flags().StringVar(&flags.ProjectRef, "project-ref", "", "Project ref of the Supabase project.")
functionsDeleteCmd.Flags().StringVar(&flags.ProjectRef, "project-ref", "", "Project ref of the Supabase project.")
deployFlags := functionsDeployCmd.Flags()
deployFlags.BoolVar(&useApi, "use-api", true, "Use Management API to bundle functions.")
deployFlags.BoolVar(&useDocker, "use-docker", false, "Use Docker to bundle functions.")
functionsDeployCmd.MarkFlagsMutuallyExclusive("use-api", "use-docker")
deployFlags.BoolVar(&useApi, "use-api", false, "Use Management API to bundle functions.")
deployFlags.BoolVar(&useDocker, "use-docker", true, "Use Docker to bundle functions.")
deployFlags.BoolVar(&useLegacyBundle, "legacy-bundle", false, "Use legacy bundling mechanism.")
functionsDeployCmd.MarkFlagsMutuallyExclusive("use-api", "use-docker", "legacy-bundle")
cobra.CheckErr(deployFlags.MarkHidden("legacy-bundle"))
deployFlags.BoolVar(noVerifyJWT, "no-verify-jwt", false, "Disable JWT verification for the Function.")
deployFlags.StringVar(&flags.ProjectRef, "project-ref", "", "Project ref of the Supabase project.")
deployFlags.BoolVar(&useLegacyBundle, "legacy-bundle", false, "Use legacy bundling mechanism.")
deployFlags.StringVar(&importMapPath, "import-map", "", "Path to import map file.")
cobra.CheckErr(deployFlags.MarkHidden("legacy-bundle"))
functionsServeCmd.Flags().BoolVar(noVerifyJWT, "no-verify-jwt", false, "Disable JWT verification for the Function.")
functionsServeCmd.Flags().StringVar(&envFilePath, "env-file", "", "Path to an env file to be populated to the Function environment.")
functionsServeCmd.Flags().StringVar(&importMapPath, "import-map", "", "Path to import map file.")
Expand Down
5 changes: 3 additions & 2 deletions internal/functions/deploy/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ func upload(ctx context.Context, param api.V1DeployAFunctionParams, meta api.Fun
defer w.Close()
defer form.Close()
if err := writeForm(form, meta, fsys); err != nil {
// Since we are streaming files to the POST request body, any errors
// should be propagated to the request context to cancel the upload.
cancel(err)
}
}()
Expand Down Expand Up @@ -111,8 +113,7 @@ func writeForm(form *multipart.Writer, meta api.FunctionDeployMetadata, fsys afe
if fi, err := f.Stat(); err != nil {
return errors.Errorf("failed to stat file: %w", err)
} else if fi.IsDir() {
fmt.Fprintln(os.Stderr, "Skipping directory:", srcPath)
return nil
return errors.New("file path is a directory: " + srcPath)
}
fmt.Fprintln(os.Stderr, "Uploading asset:", srcPath)
r := io.TeeReader(f, w)
Expand Down
14 changes: 14 additions & 0 deletions internal/functions/deploy/upload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,20 @@ func TestWriteForm(t *testing.T) {
// Check error
assert.ErrorIs(t, err, os.ErrNotExist)
})

t.Run("throws error on directory path", func(t *testing.T) {
var buf bytes.Buffer
form := multipart.NewWriter(&buf)
require.NoError(t, form.SetBoundary("test"))
// Setup in-memory fs
fsys := afero.NewMemMapFs()
// Run test
err := writeForm(form, api.FunctionDeployMetadata{
StaticPatterns: cast.Ptr([]string{"testdata"}),
}, fsys)
// Check error
assert.ErrorContains(t, err, "file path is a directory:")
})
}

func TestDeployAll(t *testing.T) {
Expand Down

0 comments on commit 4b9b7b3

Please sign in to comment.