-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
logging: adds splunk endpoint support
Signed-off-by: Colton McCurdy <cmccurdy@fastly.com>
- Loading branch information
Showing
12 changed files
with
935 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,60 @@ | ||
package splunk | ||
|
||
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 Splunk logging endpoints. | ||
type CreateCommand struct { | ||
common.Base | ||
manifest manifest.Data | ||
Input fastly.CreateSplunkInput | ||
} | ||
|
||
// 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 Splunk logging endpoint on a Fastly service version").Alias("add") | ||
|
||
c.CmdClause.Flag("name", "The name of the Splunk logging object. Used as a primary key for API access").Short('n').Required().StringVar(&c.Input.Name) | ||
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("url", "The URL to POST to").Required().StringVar(&c.Input.URL) | ||
|
||
c.CmdClause.Flag("tls-ca-cert", "A secure certificate to authenticate the server with. Must be in PEM format").StringVar(&c.Input.TLSCACert) | ||
c.CmdClause.Flag("tls-hostname", "The hostname used to verify the server's certificate. It can either be the Common Name or a Subject Alternative Name (SAN)").StringVar(&c.Input.TLSHostname) | ||
c.CmdClause.Flag("format", "Apache style log formatting").StringVar(&c.Input.Format) | ||
c.CmdClause.Flag("format-version", "The version of the custom logging format used for the configured endpoint. Can be either 2 (default) or 1").UintVar(&c.Input.FormatVersion) | ||
c.CmdClause.Flag("response-condition", "The name of an existing condition in the configured endpoint, or leave blank to always execute").StringVar(&c.Input.ResponseCondition) | ||
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").StringVar(&c.Input.Placement) | ||
c.CmdClause.Flag("auth-token", "A Splunk token for use in posting logs over HTTP to your collector").StringVar(&c.Input.Token) | ||
|
||
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.Service = serviceID | ||
|
||
d, err := c.Globals.Client.CreateSplunk(&c.Input) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
text.Success(out, "Created Splunk logging endpoint %s (service %s version %d)", d.Name, d.ServiceID, d.Version) | ||
return nil | ||
} |
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,47 @@ | ||
package splunk | ||
|
||
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 Splunk logging endpoints. | ||
type DeleteCommand struct { | ||
common.Base | ||
manifest manifest.Data | ||
Input fastly.DeleteSplunkInput | ||
} | ||
|
||
// 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 Splunk 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 Splunk 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.DeleteSplunk(&c.Input); err != nil { | ||
return err | ||
} | ||
|
||
text.Success(out, "Deleted Splunk logging endpoint %s (service %s version %d)", c.Input.Name, c.Input.Service, c.Input.Version) | ||
return nil | ||
} |
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,59 @@ | ||
package splunk | ||
|
||
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 Splunk logging endpoint. | ||
type DescribeCommand struct { | ||
common.Base | ||
manifest manifest.Data | ||
Input fastly.GetSplunkInput | ||
} | ||
|
||
// 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 Splunk 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 Splunk 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 | ||
|
||
splunk, err := c.Globals.Client.GetSplunk(&c.Input) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
fmt.Fprintf(out, "Service ID: %s\n", splunk.ServiceID) | ||
fmt.Fprintf(out, "Version: %d\n", splunk.Version) | ||
fmt.Fprintf(out, "Name: %s\n", splunk.Name) | ||
fmt.Fprintf(out, "URL: %s\n", splunk.URL) | ||
fmt.Fprintf(out, "Token: %s\n", splunk.Token) | ||
fmt.Fprintf(out, "TLS CA certificate: %s\n", splunk.TLSCACert) | ||
fmt.Fprintf(out, "TLS hostname: %s\n", splunk.TLSHostname) | ||
fmt.Fprintf(out, "Format: %s\n", splunk.Format) | ||
fmt.Fprintf(out, "Format version: %d\n", splunk.FormatVersion) | ||
fmt.Fprintf(out, "Response condition: %s\n", splunk.ResponseCondition) | ||
fmt.Fprintf(out, "Placement: %s\n", splunk.Placement) | ||
|
||
return nil | ||
} |
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 splunk contains commands to inspect and manipulate Fastly service Splunk | ||
// logging endpoints. | ||
package splunk |
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,75 @@ | ||
package splunk | ||
|
||
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/cli/pkg/text" | ||
"github.com/fastly/go-fastly/fastly" | ||
) | ||
|
||
// ListCommand calls the Fastly API to list Splunk logging endpoints. | ||
type ListCommand struct { | ||
common.Base | ||
manifest manifest.Data | ||
Input fastly.ListSplunksInput | ||
} | ||
|
||
// NewListCommand returns a usable command registered under the parent. | ||
func NewListCommand(parent common.Registerer, globals *config.Data) *ListCommand { | ||
var c ListCommand | ||
c.Globals = globals | ||
c.manifest.File.Read(manifest.Filename) | ||
c.CmdClause = parent.Command("list", "List Splunk endpoints 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.Version) | ||
return &c | ||
} | ||
|
||
// Exec invokes the application logic for the command. | ||
func (c *ListCommand) Exec(in io.Reader, out io.Writer) error { | ||
serviceID, source := c.manifest.ServiceID() | ||
if source == manifest.SourceUndefined { | ||
return errors.ErrNoServiceID | ||
} | ||
c.Input.Service = serviceID | ||
|
||
splunks, err := c.Globals.Client.ListSplunks(&c.Input) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if !c.Globals.Verbose() { | ||
tw := text.NewTable(out) | ||
tw.AddHeader("SERVICE", "VERSION", "NAME") | ||
for _, splunk := range splunks { | ||
tw.AddLine(splunk.ServiceID, splunk.Version, splunk.Name) | ||
} | ||
tw.Print() | ||
return nil | ||
} | ||
|
||
fmt.Fprintf(out, "Service ID: %s\n", c.Input.Service) | ||
fmt.Fprintf(out, "Version: %d\n", c.Input.Version) | ||
for i, splunk := range splunks { | ||
fmt.Fprintf(out, "\tSplunk %d/%d\n", i+1, len(splunks)) | ||
fmt.Fprintf(out, "\t\tService ID: %s\n", splunk.ServiceID) | ||
fmt.Fprintf(out, "\t\tVersion: %d\n", splunk.Version) | ||
fmt.Fprintf(out, "\t\tName: %s\n", splunk.Name) | ||
fmt.Fprintf(out, "\t\tURL: %s\n", splunk.URL) | ||
fmt.Fprintf(out, "\t\tToken: %s\n", splunk.Token) | ||
fmt.Fprintf(out, "\t\tTLS CA certificate: %s\n", splunk.TLSCACert) | ||
fmt.Fprintf(out, "\t\tTLS hostname: %s\n", splunk.TLSHostname) | ||
fmt.Fprintf(out, "\t\tFormat: %s\n", splunk.Format) | ||
fmt.Fprintf(out, "\t\tFormat version: %d\n", splunk.FormatVersion) | ||
fmt.Fprintf(out, "\t\tResponse condition: %s\n", splunk.ResponseCondition) | ||
fmt.Fprintf(out, "\t\tPlacement: %s\n", splunk.Placement) | ||
} | ||
fmt.Fprintln(out) | ||
|
||
return nil | ||
} |
Oops, something went wrong.