Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pkg/api/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,12 @@ type Interface interface {
ListNewRelic(i *fastly.ListNewRelicInput) ([]*fastly.NewRelic, error)
UpdateNewRelic(i *fastly.UpdateNewRelicInput) (*fastly.NewRelic, error)

CreateNewRelicOTLP(i *fastly.CreateNewRelicOTLPInput) (*fastly.NewRelicOTLP, error)
DeleteNewRelicOTLP(i *fastly.DeleteNewRelicOTLPInput) error
GetNewRelicOTLP(i *fastly.GetNewRelicOTLPInput) (*fastly.NewRelicOTLP, error)
ListNewRelicOTLP(i *fastly.ListNewRelicOTLPInput) ([]*fastly.NewRelicOTLP, error)
UpdateNewRelicOTLP(i *fastly.UpdateNewRelicOTLPInput) (*fastly.NewRelicOTLP, error)

CreateUser(i *fastly.CreateUserInput) (*fastly.User, error)
DeleteUser(i *fastly.DeleteUserInput) error
GetCurrentUser() (*fastly.User, error)
Expand Down
13 changes: 13 additions & 0 deletions pkg/app/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"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/newrelicotlp"
"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 @@ -272,6 +273,12 @@ func defineCommands(
loggingNewRelicDescribe := newrelic.NewDescribeCommand(loggingNewRelicCmdRoot.CmdClause, g, m)
loggingNewRelicList := newrelic.NewListCommand(loggingNewRelicCmdRoot.CmdClause, g, m)
loggingNewRelicUpdate := newrelic.NewUpdateCommand(loggingNewRelicCmdRoot.CmdClause, g, m)
loggingNewRelicOTLPCmdRoot := newrelicotlp.NewRootCommand(loggingCmdRoot.CmdClause, g)
loggingNewRelicOTLPCreate := newrelicotlp.NewCreateCommand(loggingNewRelicOTLPCmdRoot.CmdClause, g, m)
loggingNewRelicOTLPDelete := newrelicotlp.NewDeleteCommand(loggingNewRelicOTLPCmdRoot.CmdClause, g, m)
loggingNewRelicOTLPDescribe := newrelicotlp.NewDescribeCommand(loggingNewRelicOTLPCmdRoot.CmdClause, g, m)
loggingNewRelicOTLPList := newrelicotlp.NewListCommand(loggingNewRelicOTLPCmdRoot.CmdClause, g, m)
loggingNewRelicOTLPUpdate := newrelicotlp.NewUpdateCommand(loggingNewRelicOTLPCmdRoot.CmdClause, g, m)
loggingOpenstackCmdRoot := openstack.NewRootCommand(loggingCmdRoot.CmdClause, g)
loggingOpenstackCreate := openstack.NewCreateCommand(loggingOpenstackCmdRoot.CmdClause, g, m)
loggingOpenstackDelete := openstack.NewDeleteCommand(loggingOpenstackCmdRoot.CmdClause, g, m)
Expand Down Expand Up @@ -622,6 +629,12 @@ func defineCommands(
loggingNewRelicDescribe,
loggingNewRelicList,
loggingNewRelicUpdate,
loggingNewRelicOTLPCmdRoot,
loggingNewRelicOTLPCreate,
loggingNewRelicOTLPDelete,
loggingNewRelicOTLPDescribe,
loggingNewRelicOTLPList,
loggingNewRelicOTLPUpdate,
loggingOpenstackCmdRoot,
loggingOpenstackCreate,
loggingOpenstackDelete,
Expand Down
155 changes: 155 additions & 0 deletions pkg/commands/logging/newrelicotlp/create.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
package newrelicotlp

import (
"io"

"github.com/fastly/cli/pkg/cmd"
"github.com/fastly/cli/pkg/commands/logging/common"
"github.com/fastly/cli/pkg/errors"
"github.com/fastly/cli/pkg/global"
"github.com/fastly/cli/pkg/manifest"
"github.com/fastly/cli/pkg/text"
"github.com/fastly/go-fastly/v8/fastly"
)

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

// Required.
serviceName cmd.OptionalServiceNameID
serviceVersion cmd.OptionalServiceVersion

// Optional.
autoClone cmd.OptionalAutoClone
format cmd.OptionalString
formatVersion cmd.OptionalInt
key cmd.OptionalString
name cmd.OptionalString
placement cmd.OptionalString
region cmd.OptionalString
responseCondition cmd.OptionalString
url cmd.OptionalString
}

// NewCreateCommand returns a usable command registered under the parent.
func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *CreateCommand {
c := CreateCommand{
Base: cmd.Base{
Globals: g,
},
manifest: m,
}
c.CmdClause = parent.Command("create", "Create an New Relic logging endpoint attached to the specified service version").Alias("add")

// Required.
c.CmdClause.Flag("name", "The name for the real-time logging configuration").Action(c.name.Set).StringVar(&c.name.Value)
c.RegisterFlag(cmd.StringFlagOpts{
Name: cmd.FlagVersionName,
Description: cmd.FlagVersionDesc,
Dst: &c.serviceVersion.Value,
Required: true,
})

// Optional.
c.RegisterAutoCloneFlag(cmd.AutoCloneFlagOpts{
Action: c.autoClone.Set,
Dst: &c.autoClone.Value,
})
common.Format(c.CmdClause, &c.format)
common.FormatVersion(c.CmdClause, &c.formatVersion)
c.CmdClause.Flag("key", "The Insert API key from the Account page of your New Relic account").Action(c.key.Set).StringVar(&c.key.Value)
c.CmdClause.Flag("placement", "Where in the generated VCL the logging call should be placed").Action(c.placement.Set).StringVar(&c.placement.Value)
c.CmdClause.Flag("region", "The region to which to stream logs").Action(c.region.Set).StringVar(&c.region.Value)
c.CmdClause.Flag("response-condition", "The name of an existing condition in the configured endpoint").Action(c.responseCondition.Set).StringVar(&c.responseCondition.Value)
c.CmdClause.Flag("url", "URL of the New Relic Trace Observer, if you are using New Relic Infinite Tracing").Action(c.url.Set).StringVar(&c.url.Value)
c.RegisterFlag(cmd.StringFlagOpts{
Name: cmd.FlagServiceIDName,
Description: cmd.FlagServiceIDDesc,
Dst: &c.manifest.Flag.ServiceID,
Short: 's',
})
c.RegisterFlag(cmd.StringFlagOpts{
Action: c.serviceName.Set,
Name: cmd.FlagServiceName,
Description: cmd.FlagServiceDesc,
Dst: &c.serviceName.Value,
})

return &c
}

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

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

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

text.Success(out, "Created New Relic OTLP 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.CreateNewRelicOTLPInput {
var input fastly.CreateNewRelicOTLPInput

if c.name.WasSet {
input.Name = &c.name.Value
}
input.ServiceID = serviceID
input.ServiceVersion = serviceVersion
if c.key.WasSet {
input.Token = &c.key.Value
}

if c.format.WasSet {
input.Format = &c.format.Value
}

if c.formatVersion.WasSet {
input.FormatVersion = &c.formatVersion.Value
}

if c.placement.WasSet {
input.Placement = &c.placement.Value
}

if c.region.WasSet {
input.Region = &c.region.Value
}

if c.responseCondition.WasSet {
input.ResponseCondition = &c.responseCondition.Value
}

if c.url.WasSet {
input.URL = &c.url.Value
}

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

import (
"io"

"github.com/fastly/cli/pkg/cmd"
"github.com/fastly/cli/pkg/errors"
"github.com/fastly/cli/pkg/global"
"github.com/fastly/cli/pkg/manifest"
"github.com/fastly/cli/pkg/text"
"github.com/fastly/go-fastly/v8/fastly"
)

// NewDeleteCommand returns a usable command registered under the parent.
func NewDeleteCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *DeleteCommand {
c := DeleteCommand{
Base: cmd.Base{
Globals: g,
},
manifest: m,
}
c.CmdClause = parent.Command("delete", "Delete the New Relic OTLP Logs logging object for a particular service and version").Alias("remove")

// Required.
c.CmdClause.Flag("name", "The name for the real-time logging configuration to delete").Required().StringVar(&c.name)
c.RegisterFlag(cmd.StringFlagOpts{
Name: cmd.FlagVersionName,
Description: cmd.FlagVersionDesc,
Dst: &c.serviceVersion.Value,
Required: true,
})

// Optional.
c.RegisterAutoCloneFlag(cmd.AutoCloneFlagOpts{
Action: c.autoClone.Set,
Dst: &c.autoClone.Value,
})
c.RegisterFlag(cmd.StringFlagOpts{
Name: cmd.FlagServiceIDName,
Description: cmd.FlagServiceIDDesc,
Dst: &c.manifest.Flag.ServiceID,
Short: 's',
})
c.RegisterFlag(cmd.StringFlagOpts{
Action: c.serviceName.Set,
Name: cmd.FlagServiceName,
Description: cmd.FlagServiceDesc,
Dst: &c.serviceName.Value,
})

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
serviceName cmd.OptionalServiceNameID
serviceVersion cmd.OptionalServiceVersion
}

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

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

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

text.Success(out, "Deleted New Relic OTLP 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.DeleteNewRelicOTLPInput {
var input fastly.DeleteNewRelicOTLPInput

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

return &input
}
Loading