-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
logging: adds Loggly logging endpoint support
Signed-off-by: Colton McCurdy <cmccurdy@fastly.com>
- Loading branch information
Showing
13 changed files
with
1,117 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,100 @@ | ||
package loggly | ||
|
||
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 Loggly 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 Loggly logging endpoint on a Fastly service version").Alias("add") | ||
|
||
c.CmdClause.Flag("name", "The name of the Loggly 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.loggly.com/docs/customer-token-authentication-token/)").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.CreateLogglyInput, error) { | ||
var input fastly.CreateLogglyInput | ||
|
||
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 | ||
} | ||
|
||
d, err := c.Globals.Client.CreateLoggly(input) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
text.Success(out, "Created Loggly 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 loggly | ||
|
||
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 Loggly logging endpoints. | ||
type DeleteCommand struct { | ||
common.Base | ||
manifest manifest.Data | ||
Input fastly.DeleteLogglyInput | ||
} | ||
|
||
// 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 Loggly 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 Loggly 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.DeleteLoggly(&c.Input); err != nil { | ||
return err | ||
} | ||
|
||
text.Success(out, "Deleted Loggly 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,56 @@ | ||
package loggly | ||
|
||
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 Loggly logging endpoint. | ||
type DescribeCommand struct { | ||
common.Base | ||
manifest manifest.Data | ||
Input fastly.GetLogglyInput | ||
} | ||
|
||
// 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 Loggly 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 Loggly 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 | ||
|
||
loggly, err := c.Globals.Client.GetLoggly(&c.Input) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
fmt.Fprintf(out, "Service ID: %s\n", loggly.ServiceID) | ||
fmt.Fprintf(out, "Version: %d\n", loggly.Version) | ||
fmt.Fprintf(out, "Name: %s\n", loggly.Name) | ||
fmt.Fprintf(out, "Token: %s\n", loggly.Token) | ||
fmt.Fprintf(out, "Format: %s\n", loggly.Format) | ||
fmt.Fprintf(out, "Format version: %d\n", loggly.FormatVersion) | ||
fmt.Fprintf(out, "Response condition: %s\n", loggly.ResponseCondition) | ||
fmt.Fprintf(out, "Placement: %s\n", loggly.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 loggly contains commands to inspect and manipulate Fastly service Loggly | ||
// logging endpoints. | ||
package loggly |
Oops, something went wrong.