Skip to content

Commit

Permalink
Move object-store-keys into its own package
Browse files Browse the repository at this point in the history
Rename things accordingly.

Requested by @Integralist.
  • Loading branch information
fgsch committed Feb 6, 2023
1 parent b12b3f1 commit 06cc805
Show file tree
Hide file tree
Showing 13 changed files with 93 additions and 89 deletions.
19 changes: 10 additions & 9 deletions pkg/app/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import (
"github.com/fastly/cli/pkg/commands/logging/syslog"
"github.com/fastly/cli/pkg/commands/logtail"
"github.com/fastly/cli/pkg/commands/objectstore"
"github.com/fastly/cli/pkg/commands/objectstorekeys"
"github.com/fastly/cli/pkg/commands/pop"
"github.com/fastly/cli/pkg/commands/profile"
"github.com/fastly/cli/pkg/commands/purge"
Expand Down Expand Up @@ -298,15 +299,15 @@ func defineCommands(
loggingSyslogList := syslog.NewListCommand(loggingSyslogCmdRoot.CmdClause, globals, data)
loggingSyslogUpdate := syslog.NewUpdateCommand(loggingSyslogCmdRoot.CmdClause, globals, data)
objectstoreCmdRoot := objectstore.NewRootCommand(app, globals)
objectstoreCreate := objectstore.NewCreateStoreCommand(objectstoreCmdRoot.CmdClause, globals, data)
objectstoreDelete := objectstore.NewDeleteStoreCommand(objectstoreCmdRoot.CmdClause, globals, data)
objectstoreDescribe := objectstore.NewDescribeStoreCommand(objectstoreCmdRoot.CmdClause, globals, data)
objectstoreList := objectstore.NewListStoreCommand(objectstoreCmdRoot.CmdClause, globals, data)
objectstoreKeysCmdRoot := objectstore.NewKeysRootCommand(app, globals)
objectstoreDeleteKey := objectstore.NewDeleteKeyCommand(objectstoreKeysCmdRoot.CmdClause, globals, data)
objectstoreGetKey := objectstore.NewGetKeyCommand(objectstoreKeysCmdRoot.CmdClause, globals, data)
objectstoreInsertKey := objectstore.NewInsertKeyCommand(objectstoreKeysCmdRoot.CmdClause, globals, data)
objectstoreListKeys := objectstore.NewListKeysCommand(objectstoreKeysCmdRoot.CmdClause, globals, data)
objectstoreCreate := objectstore.NewCreateCommand(objectstoreCmdRoot.CmdClause, globals, data)
objectstoreDelete := objectstore.NewDeleteCommand(objectstoreCmdRoot.CmdClause, globals, data)
objectstoreDescribe := objectstore.NewDescribeCommand(objectstoreCmdRoot.CmdClause, globals, data)
objectstoreList := objectstore.NewListCommand(objectstoreCmdRoot.CmdClause, globals, data)
objectstoreKeysCmdRoot := objectstorekeys.NewRootCommand(app, globals)
objectstoreDeleteKey := objectstorekeys.NewDeleteCommand(objectstoreKeysCmdRoot.CmdClause, globals, data)
objectstoreGetKey := objectstorekeys.NewGetCommand(objectstoreKeysCmdRoot.CmdClause, globals, data)
objectstoreInsertKey := objectstorekeys.NewInsertCommand(objectstoreKeysCmdRoot.CmdClause, globals, data)
objectstoreListKeys := objectstorekeys.NewListCommand(objectstoreKeysCmdRoot.CmdClause, globals, data)
popCmdRoot := pop.NewRootCommand(app, globals)
profileCmdRoot := profile.NewRootCommand(app, globals)
profileCreate := profile.NewCreateCommand(profileCmdRoot.CmdClause, profile.APIClientFactory(opts.APIClient), globals)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ import (
"github.com/fastly/go-fastly/v7/fastly"
)

// CreateStoreCommand calls the Fastly API to create an object store.
type CreateStoreCommand struct {
// CreateCommand calls the Fastly API to create an object store.
type CreateCommand struct {
cmd.Base
manifest manifest.Data
Input fastly.CreateObjectStoreInput
}

// NewCreateStoreCommand returns a usable command registered under the parent.
func NewCreateStoreCommand(parent cmd.Registerer, globals *config.Data, data manifest.Data) *CreateStoreCommand {
c := CreateStoreCommand{
// NewCreateCommand returns a usable command registered under the parent.
func NewCreateCommand(parent cmd.Registerer, globals *config.Data, data manifest.Data) *CreateCommand {
c := CreateCommand{
Base: cmd.Base{
Globals: globals,
},
Expand All @@ -31,7 +31,7 @@ func NewCreateStoreCommand(parent cmd.Registerer, globals *config.Data, data man
}

// Exec invokes the application logic for the command.
func (c *CreateStoreCommand) Exec(_ io.Reader, out io.Writer) error {
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ import (
"github.com/fastly/go-fastly/v7/fastly"
)

// DeleteStoreCommand calls the Fastly API to delete an object store.
type DeleteStoreCommand struct {
// DeleteCommand calls the Fastly API to delete an object store.
type DeleteCommand struct {
cmd.Base
manifest manifest.Data
Input fastly.DeleteObjectStoreInput
}

// NewDeleteStoreCommand returns a usable command registered under the parent.
func NewDeleteStoreCommand(parent cmd.Registerer, globals *config.Data, data manifest.Data) *DeleteStoreCommand {
c := DeleteStoreCommand{
// NewDeleteCommand returns a usable command registered under the parent.
func NewDeleteCommand(parent cmd.Registerer, globals *config.Data, data manifest.Data) *DeleteCommand {
c := DeleteCommand{
Base: cmd.Base{
Globals: globals,
},
Expand All @@ -31,7 +31,7 @@ func NewDeleteStoreCommand(parent cmd.Registerer, globals *config.Data, data man
}

// Exec invokes the application logic for the command.
func (c *DeleteStoreCommand) Exec(_ io.Reader, out io.Writer) error {
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ import (
"github.com/fastly/go-fastly/v7/fastly"
)

// DescribeStoreCommand calls the Fastly API to fetch the value of a key from an object store.
type DescribeStoreCommand struct {
// DescribeCommand calls the Fastly API to fetch the value of a key from an object store.
type DescribeCommand struct {
cmd.Base
json bool
manifest manifest.Data
Input fastly.GetObjectStoreInput
}

// NewDescribeStoreCommand returns a usable command registered under the parent.
func NewDescribeStoreCommand(parent cmd.Registerer, globals *config.Data, data manifest.Data) *DescribeStoreCommand {
c := DescribeStoreCommand{
// NewDescribeCommand returns a usable command registered under the parent.
func NewDescribeCommand(parent cmd.Registerer, globals *config.Data, data manifest.Data) *DescribeCommand {
c := DescribeCommand{
Base: cmd.Base{
Globals: globals,
},
Expand All @@ -44,7 +44,7 @@ func NewDescribeStoreCommand(parent cmd.Registerer, globals *config.Data, data m
}

// Exec invokes the application logic for the command.
func (c *DescribeStoreCommand) Exec(_ io.Reader, out io.Writer) error {
func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error {
if c.Globals.Verbose() && c.json {
return fsterr.ErrInvalidVerboseJSONCombo
}
Expand Down
12 changes: 6 additions & 6 deletions pkg/commands/objectstore/liststore.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ import (
"github.com/fastly/go-fastly/v7/fastly"
)

// ListStoreCommand calls the Fastly API to list the available object stores.
type ListStoreCommand struct {
// ListCommand calls the Fastly API to list the available object stores.
type ListCommand struct {
cmd.Base
json bool
manifest manifest.Data
Input fastly.ListObjectStoresInput
}

// NewListStoreCommand returns a usable command registered under the parent.
func NewListStoreCommand(parent cmd.Registerer, globals *config.Data, data manifest.Data) *ListStoreCommand {
c := ListStoreCommand{
// NewListCommand returns a usable command registered under the parent.
func NewListCommand(parent cmd.Registerer, globals *config.Data, data manifest.Data) *ListCommand {
c := ListCommand{
Base: cmd.Base{
Globals: globals,
},
Expand All @@ -43,7 +43,7 @@ func NewListStoreCommand(parent cmd.Registerer, globals *config.Data, data manif
}

// Exec invokes the application logic for the command.
func (c *ListStoreCommand) Exec(_ io.Reader, out io.Writer) error {
func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error {
if c.Globals.Verbose() && c.json {
return fsterr.ErrInvalidVerboseJSONCombo
}
Expand Down
File renamed without changes.
28 changes: 0 additions & 28 deletions pkg/commands/objectstore/root_keys.go

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package objectstore
package objectstorekeys

import (
"io"
Expand All @@ -10,16 +10,16 @@ import (
"github.com/fastly/go-fastly/v7/fastly"
)

// DeleteKeyCommand calls the Fastly API to delete an object store.
type DeleteKeyCommand struct {
// DeleteCommand calls the Fastly API to delete an object store.
type DeleteCommand struct {
cmd.Base
manifest manifest.Data
Input fastly.DeleteObjectStoreKeyInput
}

// NewDeleteKeyCommand returns a usable command registered under the parent.
func NewDeleteKeyCommand(parent cmd.Registerer, globals *config.Data, data manifest.Data) *DeleteKeyCommand {
c := DeleteKeyCommand{
// NewDeleteCommand returns a usable command registered under the parent.
func NewDeleteCommand(parent cmd.Registerer, globals *config.Data, data manifest.Data) *DeleteCommand {
c := DeleteCommand{
Base: cmd.Base{
Globals: globals,
},
Expand All @@ -32,7 +32,7 @@ func NewDeleteKeyCommand(parent cmd.Registerer, globals *config.Data, data manif
}

// Exec invokes the application logic for the command.
func (c *DeleteKeyCommand) Exec(_ io.Reader, out io.Writer) error {
func (c *DeleteCommand) Exec(_ io.Reader, out io.Writer) error {
err := c.Globals.APIClient.DeleteObjectStoreKey(&c.Input)
if err != nil {
c.Globals.ErrLog.Add(err)
Expand Down
3 changes: 3 additions & 0 deletions pkg/commands/objectstorekeys/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Package objectstorekeys contains commands to inspect and manipulate Fastly edge
// object stores keys.
package objectstorekeys
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package objectstore
package objectstorekeys

import (
"io"
Expand All @@ -11,17 +11,17 @@ import (
"github.com/fastly/go-fastly/v7/fastly"
)

// GetKeyCommand calls the Fastly API to fetch the value of a key from an object store.
type GetKeyCommand struct {
// GetCommand calls the Fastly API to fetch the value of a key from an object store.
type GetCommand struct {
cmd.Base
json bool
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 {
c := GetKeyCommand{
// NewGetCommand returns a usable command registered under the parent.
func NewGetCommand(parent cmd.Registerer, globals *config.Data, data manifest.Data) *GetCommand {
c := GetCommand{
Base: cmd.Base{
Globals: globals,
},
Expand All @@ -43,7 +43,7 @@ func NewGetKeyCommand(parent cmd.Registerer, globals *config.Data, data manifest
}

// Exec invokes the application logic for the command.
func (c *GetKeyCommand) Exec(_ io.Reader, out io.Writer) error {
func (c *GetCommand) Exec(_ io.Reader, out io.Writer) error {
if c.Globals.Verbose() && c.json {
return fsterr.ErrInvalidVerboseJSONCombo
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package objectstore
package objectstorekeys

import (
"io"
Expand All @@ -10,16 +10,16 @@ import (
"github.com/fastly/go-fastly/v7/fastly"
)

// InsertKeyCommand calls the Fastly API to insert a key into an object store.
type InsertKeyCommand struct {
// InsertCommand calls the Fastly API to insert a key into an object store.
type InsertCommand 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 {
c := InsertKeyCommand{
// NewInsertCommand returns a usable command registered under the parent.
func NewInsertCommand(parent cmd.Registerer, globals *config.Data, data manifest.Data) *InsertCommand {
c := InsertCommand{
Base: cmd.Base{
Globals: globals,
},
Expand All @@ -33,7 +33,7 @@ func NewInsertKeyCommand(parent cmd.Registerer, globals *config.Data, data manif
}

// Exec invokes the application logic for the command.
func (c *InsertKeyCommand) Exec(_ io.Reader, out io.Writer) error {
func (c *InsertCommand) Exec(_ io.Reader, out io.Writer) error {
err := c.Globals.APIClient.InsertObjectStoreKey(&c.Input)
if err != nil {
c.Globals.ErrLog.Add(err)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package objectstore
package objectstorekeys

import (
"encoding/json"
Expand All @@ -13,17 +13,17 @@ import (
"github.com/fastly/go-fastly/v7/fastly"
)

// ListKeysCommand calls the Fastly API to list the keys for a given object store.
type ListKeysCommand struct {
// ListCommand calls the Fastly API to list the keys for a given object store.
type ListCommand struct {
cmd.Base
json bool
manifest manifest.Data
Input fastly.ListObjectStoreKeysInput
}

// NewListKeysCommand returns a usable command registered under the parent.
func NewListKeysCommand(parent cmd.Registerer, globals *config.Data, data manifest.Data) *ListKeysCommand {
c := ListKeysCommand{
// NewListCommand returns a usable command registered under the parent.
func NewListCommand(parent cmd.Registerer, globals *config.Data, data manifest.Data) *ListCommand {
c := ListCommand{
Base: cmd.Base{
Globals: globals,
},
Expand All @@ -43,7 +43,7 @@ func NewListKeysCommand(parent cmd.Registerer, globals *config.Data, data manife
}

// Exec invokes the application logic for the command.
func (c *ListKeysCommand) Exec(_ io.Reader, out io.Writer) error {
func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error {
if c.Globals.Verbose() && c.json {
return fsterr.ErrInvalidVerboseJSONCombo
}
Expand Down
28 changes: 28 additions & 0 deletions pkg/commands/objectstorekeys/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package objectstorekeys

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("object-store-keys", "Manipulate Fastly Object Store keys")
return &c
}

// Exec implements the command interface.
func (c *RootCommand) Exec(_ io.Reader, _ io.Writer) error {
panic("unreachable")
}

0 comments on commit 06cc805

Please sign in to comment.