-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
378 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,6 +70,7 @@ healthcheck | |
ip-list | ||
log-tail | ||
logging | ||
objectstore | ||
pops | ||
profile | ||
purge | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package objectstore | ||
|
||
import ( | ||
"io" | ||
|
||
"github.com/fastly/cli/pkg/cmd" | ||
"github.com/fastly/cli/pkg/config" | ||
"github.com/fastly/cli/pkg/manifest" | ||
"github.com/fastly/cli/pkg/text" | ||
"github.com/fastly/go-fastly/v6/fastly" | ||
) | ||
|
||
// CreateCommand calls the Fastly API to create an object store | ||
type CreateCommand struct { | ||
cmd.Base | ||
manifest manifest.Data | ||
Input fastly.CreateObjectStoreInput | ||
} | ||
|
||
// NewCreateCommand returns a usable command registered under the parent. | ||
func NewCreateCommand(parent cmd.Registerer, globals *config.Data, data manifest.Data) *CreateCommand { | ||
var c CreateCommand | ||
c.Globals = globals | ||
c.manifest = data | ||
c.CmdClause = parent.Command("create", "Create a Fastly edge config store") | ||
c.CmdClause.Flag("name", "Name of Object Store").Short('n').Required().StringVar(&c.Input.Name) | ||
return &c | ||
} | ||
|
||
// Exec invokes the application logic for the command. | ||
func (c *CreateCommand) Exec(_ io.Reader, out io.Writer) error { | ||
d, err := c.Globals.APIClient.CreateObjectStore(&c.Input) | ||
if err != nil { | ||
c.Globals.ErrLog.Add(err) | ||
return err | ||
} | ||
|
||
text.Success(out, "Created object store %s", d.Name) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package objectstore | ||
|
||
import ( | ||
"io" | ||
|
||
"github.com/fastly/cli/pkg/cmd" | ||
"github.com/fastly/cli/pkg/config" | ||
"github.com/fastly/cli/pkg/manifest" | ||
"github.com/fastly/cli/pkg/text" | ||
"github.com/fastly/go-fastly/v6/fastly" | ||
) | ||
|
||
// DeleteCommand calls the Fastly API to delete a service. | ||
type DeleteCommand struct { | ||
cmd.Base | ||
manifest manifest.Data | ||
Input fastly.DeleteObjectStoreInput | ||
} | ||
|
||
// NewDeleteCommand returns a usable command registered under the parent. | ||
func NewDeleteCommand(parent cmd.Registerer, globals *config.Data, data manifest.Data) *DeleteCommand { | ||
var c DeleteCommand | ||
c.Globals = globals | ||
c.manifest = data | ||
c.CmdClause = parent.Command("delete", "Delete a Fastly object store") | ||
c.CmdClause.Flag("id", "ID of object store").Required().StringVar(&c.Input.ID) | ||
return &c | ||
} | ||
|
||
// Exec invokes the application logic for the command. | ||
func (c *DeleteCommand) Exec(_ io.Reader, out io.Writer) error { | ||
err := c.Globals.APIClient.DeleteObjectStore(&c.Input) | ||
if err != nil { | ||
c.Globals.ErrLog.Add(err) | ||
return err | ||
} | ||
|
||
text.Success(out, "Deleted object store ID:%s", c.Input.ID) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package objectstore | ||
|
||
import ( | ||
"io" | ||
|
||
"github.com/fastly/cli/pkg/cmd" | ||
"github.com/fastly/cli/pkg/config" | ||
"github.com/fastly/cli/pkg/manifest" | ||
"github.com/fastly/cli/pkg/text" | ||
"github.com/fastly/go-fastly/v6/fastly" | ||
) | ||
|
||
// GetKeyCommand calls the Fastly API to list the available object stores | ||
type GetKeyCommand struct { | ||
cmd.Base | ||
manifest manifest.Data | ||
Input fastly.GetObjectStoreKeyInput | ||
} | ||
|
||
// NewGetKeyCommand returns a usable command registered under the parent. | ||
func NewGetKeyCommand(parent cmd.Registerer, globals *config.Data, data manifest.Data) *GetKeyCommand { | ||
var c GetKeyCommand | ||
c.Globals = globals | ||
c.manifest = data | ||
c.CmdClause = parent.Command("get", "Get Fastly edge config store key") | ||
c.CmdClause.Flag("id", "ID of object store").Required().StringVar(&c.Input.ID) | ||
c.CmdClause.Flag("k", "Key to fetch").Required().StringVar(&c.Input.Key) | ||
return &c | ||
} | ||
|
||
// Exec invokes the application logic for the command. | ||
func (c *GetKeyCommand) Exec(_ io.Reader, out io.Writer) error { | ||
value, err := c.Globals.APIClient.GetObjectStoreKey(&c.Input) | ||
if err != nil { | ||
c.Globals.ErrLog.Add(err) | ||
return err | ||
} | ||
|
||
text.PrintObjectStoreKeyValue(out, "", c.Input.Key, value) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package objectstore | ||
|
||
import ( | ||
"io" | ||
|
||
"github.com/fastly/cli/pkg/cmd" | ||
"github.com/fastly/cli/pkg/config" | ||
"github.com/fastly/cli/pkg/manifest" | ||
"github.com/fastly/cli/pkg/text" | ||
"github.com/fastly/go-fastly/v6/fastly" | ||
) | ||
|
||
// InsertKeyCommand calls the Fastly API to create an object store | ||
type InsertKeyCommand struct { | ||
cmd.Base | ||
manifest manifest.Data | ||
Input fastly.InsertObjectStoreKeyInput | ||
} | ||
|
||
// NewInsertKeyCommand returns a usable command registered under the parent. | ||
func NewInsertKeyCommand(parent cmd.Registerer, globals *config.Data, data manifest.Data) *InsertKeyCommand { | ||
var c InsertKeyCommand | ||
c.Globals = globals | ||
c.manifest = data | ||
c.CmdClause = parent.Command("insert", "Insert key/value pair into a Fastly edge config store") | ||
c.CmdClause.Flag("id", "Name of Object Store").Short('n').Required().StringVar(&c.Input.ID) | ||
c.CmdClause.Flag("k", "Key to insert").Required().StringVar(&c.Input.Key) | ||
c.CmdClause.Flag("v", "Value to insert").Required().StringVar(&c.Input.Value) | ||
|
||
return &c | ||
} | ||
|
||
// Exec invokes the application logic for the command. | ||
func (c *InsertKeyCommand) Exec(_ io.Reader, out io.Writer) error { | ||
err := c.Globals.APIClient.InsertObjectStoreKey(&c.Input) | ||
if err != nil { | ||
c.Globals.ErrLog.Add(err) | ||
return err | ||
} | ||
|
||
text.Success(out, "Inserted key %s into object store %s", c.Input.Key, c.Input.ID) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package objectstore | ||
|
||
import ( | ||
"io" | ||
|
||
"github.com/fastly/cli/pkg/cmd" | ||
"github.com/fastly/cli/pkg/config" | ||
"github.com/fastly/cli/pkg/manifest" | ||
"github.com/fastly/cli/pkg/text" | ||
"github.com/fastly/go-fastly/v6/fastly" | ||
) | ||
|
||
// KeysCommand calls the Fastly API to list the available object stores | ||
type KeysCommand struct { | ||
cmd.Base | ||
manifest manifest.Data | ||
Input fastly.ListObjectStoreKeysInput | ||
} | ||
|
||
// NewKeysCommand returns a usable command registered under the parent. | ||
func NewKeysCommand(parent cmd.Registerer, globals *config.Data, data manifest.Data) *KeysCommand { | ||
var c KeysCommand | ||
c.Globals = globals | ||
c.manifest = data | ||
c.CmdClause = parent.Command("keys", "List Fastly edge config store keys") | ||
c.CmdClause.Flag("id", "ID of object store").Required().StringVar(&c.Input.ID) | ||
return &c | ||
} | ||
|
||
// Exec invokes the application logic for the command. | ||
func (c *KeysCommand) Exec(_ io.Reader, out io.Writer) error { | ||
o, err := c.Globals.APIClient.ListObjectStoreKeys(&c.Input) | ||
if err != nil { | ||
c.Globals.ErrLog.Add(err) | ||
return err | ||
} | ||
|
||
text.PrintObjectStoreKeys(out, "", o.Data) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package objectstore | ||
|
||
import ( | ||
"io" | ||
|
||
"github.com/fastly/cli/pkg/cmd" | ||
"github.com/fastly/cli/pkg/config" | ||
"github.com/fastly/cli/pkg/manifest" | ||
"github.com/fastly/cli/pkg/text" | ||
"github.com/fastly/go-fastly/v6/fastly" | ||
) | ||
|
||
// ListCommand calls the Fastly API to list the available object stores | ||
type ListCommand struct { | ||
cmd.Base | ||
manifest manifest.Data | ||
Input fastly.ListObjectStoresInput | ||
} | ||
|
||
// NewListCommand returns a usable command registered under the parent. | ||
func NewListCommand(parent cmd.Registerer, globals *config.Data, data manifest.Data) *ListCommand { | ||
var c ListCommand | ||
c.Globals = globals | ||
c.manifest = data | ||
c.CmdClause = parent.Command("list", "List Fastly edge config stores") | ||
return &c | ||
} | ||
|
||
// Exec invokes the application logic for the command. | ||
func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error { | ||
o, err := c.Globals.APIClient.ListObjectStores(&c.Input) | ||
if err != nil { | ||
c.Globals.ErrLog.Add(err) | ||
return err | ||
} | ||
|
||
for _, o := range o.Data { | ||
// avoid gosec loop aliasing check :/ | ||
o := o | ||
text.PrintObjectStore(out, "", &o) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package objectstore | ||
|
||
import ( | ||
"io" | ||
|
||
"github.com/fastly/cli/pkg/cmd" | ||
"github.com/fastly/cli/pkg/config" | ||
) | ||
|
||
// RootCommand is the parent command for all subcommands in this package. | ||
// It should be installed under the primary root command. | ||
type RootCommand struct { | ||
cmd.Base | ||
// no flags | ||
} | ||
|
||
// NewRootCommand returns a new command registered in the parent. | ||
func NewRootCommand(parent cmd.Registerer, globals *config.Data) *RootCommand { | ||
var c RootCommand | ||
c.Globals = globals | ||
c.CmdClause = parent.Command("objectstore", "Manipulate Fastly object stores") | ||
return &c | ||
} | ||
|
||
// Exec implements the command interface. | ||
func (c *RootCommand) Exec(_ io.Reader, _ io.Writer) error { | ||
panic("unreachable") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.