Skip to content

Commit

Permalink
v0.35.0 (#356)
Browse files Browse the repository at this point in the history
  • Loading branch information
Integralist committed Jul 29, 2021
1 parent cbfc4e2 commit 76be35d
Show file tree
Hide file tree
Showing 12 changed files with 1,081 additions and 0 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
# Changelog

## [v0.35.0](https://github.com/fastly/cli/releases/tag/v0.35.0) (2021-07-29)

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

**Enhancements:**

- Support for Compute@Edge JS SDK (Beta) [#347](https://gthu.com/fastly/cli/pull/347)
- Implement `--override-host` and `--ssl-sni-hostname` [#352](https://github.com/fastly/cli/pull/352)
- Implement `acl` command [#350](https://github.com/fastly/cli/pull/350)
- Implement `acl-entry` command [#351](https://github.com/fastly/cli/pull/351)
- Separate command files from other logic files [#349](https://github.com/fastly/cli/pull/349)
- Log a record of errors to disk [#340](https://github.com/fastly/cli/pull/340)

**Bug fixes:**

- Fix nondeterministic flag parsing [#353](https://github.com/fastly/cli/pull/353)
- Fix `compute serve --addr` description to reference port requirement [#348](https://github.com/fastly/cli/pull/348)

## [v0.34.0](https://github.com/fastly/cli/releases/tag/v0.34.0) (2021-07-16)

[Full Changelog](https://github.com/fastly/cli/compare/v0.33.0...v0.34.0)
Expand Down
6 changes: 6 additions & 0 deletions pkg/api/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,12 @@ type Interface interface {
ListACLEntries(i *fastly.ListACLEntriesInput) ([]*fastly.ACLEntry, error)
UpdateACLEntry(i *fastly.UpdateACLEntryInput) (*fastly.ACLEntry, error)
BatchModifyACLEntries(i *fastly.BatchModifyACLEntriesInput) error

CreateNewRelic(i *fastly.CreateNewRelicInput) (*fastly.NewRelic, error)
DeleteNewRelic(i *fastly.DeleteNewRelicInput) error
GetNewRelic(i *fastly.GetNewRelicInput) (*fastly.NewRelic, error)
ListNewRelic(i *fastly.ListNewRelicInput) ([]*fastly.NewRelic, error)
UpdateNewRelic(i *fastly.UpdateNewRelicInput) (*fastly.NewRelic, error)
}

// RealtimeStatsInterface is the subset of go-fastly's realtime stats API used here.
Expand Down
13 changes: 13 additions & 0 deletions pkg/app/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (
"github.com/fastly/cli/pkg/commands/logging/logentries"
"github.com/fastly/cli/pkg/commands/logging/loggly"
"github.com/fastly/cli/pkg/commands/logging/logshuttle"
"github.com/fastly/cli/pkg/commands/logging/newrelic"
"github.com/fastly/cli/pkg/commands/logging/openstack"
"github.com/fastly/cli/pkg/commands/logging/papertrail"
"github.com/fastly/cli/pkg/commands/logging/s3"
Expand Down Expand Up @@ -299,6 +300,12 @@ func Run(opts RunOpts) error {
loggingLogshuttleDescribe := logshuttle.NewDescribeCommand(loggingLogshuttleCmdRoot.CmdClause, &globals)
loggingLogshuttleList := logshuttle.NewListCommand(loggingLogshuttleCmdRoot.CmdClause, &globals)
loggingLogshuttleUpdate := logshuttle.NewUpdateCommand(loggingLogshuttleCmdRoot.CmdClause, &globals)
loggingNewRelicCmdRoot := newrelic.NewRootCommand(loggingCmdRoot.CmdClause, &globals)
loggingNewRelicCreate := newrelic.NewCreateCommand(loggingNewRelicCmdRoot.CmdClause, &globals)
loggingNewRelicDelete := newrelic.NewDeleteCommand(loggingNewRelicCmdRoot.CmdClause, &globals)
loggingNewRelicDescribe := newrelic.NewDescribeCommand(loggingNewRelicCmdRoot.CmdClause, &globals)
loggingNewRelicList := newrelic.NewListCommand(loggingNewRelicCmdRoot.CmdClause, &globals)
loggingNewRelicUpdate := newrelic.NewUpdateCommand(loggingNewRelicCmdRoot.CmdClause, &globals)
loggingOpenstackCmdRoot := openstack.NewRootCommand(loggingCmdRoot.CmdClause, &globals)
loggingOpenstackCreate := openstack.NewCreateCommand(loggingOpenstackCmdRoot.CmdClause, &globals)
loggingOpenstackDelete := openstack.NewDeleteCommand(loggingOpenstackCmdRoot.CmdClause, &globals)
Expand Down Expand Up @@ -544,6 +551,12 @@ func Run(opts RunOpts) error {
loggingLogshuttleDescribe,
loggingLogshuttleList,
loggingLogshuttleUpdate,
loggingNewRelicCmdRoot,
loggingNewRelicCreate,
loggingNewRelicDelete,
loggingNewRelicDescribe,
loggingNewRelicList,
loggingNewRelicUpdate,
loggingOpenstackCmdRoot,
loggingOpenstackCreate,
loggingOpenstackDelete,
Expand Down
114 changes: 114 additions & 0 deletions pkg/commands/logging/newrelic/create.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package newrelic

import (
"io"

"github.com/fastly/cli/pkg/cmd"
"github.com/fastly/cli/pkg/commands/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/v3/fastly"
)

// NewCreateCommand returns a usable command registered under the parent.
func NewCreateCommand(parent cmd.Registerer, globals *config.Data) *CreateCommand {
var c CreateCommand
c.CmdClause = parent.Command("create", "Create an New Relic logging endpoint attached to the specified service version").Alias("add")
c.Globals = globals
c.manifest.File.SetOutput(c.Globals.Output)
c.manifest.File.Read(manifest.Filename)

// Required flags
c.CmdClause.Flag("key", "The Insert API key from the Account page of your New Relic account").Required().StringVar(&c.key)
c.CmdClause.Flag("name", "The name for the real-time logging configuration").Required().StringVar(&c.name)
c.RegisterServiceVersionFlag(cmd.ServiceVersionFlagOpts{
Dst: &c.serviceVersion.Value,
})

// Optional flags
c.RegisterAutoCloneFlag(cmd.AutoCloneFlagOpts{
Action: c.autoClone.Set,
Dst: &c.autoClone.Value,
})
c.CmdClause.Flag("format", "A Fastly log format string. Must produce valid JSON that New Relic Logs can ingest").StringVar(&c.format)
c.CmdClause.Flag("format-version", "The version of the custom logging format used for the configured endpoint").UintVar(&c.formatVersion)
c.CmdClause.Flag("placement", "Where in the generated VCL the logging call should be placed").StringVar(&c.placement)
c.CmdClause.Flag("response-condition", "The name of an existing condition in the configured endpoint").Action(c.responseCondition.Set).StringVar(&c.responseCondition.Value)
c.RegisterServiceIDFlag(&c.manifest.Flag.ServiceID)

return &c
}

// CreateCommand calls the Fastly API to create an appropriate resource.
type CreateCommand struct {
cmd.Base

autoClone cmd.OptionalAutoClone
format string
formatVersion uint
key string
manifest manifest.Data
name string
placement string
responseCondition cmd.OptionalString
serviceVersion cmd.OptionalServiceVersion
}

// Exec invokes the application logic for the command.
func (c *CreateCommand) Exec(in io.Reader, out io.Writer) error {
serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{
AutoCloneFlag: c.autoClone,
Client: c.Globals.Client,
Manifest: c.manifest,
Out: out,
ServiceVersionFlag: c.serviceVersion,
VerboseMode: c.Globals.Flag.Verbose,
})
if err != nil {
c.Globals.ErrLog.AddWithContext(err, map[string]interface{}{
"Service ID": serviceID,
"Service Version": errors.ServiceVersion(serviceVersion),
})
return err
}

input := c.constructInput(serviceID, serviceVersion.Number)

l, err := c.Globals.Client.CreateNewRelic(input)
if err != nil {
c.Globals.ErrLog.AddWithContext(err, map[string]interface{}{
"Service ID": serviceID,
"Service Version": serviceVersion.Number,
})
return err
}

text.Success(out, "Created New Relic logging endpoint '%s' (service: %s, version: %d)", l.Name, l.ServiceID, l.ServiceVersion)
return nil
}

// constructInput transforms values parsed from CLI flags into an object to be used by the API client library.
func (c *CreateCommand) constructInput(serviceID string, serviceVersion int) *fastly.CreateNewRelicInput {
var input fastly.CreateNewRelicInput

input.Name = c.name
input.ServiceID = serviceID
input.ServiceVersion = serviceVersion
input.Token = c.key

if c.format != "" {
input.Format = c.format
}
if c.formatVersion > 0 {
input.FormatVersion = c.formatVersion
}
if c.placement != "" {
input.Placement = c.placement
}
if c.responseCondition.WasSet {
input.ResponseCondition = c.responseCondition.Value
}

return &input
}
90 changes: 90 additions & 0 deletions pkg/commands/logging/newrelic/delete.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package newrelic

import (
"io"

"github.com/fastly/cli/pkg/cmd"
"github.com/fastly/cli/pkg/commands/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/v3/fastly"
)

// NewDeleteCommand returns a usable command registered under the parent.
func NewDeleteCommand(parent cmd.Registerer, globals *config.Data) *DeleteCommand {
var c DeleteCommand
c.CmdClause = parent.Command("delete", "Delete the New Relic Logs logging object for a particular service and version").Alias("remove")
c.Globals = globals
c.manifest.File.SetOutput(c.Globals.Output)
c.manifest.File.Read(manifest.Filename)

// Required flags
c.CmdClause.Flag("name", "The name for the real-time logging configuration to delete").Required().StringVar(&c.name)
c.RegisterServiceVersionFlag(cmd.ServiceVersionFlagOpts{
Dst: &c.serviceVersion.Value,
})

// Optional flags
c.RegisterAutoCloneFlag(cmd.AutoCloneFlagOpts{
Action: c.autoClone.Set,
Dst: &c.autoClone.Value,
})
c.RegisterServiceIDFlag(&c.manifest.Flag.ServiceID)

return &c
}

// DeleteCommand calls the Fastly API to delete an appropriate resource.
type DeleteCommand struct {
cmd.Base

autoClone cmd.OptionalAutoClone
manifest manifest.Data
name string
serviceVersion cmd.OptionalServiceVersion
}

// Exec invokes the application logic for the command.
func (c *DeleteCommand) Exec(in io.Reader, out io.Writer) error {
serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{
AutoCloneFlag: c.autoClone,
Client: c.Globals.Client,
Manifest: c.manifest,
Out: out,
ServiceVersionFlag: c.serviceVersion,
VerboseMode: c.Globals.Flag.Verbose,
})
if err != nil {
c.Globals.ErrLog.AddWithContext(err, map[string]interface{}{
"Service ID": serviceID,
"Service Version": errors.ServiceVersion(serviceVersion),
})
return err
}

input := c.constructInput(serviceID, serviceVersion.Number)

err = c.Globals.Client.DeleteNewRelic(input)
if err != nil {
c.Globals.ErrLog.AddWithContext(err, map[string]interface{}{
"Service ID": serviceID,
"Service Version": serviceVersion.Number,
})
return err
}

text.Success(out, "Deleted New Relic logging endpoint '%s' (service: %s, version: %d)", c.name, serviceID, serviceVersion.Number)
return nil
}

// constructInput transforms values parsed from CLI flags into an object to be used by the API client library.
func (c *DeleteCommand) constructInput(serviceID string, serviceVersion int) *fastly.DeleteNewRelicInput {
var input fastly.DeleteNewRelicInput

input.Name = c.name
input.ServiceID = serviceID
input.ServiceVersion = serviceVersion

return &input
}
107 changes: 107 additions & 0 deletions pkg/commands/logging/newrelic/describe.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package newrelic

import (
"fmt"
"io"

"github.com/fastly/cli/pkg/cmd"
"github.com/fastly/cli/pkg/commands/compute/manifest"
"github.com/fastly/cli/pkg/config"
"github.com/fastly/cli/pkg/errors"
"github.com/fastly/go-fastly/v3/fastly"
)

// NewDescribeCommand returns a usable command registered under the parent.
func NewDescribeCommand(parent cmd.Registerer, globals *config.Data) *DescribeCommand {
var c DescribeCommand
c.CmdClause = parent.Command("describe", "Get the details of a New Relic Logs logging object for a particular service and version").Alias("get")
c.Globals = globals
c.manifest.File.SetOutput(c.Globals.Output)
c.manifest.File.Read(manifest.Filename)

// Required flags
c.CmdClause.Flag("name", "The name for the real-time logging configuration").Required().StringVar(&c.name)
c.RegisterServiceVersionFlag(cmd.ServiceVersionFlagOpts{
Dst: &c.serviceVersion.Value,
})

// Optional Flags
c.RegisterServiceIDFlag(&c.manifest.Flag.ServiceID)

return &c
}

// DescribeCommand calls the Fastly API to describe an appropriate resource.
type DescribeCommand struct {
cmd.Base

manifest manifest.Data
name string
serviceVersion cmd.OptionalServiceVersion
}

// Exec invokes the application logic for the command.
func (c *DescribeCommand) Exec(in io.Reader, out io.Writer) error {
serviceID, serviceVersion, err := cmd.ServiceDetails(cmd.ServiceDetailsOpts{
AllowActiveLocked: true,
Client: c.Globals.Client,
Manifest: c.manifest,
Out: out,
ServiceVersionFlag: c.serviceVersion,
VerboseMode: c.Globals.Flag.Verbose,
})
if err != nil {
c.Globals.ErrLog.AddWithContext(err, map[string]interface{}{
"Service ID": serviceID,
"Service Version": errors.ServiceVersion(serviceVersion),
})
return err
}

input := c.constructInput(serviceID, serviceVersion.Number)

a, err := c.Globals.Client.GetNewRelic(input)
if err != nil {
c.Globals.ErrLog.AddWithContext(err, map[string]interface{}{
"Service ID": serviceID,
"Service Version": serviceVersion.Number,
})
return err
}

c.print(out, a)
return nil
}

// constructInput transforms values parsed from CLI flags into an object to be used by the API client library.
func (c *DescribeCommand) constructInput(serviceID string, serviceVersion int) *fastly.GetNewRelicInput {
var input fastly.GetNewRelicInput

input.Name = c.name
input.ServiceID = serviceID
input.ServiceVersion = serviceVersion

return &input
}

// print displays the information returned from the API.
func (c *DescribeCommand) print(out io.Writer, l *fastly.NewRelic) {
fmt.Fprintf(out, "\nService ID: %s\n", l.ServiceID)
fmt.Fprintf(out, "Service Version: %d\n\n", l.ServiceVersion)
fmt.Fprintf(out, "Name: %s\n", l.Name)
fmt.Fprintf(out, "Token: %s\n", l.Token)
fmt.Fprintf(out, "Format: %s\n", l.Format)
fmt.Fprintf(out, "Format Version: %d\n", l.FormatVersion)
fmt.Fprintf(out, "Placement: %s\n", l.Placement)
fmt.Fprintf(out, "Response Condition: %s\n\n", l.ResponseCondition)

if l.CreatedAt != nil {
fmt.Fprintf(out, "Created at: %s\n", l.CreatedAt)
}
if l.UpdatedAt != nil {
fmt.Fprintf(out, "Updated at: %s\n", l.UpdatedAt)
}
if l.DeletedAt != nil {
fmt.Fprintf(out, "Deleted at: %s\n", l.DeletedAt)
}
}
3 changes: 3 additions & 0 deletions pkg/commands/logging/newrelic/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Package newrelic contains commands to inspect and manipulate NewRelic logging
// endpoints.
package newrelic
Loading

0 comments on commit 76be35d

Please sign in to comment.