Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 1 addition & 2 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ version: 2
updates:
# Dependencies listed in go.mod
- package-ecosystem: "gomod"
directory: "/" # Location of package manifests
directory: "/"
schedule:
interval: "weekly"

# Dependencies listed in .github/workflows/*.yml
- package-ecosystem: "github-actions"
directory: "/"
Expand Down
1 change: 1 addition & 0 deletions pkg/app/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func FastlyAPIClient(token, endpoint string) (api.Interface, error) {
// and returned to the caller. This includes usage text.
func Run(opts RunOpts) error {
var md manifest.Data
md.File.Args = opts.Args
md.File.SetErrLog(opts.ErrLog)
md.File.SetOutput(opts.Stdout)
_ = md.File.Read(manifest.Filename)
Expand Down
2 changes: 1 addition & 1 deletion pkg/commands/compute/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (c *BuildCommand) Exec(in io.Reader, out io.Writer) (err error) {
if err != nil {
return err
}
msg := "Verifying package manifest"
msg := "Verifying fastly.toml"
spinner.Message(msg + "...")

err = c.Manifest.File.ReadError()
Expand Down
8 changes: 4 additions & 4 deletions pkg/commands/compute/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestBuildRust(t *testing.T) {
{
name: "no fastly.toml manifest",
args: args("compute build"),
wantError: "error reading package manifest",
wantError: "error reading fastly.toml",
wantRemediationError: "Run `fastly compute init` to ensure a correctly configured manifest.",
},
{
Expand Down Expand Up @@ -223,7 +223,7 @@ func TestBuildGo(t *testing.T) {
{
name: "no fastly.toml manifest",
args: args("compute build"),
wantError: "error reading package manifest",
wantError: "error reading fastly.toml",
wantRemediationError: "Run `fastly compute init` to ensure a correctly configured manifest.",
},
{
Expand Down Expand Up @@ -383,7 +383,7 @@ func TestBuildJavaScript(t *testing.T) {
{
name: "no fastly.toml manifest",
args: args("compute build"),
wantError: "error reading package manifest",
wantError: "error reading fastly.toml",
wantRemediationError: "Run `fastly compute init` to ensure a correctly configured manifest.",
},
{
Expand Down Expand Up @@ -535,7 +535,7 @@ func TestBuildAssemblyScript(t *testing.T) {
{
name: "no fastly.toml manifest",
args: args("compute build"),
wantError: "error reading package manifest",
wantError: "error reading fastly.toml",
wantRemediationError: "Run `fastly compute init` to ensure a correctly configured manifest.",
},
{
Expand Down
7 changes: 5 additions & 2 deletions pkg/commands/compute/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,9 @@ func readManifestFromPackageArchive(data *manifest.Data, packageFlag string, ver

err = data.File.Read(manifestPath)
if err != nil {
if errors.Is(err, os.ErrNotExist) {
err = fsterr.ErrReadingManifest
}
return err
}

Expand Down Expand Up @@ -684,13 +687,13 @@ func cleanupService(apiClient api.Interface, serviceID string, m manifest.Data,
// manifest will continue to hold a reference to it).
func updateManifestServiceID(m *manifest.File, manifestFilename string, serviceID string) error {
if err := m.Read(manifestFilename); err != nil {
return fmt.Errorf("error reading package manifest: %w", err)
return fmt.Errorf("error reading fastly.toml: %w", err)
}

m.ServiceID = serviceID

if err := m.Write(manifestFilename); err != nil {
return fmt.Errorf("error saving package manifest: %w", err)
return fmt.Errorf("error saving fastly.toml: %w", err)
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/commands/compute/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func TestDeploy(t *testing.T) {
{
name: "no fastly.toml manifest",
args: args("compute deploy --token 123"),
wantError: "error reading package manifest",
wantError: "error reading fastly.toml",
wantRemediationError: errors.ComputeInitRemediation,
noManifest: true,
},
Expand Down
8 changes: 4 additions & 4 deletions pkg/commands/compute/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -960,7 +960,7 @@ func updateManifest(
if err != nil {
return m, err
}
msg := "Reading package manifest"
msg := "Reading fastly.toml"
spinner.Message(msg + "...")

mp := filepath.Join(path, manifest.Filename)
Expand All @@ -981,7 +981,7 @@ func updateManifest(
if spinErr != nil {
return m, spinErr
}
return m, fmt.Errorf("error saving package manifest: %w", err)
return m, fmt.Errorf("error saving fastly.toml: %w", err)
}
spinner.StopFailMessage(msg)
spinErr := spinner.StopFail()
Expand All @@ -997,7 +997,7 @@ func updateManifest(
if spinErr != nil {
return m, spinErr
}
return m, fmt.Errorf("error reading package manifest: %w", err)
return m, fmt.Errorf("error reading fastly.toml: %w", err)
}

spinner.StopMessage(msg)
Expand Down Expand Up @@ -1087,7 +1087,7 @@ func updateManifest(
if spinErr != nil {
return m, spinErr
}
return m, fmt.Errorf("error saving package manifest: %w", err)
return m, fmt.Errorf("error saving fastly.toml: %w", err)
}

spinner.StopMessage(msg)
Expand Down
28 changes: 14 additions & 14 deletions pkg/commands/compute/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func TestInit(t *testing.T) {
stdin: "foobar", // expect the first prompt to be for the package name.
wantOutput: []string{
"Fetching package template",
"Reading package manifest",
"Reading fastly.toml",
},
manifestIncludes: `name = "foobar"`,
},
Expand All @@ -86,7 +86,7 @@ func TestInit(t *testing.T) {
},
wantOutput: []string{
"Fetching package template",
"Reading package manifest",
"Reading fastly.toml",
},
manifestIncludes: `description = ""`, // expect this to be empty
},
Expand All @@ -100,7 +100,7 @@ func TestInit(t *testing.T) {
},
wantOutput: []string{
"Fetching package template",
"Reading package manifest",
"Reading fastly.toml",
},
manifestIncludes: `authors = ["[email protected]"]`,
},
Expand All @@ -114,7 +114,7 @@ func TestInit(t *testing.T) {
},
wantOutput: []string{
"Fetching package template",
"Reading package manifest",
"Reading fastly.toml",
},
manifestIncludes: `authors = ["[email protected]", "[email protected]"]`,
},
Expand All @@ -133,7 +133,7 @@ func TestInit(t *testing.T) {
},
wantOutput: []string{
"Fetching package template",
"Reading package manifest",
"Reading fastly.toml",
"SUCCESS: Initialized package",
},
},
Expand All @@ -152,7 +152,7 @@ func TestInit(t *testing.T) {
},
wantOutput: []string{
"Fetching package template",
"Reading package manifest",
"Reading fastly.toml",
"SUCCESS: Initialized package",
},
},
Expand All @@ -171,7 +171,7 @@ func TestInit(t *testing.T) {
},
wantOutput: []string{
"Fetching package template",
"Reading package manifest",
"Reading fastly.toml",
"SUCCESS: Initialized package",
},
},
Expand All @@ -190,12 +190,12 @@ func TestInit(t *testing.T) {
},
wantOutput: []string{
"Fetching package template",
"Reading package manifest",
"Reading fastly.toml",
"SUCCESS: Initialized package",
},
},
{
name: "with existing package manifest",
name: "with existing fastly.toml",
args: args("compute init --auto-yes"), // --force will ignore a directory that isn't empty
configFile: config.File{
StarterKits: config.StarterKitLanguages{
Expand All @@ -210,12 +210,12 @@ func TestInit(t *testing.T) {
description = "test"
authors = ["[email protected]"]`,
wantOutput: []string{
"Reading package manifest",
"Reading fastly.toml",
"Initializing package",
},
},
{
name: "with existing package manifest",
name: "with existing fastly.toml",
args: args("compute init --auto-yes"), // --force will ignore a directory that isn't empty
configFile: config.File{
StarterKits: config.StarterKitLanguages{
Expand All @@ -230,7 +230,7 @@ func TestInit(t *testing.T) {
description = "test"
authors = ["[email protected]"]`,
wantOutput: []string{
"Reading package manifest",
"Reading fastly.toml",
"Saving manifest changes",
"Initializing package",
},
Expand All @@ -254,7 +254,7 @@ func TestInit(t *testing.T) {
wantOutput: []string{
"Author (email): Language:",
"Fetching package template",
"Reading package manifest",
"Reading fastly.toml",
"Saving manifest changes",
"Initializing package",
},
Expand Down Expand Up @@ -287,7 +287,7 @@ func TestInit(t *testing.T) {
},
wantOutput: []string{
"Fetching package template",
"Reading package manifest",
"Reading fastly.toml",
"Saving manifest changes",
"Initializing package",
},
Expand Down
4 changes: 2 additions & 2 deletions pkg/commands/service/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,12 @@ func (c *DeleteCommand) Exec(_ io.Reader, out io.Writer) error {
if source == manifest.SourceFile {
if err := c.manifest.File.Read(manifest.Filename); err != nil {
c.Globals.ErrLog.Add(err)
return fmt.Errorf("error reading package manifest: %w", err)
return fmt.Errorf("error reading fastly.toml: %w", err)
}
c.manifest.File.ServiceID = ""
if err := c.manifest.File.Write(manifest.Filename); err != nil {
c.Globals.ErrLog.Add(err)
return fmt.Errorf("error updating package manifest: %w", err)
return fmt.Errorf("error updating fastly.toml: %w", err)
}
}

Expand Down
10 changes: 5 additions & 5 deletions pkg/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var ErrNoToken = RemediationError{
Remediation: AuthRemediation,
}

// ErrNoServiceID means no --service-id or service_id package manifest value has
// ErrNoServiceID means no --service-id or service_id fastly.toml value has
// been provided.
var ErrNoServiceID = RemediationError{
Inner: fmt.Errorf("error reading service: no service ID found"),
Expand Down Expand Up @@ -70,15 +70,15 @@ var ErrNoID = RemediationError{
Remediation: IDRemediation,
}

// ErrReadingManifest means there was a problem reading the package manifest.
// ErrReadingManifest means there was a problem reading the fastly.toml.
var ErrReadingManifest = RemediationError{
Inner: fmt.Errorf("error reading package manifest"),
Inner: fmt.Errorf("error reading fastly.toml"),
Remediation: "Ensure the Fastly CLI is being run within a directory containing a fastly.toml file. " + ComputeInitRemediation,
}

// ErrParsingManifest means there was a problem unmarshalling the package manifest.
// ErrParsingManifest means there was a problem unmarshalling the fastly.toml.
var ErrParsingManifest = RemediationError{
Inner: fmt.Errorf("error parsing package manifest"),
Inner: fmt.Errorf("error parsing fastly.toml"),
Remediation: ComputeInitRemediation,
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/errors/remediation_error.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ var ConfigRemediation = strings.Join([]string{
}, " ")

// ServiceIDRemediation suggests provide a service ID via --service-id flag or
// package manifest.
// fastly.toml.
var ServiceIDRemediation = strings.Join([]string{
"Please provide one via the --service-id or --service-name flag, or by setting the FASTLY_SERVICE_ID environment variable, or within your package manifest",
"Please provide one via the --service-id or --service-name flag, or by setting the FASTLY_SERVICE_ID environment variable, or within your fastly.toml",
}, " ")

// CustomerIDRemediation suggests provide a customer ID via --customer-id flag
Expand Down
7 changes: 6 additions & 1 deletion pkg/manifest/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
// File represents all of the configuration parameters in the fastly.toml
// manifest file schema.
type File struct {
// Args is necessary to track the subcommand called (see: File.Read method).
Args []string
Authors []string `toml:"authors"`
Description string `toml:"description"`
Language string `toml:"language"`
Expand Down Expand Up @@ -67,7 +69,10 @@ func (f *File) Read(path string) (err error) {
/* #nosec */
tree, err := toml.LoadFile(path)
if err != nil {
f.logErr(err)
// IMPORTANT: Only `fastly compute` references the fastly.toml file.
if len(f.Args) > 0 && f.Args[0] == "compute" {
f.logErr(err) // only log error if user executed `compute` subcommand.
}
return err
}

Expand Down