Skip to content

Commit

Permalink
debugging windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Integralist committed Sep 27, 2023
1 parent 366518f commit 6f9d7ff
Show file tree
Hide file tree
Showing 8 changed files with 229 additions and 115 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pr_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ jobs:
shell: bash
env:
# NOTE: The following lets us focus the test run while debugging.
# TEST_ARGS: "-run TestDeploy ./pkg/commands/compute/..."
# TEST_ARGS: "-run TestBuild ./pkg/commands/compute/..."
TEST_COMPUTE_INIT: true
TEST_COMPUTE_BUILD: true
TEST_COMPUTE_DEPLOY: true
Expand Down
20 changes: 11 additions & 9 deletions cmd/fastly/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

"github.com/fastly/cli/pkg/api"
"github.com/fastly/cli/pkg/app"
"github.com/fastly/cli/pkg/commands/compute"
"github.com/fastly/cli/pkg/config"
"github.com/fastly/cli/pkg/env"
fsterr "github.com/fastly/cli/pkg/errors"
Expand Down Expand Up @@ -87,15 +88,16 @@ func main() {
client, err := fastly.NewClientForEndpoint(token, endpoint)
return client, err
},
Args: args,
ConfigFile: cfg,
ConfigPath: config.FilePath,
Env: e,
ErrLog: fsterr.Log,
HTTPClient: httpClient,
Manifest: &md,
Stdin: in,
Stdout: out,
Args: args,
ConfigFile: cfg,
ConfigPath: config.FilePath,
Env: e,
ErrLog: fsterr.Log,
ExecuteWasmTools: compute.ExecuteWasmTools,
HTTPClient: httpClient,
Manifest: &md,
Stdin: in,
Stdout: out,
Versioners: app.Versioners{
CLI: github.New(github.Opts{
HTTPClient: httpClient,
Expand Down
38 changes: 20 additions & 18 deletions pkg/app/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,14 @@ func Run(opts RunOpts) error {
// The g will hold generally-applicable configuration parameters
// from a variety of sources, and is provided to each concrete command.
g := global.Data{
Env: opts.Env,
ErrLog: opts.ErrLog,
Config: opts.ConfigFile,
ConfigPath: opts.ConfigPath,
HTTPClient: opts.HTTPClient,
Manifest: *opts.Manifest,
Output: opts.Stdout,
Config: opts.ConfigFile,
ConfigPath: opts.ConfigPath,
Env: opts.Env,
ErrLog: opts.ErrLog,
ExecuteWasmTools: opts.ExecuteWasmTools,
HTTPClient: opts.HTTPClient,
Manifest: *opts.Manifest,
Output: opts.Stdout,
}

// Set up the main application root, including global flags, and then each
Expand Down Expand Up @@ -186,17 +187,18 @@ func Run(opts RunOpts) error {

// RunOpts represent arguments to Run()
type RunOpts struct {
APIClient APIClientFactory
Args []string
ConfigFile config.File
ConfigPath string
Env config.Environment
ErrLog fsterr.LogInterface
HTTPClient api.HTTPClient
Manifest *manifest.Data
Stdin io.Reader
Stdout io.Writer
Versioners Versioners
APIClient APIClientFactory
Args []string
ConfigFile config.File
ConfigPath string
Env config.Environment
ErrLog fsterr.LogInterface
ExecuteWasmTools func(bin string, args []string) error
HTTPClient api.HTTPClient
Manifest *manifest.Data
Stdin io.Reader
Stdout io.Writer
Versioners Versioners
}

// APIClientFactory creates a Fastly API client (modeled as an api.Interface)
Expand Down
52 changes: 26 additions & 26 deletions pkg/commands/compute/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ func (c *BuildCommand) Exec(in io.Reader, out io.Writer) (err error) {
args = append(args, fmt.Sprintf("--sdk=%s=%s", k, v))
}

err = c.executeWasmtools(wasmtools, args)
err = c.Globals.ExecuteWasmTools(wasmtools, args)
if err != nil {
return err
}
Expand Down Expand Up @@ -281,7 +281,7 @@ func (c *BuildCommand) Exec(in io.Reader, out io.Writer) (err error) {
"metadata", "add", "bin/main.wasm",
fmt.Sprintf("--language=CLI_%s: %s", revision.AppVersion, strings.ToUpper(language.Name)),
}
err = c.executeWasmtools(wasmtools, args)
err = c.Globals.ExecuteWasmTools(wasmtools, args)
if err != nil {
return err
}
Expand Down Expand Up @@ -339,30 +339,6 @@ func (c *BuildCommand) Exec(in io.Reader, out io.Writer) (err error) {
return nil
}

func (c *BuildCommand) executeWasmtools(wasmtools string, args []string) error {
// gosec flagged this:
// G204 (CWE-78): Subprocess launched with function call as argument or command arguments
// Disabling as we trust the source of the variable.
// #nosec
// nosemgrep: go.lang.security.audit.dangerous-exec-command.dangerous-exec-command
command := exec.Command(wasmtools, args...)
wasmtoolsOutput, err := command.Output()
if err != nil {
return fmt.Errorf("failed to annotate binary with metadata: %w", err)
}
// Ensure the Wasm binary can be executed.
//
// G302 (CWE-276): Expect file permissions to be 0600 or less
// gosec flagged this:
// Disabling as we want all users to be able to execute this binary.
// #nosec
err = os.WriteFile("bin/main.wasm", wasmtoolsOutput, 0o777)
if err != nil {
return fmt.Errorf("failed to annotate binary with metadata: %w", err)
}
return nil
}

// includeSourceCode calculates what source code files to include in the final
// package.tar.gz that is uploaded to the Fastly API.
//
Expand Down Expand Up @@ -404,6 +380,30 @@ func (c *BuildCommand) includeSourceCode(files []string, srcDir string) ([]strin
return files, nil
}

func ExecuteWasmTools(wasmtools string, args []string) error {

Check failure on line 383 in pkg/commands/compute/build.go

View workflow job for this annotation

GitHub Actions / lint

exported function ExecuteWasmTools should have comment or be unexported
// gosec flagged this:
// G204 (CWE-78): Subprocess launched with function call as argument or command arguments
// Disabling as we trust the source of the variable.
// #nosec
// nosemgrep: go.lang.security.audit.dangerous-exec-command.dangerous-exec-command
command := exec.Command(wasmtools, args...)
wasmtoolsOutput, err := command.Output()
if err != nil {
return fmt.Errorf("failed to annotate binary with metadata: %w", err)
}
// Ensure the Wasm binary can be executed.
//
// G302 (CWE-276): Expect file permissions to be 0600 or less
// gosec flagged this:
// Disabling as we want all users to be able to execute this binary.
// #nosec
err = os.WriteFile("bin/main.wasm", wasmtoolsOutput, 0o777)
if err != nil {
return fmt.Errorf("failed to annotate binary with metadata: %w", err)
}
return nil
}

// GetWasmTools returns the path to the wasm-tools binary.
// If there is no version installed, install the latest version.
// If there is a version installed, update to the latest version if not already.
Expand Down
Loading

0 comments on commit 6f9d7ff

Please sign in to comment.