Skip to content

Commit

Permalink
Merge branch 'master' into add-kinesis-logging-endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
kellymclaughlin committed Dec 15, 2020
2 parents 09d40e7 + 5363783 commit 3c70a40
Show file tree
Hide file tree
Showing 28 changed files with 1,985 additions and 42 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## [v0.21.0](https://github.com/fastly/cli/releases/tag/v0.21.0) (2020-12-14)

[Full Changelog](https://github.com/fastly/cli/compare/v0.20.0...v0.21.0)

**Enhancements:**

- Adds support for managing edge dictionaries [\#159](https://github.com/fastly/cli/pull/159)

## [v0.20.0](https://github.com/fastly/cli/releases/tag/v0.20.0) (2020-11-24)

[Full Changelog](https://github.com/fastly/cli/compare/v0.19.0...v0.20.0)
Expand Down
15 changes: 15 additions & 0 deletions pkg/api/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,21 @@ type Interface interface {
GetPackage(*fastly.GetPackageInput) (*fastly.Package, error)
UpdatePackage(*fastly.UpdatePackageInput) (*fastly.Package, error)

CreateDictionary(*fastly.CreateDictionaryInput) (*fastly.Dictionary, error)
GetDictionary(*fastly.GetDictionaryInput) (*fastly.Dictionary, error)
DeleteDictionary(*fastly.DeleteDictionaryInput) error
ListDictionaries(*fastly.ListDictionariesInput) ([]*fastly.Dictionary, error)
UpdateDictionary(*fastly.UpdateDictionaryInput) (*fastly.Dictionary, error)

ListDictionaryItems(*fastly.ListDictionaryItemsInput) ([]*fastly.DictionaryItem, error)
GetDictionaryItem(*fastly.GetDictionaryItemInput) (*fastly.DictionaryItem, error)
CreateDictionaryItem(*fastly.CreateDictionaryItemInput) (*fastly.DictionaryItem, error)
UpdateDictionaryItem(*fastly.UpdateDictionaryItemInput) (*fastly.DictionaryItem, error)
DeleteDictionaryItem(*fastly.DeleteDictionaryItemInput) error
BatchModifyDictionaryItems(*fastly.BatchModifyDictionaryItemsInput) error

GetDictionaryInfo(*fastly.GetDictionaryInfoInput) (*fastly.DictionaryInfo, error)

CreateBigQuery(*fastly.CreateBigQueryInput) (*fastly.BigQuery, error)
ListBigQueries(*fastly.ListBigQueriesInput) ([]*fastly.BigQuery, error)
GetBigQuery(*fastly.GetBigQueryInput) (*fastly.BigQuery, error)
Expand Down
32 changes: 32 additions & 0 deletions pkg/app/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import (
"github.com/fastly/cli/pkg/config"
"github.com/fastly/cli/pkg/configure"
"github.com/fastly/cli/pkg/domain"
"github.com/fastly/cli/pkg/edgedictionary"
"github.com/fastly/cli/pkg/edgedictionaryitem"
"github.com/fastly/cli/pkg/errors"
"github.com/fastly/cli/pkg/healthcheck"
"github.com/fastly/cli/pkg/logging"
Expand Down Expand Up @@ -157,6 +159,21 @@ func Run(args []string, env config.Environment, file config.File, configFilePath
healthcheckUpdate := healthcheck.NewUpdateCommand(healthcheckRoot.CmdClause, &globals)
healthcheckDelete := healthcheck.NewDeleteCommand(healthcheckRoot.CmdClause, &globals)

dictionaryRoot := edgedictionary.NewRootCommand(app, &globals)
dictionaryCreate := edgedictionary.NewCreateCommand(dictionaryRoot.CmdClause, &globals)
dictionaryDescribe := edgedictionary.NewDescribeCommand(dictionaryRoot.CmdClause, &globals)
dictionaryDelete := edgedictionary.NewDeleteCommand(dictionaryRoot.CmdClause, &globals)
dictionaryList := edgedictionary.NewListCommand(dictionaryRoot.CmdClause, &globals)
dictionaryUpdate := edgedictionary.NewUpdateCommand(dictionaryRoot.CmdClause, &globals)

dictionaryItemRoot := edgedictionaryitem.NewRootCommand(app, &globals)
dictionaryItemList := edgedictionaryitem.NewListCommand(dictionaryItemRoot.CmdClause, &globals)
dictionaryItemDescribe := edgedictionaryitem.NewDescribeCommand(dictionaryItemRoot.CmdClause, &globals)
dictionaryItemCreate := edgedictionaryitem.NewCreateCommand(dictionaryItemRoot.CmdClause, &globals)
dictionaryItemUpdate := edgedictionaryitem.NewUpdateCommand(dictionaryItemRoot.CmdClause, &globals)
dictionaryItemDelete := edgedictionaryitem.NewDeleteCommand(dictionaryItemRoot.CmdClause, &globals)
dictionaryItemBatchModify := edgedictionaryitem.NewBatchCommand(dictionaryItemRoot.CmdClause, &globals)

loggingRoot := logging.NewRootCommand(app, &globals)

bigQueryRoot := bigquery.NewRootCommand(loggingRoot.CmdClause, &globals)
Expand Down Expand Up @@ -389,6 +406,21 @@ func Run(args []string, env config.Environment, file config.File, configFilePath
healthcheckUpdate,
healthcheckDelete,

dictionaryRoot,
dictionaryCreate,
dictionaryDescribe,
dictionaryDelete,
dictionaryList,
dictionaryUpdate,

dictionaryItemRoot,
dictionaryItemList,
dictionaryItemDescribe,
dictionaryItemCreate,
dictionaryItemUpdate,
dictionaryItemDelete,
dictionaryItemBatchModify,

loggingRoot,

bigQueryRoot,
Expand Down
90 changes: 90 additions & 0 deletions pkg/app/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ COMMANDS
domain Manipulate Fastly service version domains
backend Manipulate Fastly service version backends
healthcheck Manipulate Fastly service version healthchecks
dictionary Manipulate Fastly edge dictionaries
dictionaryitem Manipulate Fastly edge dictionary items
logging Manipulate Fastly service version logging endpoints
stats View statistics (historical and realtime) for a Fastly
service
Expand Down Expand Up @@ -559,6 +561,94 @@ COMMANDS
--version=VERSION Number of service version
-n, --name=NAME Healthcheck name
dictionary create --version=VERSION --name=NAME [<flags>]
Create a Fastly edge dictionary on a Fastly service version
-s, --service-id=SERVICE-ID Service ID
--version=VERSION Number of service version
-n, --name=NAME Name of Dictionary
--write-only=WRITE-ONLY Whether to mark this dictionary as write-only.
Can be true or false (defaults to false)
dictionary describe --version=VERSION --name=NAME [<flags>]
Show detailed information about a Fastly edge dictionary
-s, --service-id=SERVICE-ID Service ID
--version=VERSION Number of service version
-n, --name=NAME Name of Dictionary
dictionary delete --version=VERSION --name=NAME [<flags>]
Delete a Fastly edge dictionary from a Fastly service version
-s, --service-id=SERVICE-ID Service ID
--version=VERSION Number of service version
-n, --name=NAME Name of Dictionary
dictionary list --version=VERSION [<flags>]
List all dictionaries on a Fastly service version
-s, --service-id=SERVICE-ID Service ID
--version=VERSION Number of service version
dictionary update --version=VERSION --name=NAME [<flags>]
Update name of dictionary on a Fastly service version
-s, --service-id=SERVICE-ID Service ID
--version=VERSION Number of service version
-n, --name=NAME Old name of Dictionary
--new-name=NEW-NAME New name of Dictionary
--write-only=WRITE-ONLY Whether to mark this dictionary as write-only.
Can be true or false (defaults to false)
dictionaryitem list --dictionary-id=DICTIONARY-ID [<flags>]
List items in a Fastly edge dictionary
-s, --service-id=SERVICE-ID Service ID
--dictionary-id=DICTIONARY-ID
Dictionary ID
dictionaryitem describe --dictionary-id=DICTIONARY-ID --key=KEY [<flags>]
Show detailed information about a Fastly edge dictionary item
-s, --service-id=SERVICE-ID Service ID
--dictionary-id=DICTIONARY-ID
Dictionary ID
--key=KEY Dictionary item key
dictionaryitem create --dictionary-id=DICTIONARY-ID --key=KEY --value=VALUE [<flags>]
Create a new item on a Fastly edge dictionary
-s, --service-id=SERVICE-ID Service ID
--dictionary-id=DICTIONARY-ID
Dictionary ID
--key=KEY Dictionary item key
--value=VALUE Dictionary item value
dictionaryitem update --dictionary-id=DICTIONARY-ID --key=KEY --value=VALUE [<flags>]
Update or insert an item on a Fastly edge dictionary
-s, --service-id=SERVICE-ID Service ID
--dictionary-id=DICTIONARY-ID
Dictionary ID
--key=KEY Dictionary item key
--value=VALUE Dictionary item value
dictionaryitem delete --dictionary-id=DICTIONARY-ID --key=KEY [<flags>]
Delete an item from a Fastly edge dictionary
-s, --service-id=SERVICE-ID Service ID
--dictionary-id=DICTIONARY-ID
Dictionary ID
--key=KEY Dictionary item key
dictionaryitem batchmodify --dictionary-id=DICTIONARY-ID --file=FILE [<flags>]
Update multiple items in a Fastly edge dictionary
-s, --service-id=SERVICE-ID Service ID
--dictionary-id=DICTIONARY-ID
Dictionary ID
--file=FILE Batch update json file
logging bigquery create --name=NAME --version=VERSION --project-id=PROJECT-ID --dataset=DATASET --table=TABLE --user=USER --secret-key=SECRET-KEY [<flags>]
Create a BigQuery logging endpoint on a Fastly service version
Expand Down
38 changes: 1 addition & 37 deletions pkg/configure/configure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@ package configure_test

import (
"bytes"
"crypto/rand"
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"path/filepath"
"strings"
"testing"

Expand Down Expand Up @@ -198,7 +195,7 @@ func TestConfigure(t *testing.T) {
},
} {
t.Run(testcase.name, func(t *testing.T) {
configFilePath := tempFile(t, testcase.configFileData)
configFilePath := testutil.MakeTempFile(t, testcase.configFileData)
defer os.RemoveAll(configFilePath)

var (
Expand All @@ -224,36 +221,3 @@ func TestConfigure(t *testing.T) {
})
}
}

func tempFile(t *testing.T, contents string) string {
t.Helper()

p := make([]byte, 32)
n, err := rand.Read(p)
if err != nil {
t.Fatal(err)
}

filename := filepath.Join(
os.TempDir(),
fmt.Sprintf("fastly-%x", p[:n]),
)

if contents != "" {
f, err := os.Create(filename)
if err != nil {
t.Fatal(err)
}
if _, err := fmt.Fprintln(f, contents); err != nil {
t.Fatal(err)
}
if err := f.Sync(); err != nil {
t.Fatal(err)
}
if err := f.Close(); err != nil {
t.Fatal(err)
}
}

return filename
}
65 changes: 65 additions & 0 deletions pkg/edgedictionary/create.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package edgedictionary

import (
"io"
"strconv"

"github.com/fastly/cli/pkg/common"
"github.com/fastly/cli/pkg/compute/manifest"
"github.com/fastly/cli/pkg/config"
"github.com/fastly/cli/pkg/errors"
"github.com/fastly/cli/pkg/text"
"github.com/fastly/go-fastly/v2/fastly"
)

// CreateCommand calls the Fastly API to create a service.
type CreateCommand struct {
common.Base
manifest manifest.Data
Input fastly.CreateDictionaryInput

writeOnly common.OptionalString
}

// NewCreateCommand returns a usable command registered under the parent.
func NewCreateCommand(parent common.Registerer, globals *config.Data) *CreateCommand {
var c CreateCommand
c.Globals = globals
c.manifest.File.Read(manifest.Filename)
c.CmdClause = parent.Command("create", "Create a Fastly edge dictionary on a Fastly service version")
c.CmdClause.Flag("service-id", "Service ID").Short('s').StringVar(&c.manifest.Flag.ServiceID)
c.CmdClause.Flag("version", "Number of service version").Required().IntVar(&c.Input.ServiceVersion)
c.CmdClause.Flag("name", "Name of Dictionary").Short('n').Required().StringVar(&c.Input.Name)
c.CmdClause.Flag("write-only", "Whether to mark this dictionary as write-only. Can be true or false (defaults to false)").Action(c.writeOnly.Set).StringVar(&c.writeOnly.Value)
return &c
}

// Exec invokes the application logic for the command.
func (c *CreateCommand) Exec(in io.Reader, out io.Writer) error {
serviceID, source := c.manifest.ServiceID()
if source == manifest.SourceUndefined {
return errors.ErrNoServiceID
}
c.Input.ServiceID = serviceID

if c.writeOnly.WasSet {
writeOnly, err := strconv.ParseBool(c.writeOnly.Value)
if err != nil {
return err
}
c.Input.WriteOnly = fastly.Compatibool(writeOnly)
}

d, err := c.Globals.Client.CreateDictionary(&c.Input)
if err != nil {
return err
}

var writeOnlyOutput string
if d.WriteOnly {
writeOnlyOutput = "as write-only "
}

text.Success(out, "Created dictionary %s %s(service %s version %d)", d.Name, writeOnlyOutput, d.ServiceID, d.ServiceVersion)
return nil
}
48 changes: 48 additions & 0 deletions pkg/edgedictionary/delete.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package edgedictionary

import (
"io"

"github.com/fastly/cli/pkg/common"
"github.com/fastly/cli/pkg/compute/manifest"
"github.com/fastly/cli/pkg/config"
"github.com/fastly/cli/pkg/errors"
"github.com/fastly/cli/pkg/text"
"github.com/fastly/go-fastly/v2/fastly"
)

// DeleteCommand calls the Fastly API to delete a service.
type DeleteCommand struct {
common.Base
manifest manifest.Data
Input fastly.DeleteDictionaryInput
}

// NewDeleteCommand returns a usable command registered under the parent.
func NewDeleteCommand(parent common.Registerer, globals *config.Data) *DeleteCommand {
var c DeleteCommand
c.Globals = globals
c.manifest.File.Read(manifest.Filename)
c.CmdClause = parent.Command("delete", "Delete a Fastly edge dictionary from a Fastly service version")
c.CmdClause.Flag("service-id", "Service ID").Short('s').StringVar(&c.manifest.Flag.ServiceID)
c.CmdClause.Flag("version", "Number of service version").Required().IntVar(&c.Input.ServiceVersion)
c.CmdClause.Flag("name", "Name of Dictionary").Short('n').Required().StringVar(&c.Input.Name)
return &c
}

// Exec invokes the application logic for the command.
func (c *DeleteCommand) Exec(in io.Reader, out io.Writer) error {
serviceID, source := c.manifest.ServiceID()
if source == manifest.SourceUndefined {
return errors.ErrNoServiceID
}
c.Input.ServiceID = serviceID

err := c.Globals.Client.DeleteDictionary(&c.Input)
if err != nil {
return err
}

text.Success(out, "Deleted dictionary %s (service %s version %d)", c.Input.Name, c.Input.ServiceID, c.Input.ServiceVersion)
return nil
}

0 comments on commit 3c70a40

Please sign in to comment.