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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ require (
)

require (
github.com/fastly/go-fastly/v7 v7.0.0
github.com/fastly/go-fastly/v7 v7.1.0
github.com/kennygrant/sanitize v1.2.4
github.com/mholt/archiver v3.1.1+incompatible
github.com/otiai10/copy v1.9.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ github.com/dsnet/compress v0.0.2-0.20210315054119-f66993602bf5/go.mod h1:qssHWj6
github.com/dsnet/golib v0.0.0-20171103203638-1ea166775780/go.mod h1:Lj+Z9rebOhdfkVLjJ8T6VcRQv3SXugXy999NBtR9aFY=
github.com/dustinkirkland/golang-petname v0.0.0-20191129215211-8e5a1ed0cff0 h1:90Ly+6UfUypEF6vvvW5rQIv9opIL8CbmW9FT20LDQoY=
github.com/dustinkirkland/golang-petname v0.0.0-20191129215211-8e5a1ed0cff0/go.mod h1:V+Qd57rJe8gd4eiGzZyg4h54VLHmYVVw54iMnlAMrF8=
github.com/fastly/go-fastly/v7 v7.0.0 h1:Qz6AHosQtSbp8u3aQyGruXNFF/yAqvvjaUCNvTM1XS4=
github.com/fastly/go-fastly/v7 v7.0.0/go.mod h1:WdssHSSIe41/a5juIJagw8MCTA9m7xQ1TVLRcBQQuS8=
github.com/fastly/go-fastly/v7 v7.1.0 h1:Xrx4WvFEslI7Ry8KXgTk7OPKFe4VU2aDULSPlSmIzTU=
github.com/fastly/go-fastly/v7 v7.1.0/go.mod h1:WdssHSSIe41/a5juIJagw8MCTA9m7xQ1TVLRcBQQuS8=
github.com/fastly/kingpin v2.1.12-0.20191105091915-95d230a53780+incompatible h1:FhrXlfhgGCS+uc6YwyiFUt04alnjpoX7vgDKJxS6Qbk=
github.com/fastly/kingpin v2.1.12-0.20191105091915-95d230a53780+incompatible/go.mod h1:U8UynVoU1SQaqD2I4ZqgYd5lx3A1ipQYn4aSt2Y5h6c=
github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w=
Expand Down
2 changes: 2 additions & 0 deletions pkg/api/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,8 @@ type Interface interface {
ListObjectStoreKeys(i *fastly.ListObjectStoreKeysInput) (*fastly.ListObjectStoreKeysResponse, error)
GetObjectStoreKey(i *fastly.GetObjectStoreKeyInput) (string, error)
InsertObjectStoreKey(i *fastly.InsertObjectStoreKeyInput) error

CreateResource(i *fastly.CreateResourceInput) (*fastly.Resource, error)
}

// RealtimeStatsInterface is the subset of go-fastly's realtime stats API used here.
Expand Down
4 changes: 4 additions & 0 deletions pkg/commands/compute/compute_mocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ func createObjectStoreItemOK(i *fastly.InsertObjectStoreKeyInput) error {
return nil
}

func createResourceOK(i *fastly.CreateResourceInput) (*fastly.Resource, error) {
return nil, nil
}

func getPackageOk(i *fastly.GetPackageInput) (*fastly.Package, error) {
return &fastly.Package{ServiceID: i.ServiceID, ServiceVersion: i.ServiceVersion}, nil
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/commands/compute/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ func (c *DeployCommand) Exec(in io.Reader, out io.Writer) (err error) {
APIClient: apiClient,
AcceptDefaults: c.Globals.Flag.AcceptDefaults,
NonInteractive: c.Globals.Flag.NonInteractive,
ServiceID: serviceID,
ServiceVersion: serviceVersion.Number,
Setup: c.Manifest.File.Setup.ObjectStores,
Stdin: in,
Stdout: out,
Expand Down
3 changes: 3 additions & 0 deletions pkg/commands/compute/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1317,6 +1317,7 @@ func TestDeploy(t *testing.T) {
CreateBackendFn: createBackendOK,
CreateObjectStoreFn: createObjectStoreOK,
InsertObjectStoreKeyFn: createObjectStoreItemOK,
CreateResourceFn: createResourceOK,
CreateDomainFn: createDomainOK,
CreateServiceFn: createServiceOK,
GetPackageFn: getPackageOk,
Expand Down Expand Up @@ -1363,6 +1364,7 @@ func TestDeploy(t *testing.T) {
CreateBackendFn: createBackendOK,
CreateObjectStoreFn: createObjectStoreOK,
InsertObjectStoreKeyFn: createObjectStoreItemOK,
CreateResourceFn: createResourceOK,
CreateDomainFn: createDomainOK,
CreateServiceFn: createServiceOK,
GetPackageFn: getPackageOk,
Expand Down Expand Up @@ -1406,6 +1408,7 @@ func TestDeploy(t *testing.T) {
CreateBackendFn: createBackendOK,
CreateObjectStoreFn: createObjectStoreOK,
InsertObjectStoreKeyFn: createObjectStoreItemOK,
CreateResourceFn: createResourceOK,
CreateDomainFn: createDomainOK,
CreateServiceFn: createServiceOK,
GetPackageFn: getPackageOk,
Expand Down
24 changes: 19 additions & 5 deletions pkg/commands/compute/setup/object_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/fastly/go-fastly/v7/fastly"
)

// ObjectStores represents the service state related to dictionaries defined
// ObjectStores represents the service state related to object stores defined
// within the fastly.toml [setup] configuration.
//
// NOTE: It implements the setup.Interface interface.
Expand All @@ -21,6 +21,8 @@ type ObjectStores struct {
AcceptDefaults bool
NonInteractive bool
Progress text.Progress
ServiceID string
ServiceVersion int
Setup map[string]*manifest.SetupObjectStore
Stdin io.Reader
Stdout io.Writer
Expand All @@ -31,8 +33,6 @@ type ObjectStores struct {

// ObjectStore represents the configuration parameters for creating an
// object store via the API client.
//
// NOTE: WriteOnly (i.e. private) dictionaries not supported.
type ObjectStore struct {
Name string
Items []ObjectStoreItem
Expand Down Expand Up @@ -115,7 +115,7 @@ func (d *ObjectStores) Create() error {
for _, objectStore := range d.required {
d.Progress.Step(fmt.Sprintf("Creating object store '%s'...", objectStore.Name))

dict, err := d.APIClient.CreateObjectStore(&fastly.CreateObjectStoreInput{
store, err := d.APIClient.CreateObjectStore(&fastly.CreateObjectStoreInput{
Name: objectStore.Name,
})
if err != nil {
Expand All @@ -128,7 +128,7 @@ func (d *ObjectStores) Create() error {
d.Progress.Step(fmt.Sprintf("Creating object store key '%s'...", item.Key))

err := d.APIClient.InsertObjectStoreKey(&fastly.InsertObjectStoreKeyInput{
ID: dict.ID,
ID: store.ID,
Key: item.Key,
Value: item.Value,
})
Expand All @@ -138,6 +138,20 @@ func (d *ObjectStores) Create() error {
}
}
}

d.Progress.Step(fmt.Sprintf("Creating resource link between service and object store '%s'...", objectStore.Name))

// IMPORTANT: We need to link the object store to the C@E Service.
_, err = d.APIClient.CreateResource(&fastly.CreateResourceInput{
ServiceID: d.ServiceID,
ServiceVersion: d.ServiceVersion,
Name: fastly.String(store.Name),
ResourceID: fastly.String(store.ID),
})
if err != nil {
d.Progress.Fail()
return fmt.Errorf("error creating resource link between the service '%s' and the object store '%s': %w", d.ServiceID, store.Name, err)
}
}

return nil
Expand Down
7 changes: 7 additions & 0 deletions pkg/mock/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,8 @@ type API struct {
ListObjectStoreKeysFn func(i *fastly.ListObjectStoreKeysInput) (*fastly.ListObjectStoreKeysResponse, error)
GetObjectStoreKeyFn func(i *fastly.GetObjectStoreKeyInput) (string, error)
InsertObjectStoreKeyFn func(i *fastly.InsertObjectStoreKeyInput) error

CreateResourceFn func(i *fastly.CreateResourceInput) (*fastly.Resource, error)
}

// AllDatacenters implements Interface.
Expand Down Expand Up @@ -1646,3 +1648,8 @@ func (m API) GetObjectStoreKey(i *fastly.GetObjectStoreKeyInput) (string, error)
func (m API) InsertObjectStoreKey(i *fastly.InsertObjectStoreKeyInput) error {
return m.InsertObjectStoreKeyFn(i)
}

// CreateResourceFn implements Interface.
func (m API) CreateResource(i *fastly.CreateResourceInput) (*fastly.Resource, error) {
return m.CreateResourceFn(i)
}