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
34 changes: 34 additions & 0 deletions pkg/commands/compute/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,7 @@ type setupObjects struct {
backends *setup.Backends
configStores *setup.ConfigStores
loggers *setup.Loggers
objectStores *setup.KVStores
kvStores *setup.KVStores
secretStores *setup.SecretStores
}
Expand Down Expand Up @@ -929,6 +930,17 @@ func constructSetupObjects(
Stdout: out,
}

so.objectStores = &setup.KVStores{
APIClient: c.Globals.APIClient,
AcceptDefaults: c.Globals.Flags.AcceptDefaults,
NonInteractive: c.Globals.Flags.NonInteractive,
ServiceID: serviceID,
ServiceVersion: serviceVersion,
Setup: c.Manifest.File.Setup.ObjectStores,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're effectively aliasing [setup.object_stores] to the kv_stores implementation. Discussed internally, and it was decided this was OK to do as an interim solution.

Stdin: in,
Stdout: out,
}

so.kvStores = &setup.KVStores{
APIClient: c.Globals.APIClient,
AcceptDefaults: c.Globals.Flags.AcceptDefaults,
Expand Down Expand Up @@ -999,6 +1011,13 @@ func processSetupConfig(
_ = so.loggers.Configure()
}

if so.objectStores.Predefined() {
if err := so.objectStores.Configure(); err != nil {
errLogService(c.Globals.ErrLog, err, serviceID, serviceVersion)
return fmt.Errorf("error configuring service object stores: %w", err)
}
}

if so.kvStores.Predefined() {
if err := so.kvStores.Configure(); err != nil {
errLogService(c.Globals.ErrLog, err, serviceID, serviceVersion)
Expand Down Expand Up @@ -1045,6 +1064,7 @@ func processSetupCreation(
if newService {
so.backends.Spinner = spinner
so.configStores.Spinner = spinner
so.objectStores.Spinner = spinner
so.kvStores.Spinner = spinner
so.secretStores.Spinner = spinner

Expand All @@ -1070,6 +1090,17 @@ func processSetupCreation(
return err
}

if err := so.objectStores.Create(); err != nil {
c.Globals.ErrLog.AddWithContext(err, map[string]any{
"Accept defaults": c.Globals.Flags.AcceptDefaults,
"Auto-yes": c.Globals.Flags.AutoYes,
"Non-interactive": c.Globals.Flags.NonInteractive,
"Service ID": serviceID,
"Service Version": serviceVersion,
})
return err
}

if err := so.kvStores.Create(); err != nil {
c.Globals.ErrLog.AddWithContext(err, map[string]any{
"Accept defaults": c.Globals.Flags.AcceptDefaults,
Expand Down Expand Up @@ -1282,6 +1313,9 @@ func pingServiceURL(serviceURL string, httpClient api.HTTPClient, expectedStatus
if err != nil {
return false, 0, err
}
defer func() {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The gosec CI tool started complaining.

_ = resp.Body.Close()
}()

// We check for the user's defined status code expectation.
// Otherwise we'll default to checking for a non-500.
Expand Down
9 changes: 5 additions & 4 deletions pkg/commands/compute/setup/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import (
"net"
"strconv"

"github.com/fastly/go-fastly/v8/fastly"

"github.com/fastly/cli/pkg/api"
"github.com/fastly/cli/pkg/commands/backend"
"github.com/fastly/cli/pkg/errors"
"github.com/fastly/cli/pkg/manifest"
"github.com/fastly/cli/pkg/text"
"github.com/fastly/go-fastly/v8/fastly"
)

// Backends represents the service state related to backends defined within the
Expand Down Expand Up @@ -98,9 +99,9 @@ func (b *Backends) Create() error {
if err != nil {
if !b.isOriginless() {
b.Spinner.StopFailMessage(msg)
err := b.Spinner.StopFail()
if err != nil {
return err
spinErr := b.Spinner.StopFail()
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I discovered a bunch of these issues where the actual API error was being accidentally overridden by a separate error and so (as a user) you wouldn't see an error related to what had gone wrong.

if spinErr != nil {
return spinErr
}
}

Expand Down
21 changes: 11 additions & 10 deletions pkg/commands/compute/setup/config_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import (
"fmt"
"io"

"github.com/fastly/go-fastly/v8/fastly"

"github.com/fastly/cli/pkg/api"
"github.com/fastly/cli/pkg/errors"
"github.com/fastly/cli/pkg/manifest"
"github.com/fastly/cli/pkg/text"
"github.com/fastly/go-fastly/v8/fastly"
)

// ConfigStores represents the service state related to config stores defined
Expand Down Expand Up @@ -125,9 +126,9 @@ func (o *ConfigStores) Create() error {
})
if err != nil {
o.Spinner.StopFailMessage(msg)
err := o.Spinner.StopFail()
if err != nil {
return err
spinErr := o.Spinner.StopFail()
if spinErr != nil {
return spinErr
}
return fmt.Errorf("error creating config store: %w", err)
}
Expand All @@ -154,9 +155,9 @@ func (o *ConfigStores) Create() error {
})
if err != nil {
o.Spinner.StopFailMessage(msg)
err := o.Spinner.StopFail()
if err != nil {
return err
spinErr := o.Spinner.StopFail()
if spinErr != nil {
return spinErr
}
return fmt.Errorf("error creating config store item: %w", err)
}
Expand Down Expand Up @@ -185,9 +186,9 @@ func (o *ConfigStores) Create() error {
})
if err != nil {
o.Spinner.StopFailMessage(msg)
err := o.Spinner.StopFail()
if err != nil {
return err
spinErr := o.Spinner.StopFail()
if spinErr != nil {
return spinErr
}
return fmt.Errorf("error creating resource link between the service '%s' and the config store '%s': %w", o.ServiceID, store.Name, err)
}
Expand Down
23 changes: 12 additions & 11 deletions pkg/commands/compute/setup/kv_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import (
"fmt"
"io"

"github.com/fastly/go-fastly/v8/fastly"

"github.com/fastly/cli/pkg/api"
"github.com/fastly/cli/pkg/errors"
"github.com/fastly/cli/pkg/manifest"
"github.com/fastly/cli/pkg/text"
"github.com/fastly/go-fastly/v8/fastly"
)

// KVStores represents the service state related to kv stores defined
Expand Down Expand Up @@ -107,7 +108,7 @@ func (o *KVStores) Configure() error {
func (o *KVStores) Create() error {
if o.Spinner == nil {
return errors.RemediationError{
Inner: fmt.Errorf("internal logic error: no text.Progress configured for setup.KVStores"),
Inner: fmt.Errorf("internal logic error: no spinner configured for setup.KVStores"),
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should have been fixed in an older PR but I think a bad rebase meant this old implementation detail was left in.

Remediation: errors.BugRemediation,
}
}
Expand All @@ -125,9 +126,9 @@ func (o *KVStores) Create() error {
})
if err != nil {
o.Spinner.StopFailMessage(msg)
err := o.Spinner.StopFail()
if err != nil {
return err
spinErr := o.Spinner.StopFail()
if spinErr != nil {
return spinErr
}
return fmt.Errorf("error creating kv store: %w", err)
}
Expand All @@ -154,9 +155,9 @@ func (o *KVStores) Create() error {
})
if err != nil {
o.Spinner.StopFailMessage(msg)
err := o.Spinner.StopFail()
if err != nil {
return err
spinErr := o.Spinner.StopFail()
if spinErr != nil {
return spinErr
}
return fmt.Errorf("error creating kv store key: %w", err)
}
Expand Down Expand Up @@ -185,9 +186,9 @@ func (o *KVStores) Create() error {
})
if err != nil {
o.Spinner.StopFailMessage(msg)
err := o.Spinner.StopFail()
if err != nil {
return err
spinErr := o.Spinner.StopFail()
if spinErr != nil {
return spinErr
}
return fmt.Errorf("error creating resource link between the service '%s' and the kv store '%s': %w", o.ServiceID, store.Name, err)
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/commands/service/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import (
"fmt"
"io"

"github.com/fastly/go-fastly/v8/fastly"

"github.com/fastly/cli/pkg/cmd"
fsterr "github.com/fastly/cli/pkg/errors"
"github.com/fastly/cli/pkg/global"
"github.com/fastly/cli/pkg/text"
"github.com/fastly/cli/pkg/time"
"github.com/fastly/go-fastly/v8/fastly"
)

// ListCommand calls the Fastly API to list services.
Expand Down
2 changes: 1 addition & 1 deletion pkg/manifest/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
// manifest file schema.
type File struct {
// Args is necessary to track the subcommand called (see: File.Read method).
Args []string
Args []string `toml:"omitempty"`
Authors []string `toml:"authors"`
Description string `toml:"description"`
Language string `toml:"language"`
Expand Down
1 change: 1 addition & 0 deletions pkg/manifest/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ type Setup struct {
Backends map[string]*SetupBackend `toml:"backends,omitempty"`
ConfigStores map[string]*SetupConfigStore `toml:"config_stores,omitempty"`
Loggers map[string]*SetupLogger `toml:"log_endpoints,omitempty"`
ObjectStores map[string]*SetupKVStore `toml:"object_stores,omitempty"`
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is where we're again parsing [setup.object_stores].

KVStores map[string]*SetupKVStore `toml:"kv_stores,omitempty"`
SecretStores map[string]*SetupSecretStore `toml:"secret_stores,omitempty"`
}
Expand Down