Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds Scalyr logging endpoint support #73

Merged
merged 1 commit into from
May 19, 2020
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 @@ -106,6 +106,12 @@ type Interface interface {
UpdateSplunk(*fastly.UpdateSplunkInput) (*fastly.Splunk, error)
DeleteSplunk(*fastly.DeleteSplunkInput) error

CreateScalyr(*fastly.CreateScalyrInput) (*fastly.Scalyr, error)
ListScalyrs(*fastly.ListScalyrsInput) ([]*fastly.Scalyr, error)
GetScalyr(*fastly.GetScalyrInput) (*fastly.Scalyr, error)
UpdateScalyr(*fastly.UpdateScalyrInput) (*fastly.Scalyr, error)
DeleteScalyr(*fastly.DeleteScalyrInput) error

GetUser(*fastly.GetUserInput) (*fastly.User, error)

GetRegions() (*fastly.RegionsResponse, error)
Expand Down
15 changes: 15 additions & 0 deletions pkg/app/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/fastly/cli/pkg/logging/logentries"
"github.com/fastly/cli/pkg/logging/papertrail"
"github.com/fastly/cli/pkg/logging/s3"
"github.com/fastly/cli/pkg/logging/scalyr"
"github.com/fastly/cli/pkg/logging/splunk"
"github.com/fastly/cli/pkg/logging/sumologic"
"github.com/fastly/cli/pkg/logging/syslog"
Expand Down Expand Up @@ -191,6 +192,13 @@ func Run(args []string, env config.Environment, file config.File, configFilePath
splunkUpdate := splunk.NewUpdateCommand(splunkRoot.CmdClause, &globals)
splunkDelete := splunk.NewDeleteCommand(splunkRoot.CmdClause, &globals)

scalyrRoot := scalyr.NewRootCommand(loggingRoot.CmdClause, &globals)
scalyrCreate := scalyr.NewCreateCommand(scalyrRoot.CmdClause, &globals)
scalyrList := scalyr.NewListCommand(scalyrRoot.CmdClause, &globals)
scalyrDescribe := scalyr.NewDescribeCommand(scalyrRoot.CmdClause, &globals)
scalyrUpdate := scalyr.NewUpdateCommand(scalyrRoot.CmdClause, &globals)
scalyrDelete := scalyr.NewDeleteCommand(scalyrRoot.CmdClause, &globals)

statsRoot := stats.NewRootCommand(app, &globals)
statsRegions := stats.NewRegionsCommand(statsRoot.CmdClause, &globals)
statsHistorical := stats.NewHistoricalCommand(statsRoot.CmdClause, &globals)
Expand Down Expand Up @@ -310,6 +318,13 @@ func Run(args []string, env config.Environment, file config.File, configFilePath
splunkUpdate,
splunkDelete,

scalyrRoot,
scalyrCreate,
scalyrList,
scalyrDescribe,
scalyrUpdate,
scalyrDelete,

statsRoot,
statsRegions,
statsHistorical,
Expand Down
65 changes: 65 additions & 0 deletions pkg/app/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1362,6 +1362,71 @@ COMMANDS
--version=VERSION Number of service version
-n, --name=NAME The name of the Splunk logging object

logging scalyr create --name=NAME --version=VERSION --auth-token=AUTH-TOKEN [<flags>]
Create a Scalyr logging endpoint on a Fastly service version

-n, --name=NAME The name of the Scalyr logging object. Used as
a primary key for API access
-s, --service-id=SERVICE-ID Service ID
--version=VERSION Number of service version
--auth-token=AUTH-TOKEN The token to use for authentication
(https://www.scalyr.com/keys)
--format=FORMAT Apache style log formatting
--format-version=FORMAT-VERSION
The version of the custom logging format used
for the configured endpoint. Can be either 2
(default) or 1
--response-condition=RESPONSE-CONDITION
The name of an existing condition in the
configured endpoint, or leave blank to always
execute
--placement=PLACEMENT Where in the generated VCL the logging call
should be placed, overriding any format_version
default. Can be none or waf_debug

logging scalyr list --version=VERSION [<flags>]
List Scalyr endpoints on a Fastly service version

-s, --service-id=SERVICE-ID Service ID
--version=VERSION Number of service version

logging scalyr describe --version=VERSION --name=NAME [<flags>]
Show detailed information about a Scalyr logging endpoint on a Fastly
service version

-s, --service-id=SERVICE-ID Service ID
--version=VERSION Number of service version
-d, --name=NAME The name of the Scalyr logging object

logging scalyr update --version=VERSION --name=NAME [<flags>]
Update a Scalyr logging endpoint on a Fastly service version

-s, --service-id=SERVICE-ID Service ID
--version=VERSION Number of service version
-n, --name=NAME The name of the Scalyr logging object
--new-name=NEW-NAME New name of the Scalyr logging object
--format=FORMAT Apache style log formatting
--format-version=FORMAT-VERSION
The version of the custom logging format used
for the configured endpoint. Can be either 2
(default) or 1
--auth-token=AUTH-TOKEN The token to use for authentication
(https://www.scalyr.com/keys)
--response-condition=RESPONSE-CONDITION
The name of an existing condition in the
configured endpoint, or leave blank to always
execute
--placement=PLACEMENT Where in the generated VCL the logging call
should be placed, overriding any format_version
default. Can be none or waf_debug

logging scalyr delete --version=VERSION --name=NAME [<flags>]
Delete a Scalyr logging endpoint on a Fastly service version

-s, --service-id=SERVICE-ID Service ID
--version=VERSION Number of service version
-n, --name=NAME The name of the Scalyr logging object

stats regions
List stats regions

Expand Down
100 changes: 100 additions & 0 deletions pkg/logging/scalyr/create.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package scalyr

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/fastly"
)

// CreateCommand calls the Fastly API to create Scalyr logging endpoints.
type CreateCommand struct {
common.Base
manifest manifest.Data

// required
EndpointName string // Can't shaddow common.Base method Name().
Token string
Version int

// optional
Format common.OptionalString
FormatVersion common.OptionalUint
ResponseCondition common.OptionalString
Placement 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 Scalyr logging endpoint on a Fastly service version").Alias("add")

c.CmdClause.Flag("name", "The name of the Scalyr logging object. Used as a primary key for API access").Short('n').Required().StringVar(&c.EndpointName)
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.Version)

c.CmdClause.Flag("auth-token", "The token to use for authentication (https://www.scalyr.com/keys)").Required().StringVar(&c.Token)

c.CmdClause.Flag("format", "Apache style log formatting").Action(c.Format.Set).StringVar(&c.Format.Value)
c.CmdClause.Flag("format-version", "The version of the custom logging format used for the configured endpoint. Can be either 2 (default) or 1").Action(c.FormatVersion.Set).UintVar(&c.FormatVersion.Value)
c.CmdClause.Flag("response-condition", "The name of an existing condition in the configured endpoint, or leave blank to always execute").Action(c.ResponseCondition.Set).StringVar(&c.ResponseCondition.Value)
c.CmdClause.Flag("placement", "Where in the generated VCL the logging call should be placed, overriding any format_version default. Can be none or waf_debug").Action(c.Placement.Set).StringVar(&c.Placement.Value)

return &c
}

// createInput transforms values parsed from CLI flags into an object to be used by the API client library.
func (c *CreateCommand) createInput() (*fastly.CreateScalyrInput, error) {
var input fastly.CreateScalyrInput

serviceID, source := c.manifest.ServiceID()
if source == manifest.SourceUndefined {
return nil, errors.ErrNoServiceID
}

input.Service = serviceID
input.Version = c.Version
input.Name = fastly.String(c.EndpointName)
input.Token = fastly.String(c.Token)

if c.Format.Valid {
input.Format = fastly.String(c.Format.Value)
}

if c.FormatVersion.Valid {
input.FormatVersion = fastly.Uint(c.FormatVersion.Value)
}

if c.ResponseCondition.Valid {
input.ResponseCondition = fastly.String(c.ResponseCondition.Value)
}

if c.Placement.Valid {
input.Placement = fastly.String(c.Placement.Value)
}

return &input, nil
}

// Exec invokes the application logic for the command.
func (c *CreateCommand) Exec(in io.Reader, out io.Writer) error {
input, err := c.createInput()
if err != nil {
return err
}
mccurdyc marked this conversation as resolved.
Show resolved Hide resolved

d, err := c.Globals.Client.CreateScalyr(input)
if err != nil {
return err
}

text.Success(out, "Created Scalyr logging endpoint %s (service %s version %d)", d.Name, d.ServiceID, d.Version)
return nil
}
47 changes: 47 additions & 0 deletions pkg/logging/scalyr/delete.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package scalyr

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/fastly"
)

// DeleteCommand calls the Fastly API to delete Scalyr logging endpoints.
type DeleteCommand struct {
common.Base
manifest manifest.Data
Input fastly.DeleteScalyrInput
}

// 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 Scalyr logging endpoint on a Fastly service version").Alias("remove")
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.Version)
c.CmdClause.Flag("name", "The name of the Scalyr logging object").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.Service = serviceID

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

text.Success(out, "Deleted Scalyr logging endpoint %s (service %s version %d)", c.Input.Name, c.Input.Service, c.Input.Version)
return nil
}
56 changes: 56 additions & 0 deletions pkg/logging/scalyr/describe.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package scalyr

import (
"fmt"
"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/go-fastly/fastly"
)

// DescribeCommand calls the Fastly API to describe a Scalyr logging endpoint.
type DescribeCommand struct {
common.Base
manifest manifest.Data
Input fastly.GetScalyrInput
}

// NewDescribeCommand returns a usable command registered under the parent.
func NewDescribeCommand(parent common.Registerer, globals *config.Data) *DescribeCommand {
var c DescribeCommand
c.Globals = globals
c.manifest.File.Read(manifest.Filename)
c.CmdClause = parent.Command("describe", "Show detailed information about a Scalyr logging endpoint on a Fastly service version").Alias("get")
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.Version)
c.CmdClause.Flag("name", "The name of the Scalyr logging object").Short('d').Required().StringVar(&c.Input.Name)
return &c
}

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

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

fmt.Fprintf(out, "Service ID: %s\n", scalyr.ServiceID)
fmt.Fprintf(out, "Version: %d\n", scalyr.Version)
fmt.Fprintf(out, "Name: %s\n", scalyr.Name)
fmt.Fprintf(out, "Token: %s\n", scalyr.Token)
fmt.Fprintf(out, "Format: %s\n", scalyr.Format)
fmt.Fprintf(out, "Format version: %d\n", scalyr.FormatVersion)
fmt.Fprintf(out, "Response condition: %s\n", scalyr.ResponseCondition)
fmt.Fprintf(out, "Placement: %s\n", scalyr.Placement)

return nil
}
3 changes: 3 additions & 0 deletions pkg/logging/scalyr/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Package scalyr contains commands to inspect and manipulate Fastly service Scalyr
// logging endpoints.
package scalyr
Loading