-
Notifications
You must be signed in to change notification settings - Fork 59
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
1 parent
cbfc4e2
commit 76be35d
Showing
12 changed files
with
1,081 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
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,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 | ||
} |
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,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 | ||
} |
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,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) | ||
} | ||
} |
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,3 @@ | ||
// Package newrelic contains commands to inspect and manipulate NewRelic logging | ||
// endpoints. | ||
package newrelic |
Oops, something went wrong.