-
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.
Add support for Kinesis logging endpoint (#177)
* Add support for Kinesis logging endpoint * Code reorganization and comment re-wording for Kinesis endpoint * Indicate service-id as required for Kinesis operations * Fix comments typo in Kinesis create and update files * Make service-id optional again and clean up go.sum file
- Loading branch information
1 parent
32ca6b9
commit 7bc9416
Showing
15 changed files
with
1,205 additions
and
3 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
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,109 @@ | ||
package kinesis | ||
|
||
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/v2/fastly" | ||
) | ||
|
||
// CreateCommand calls the Fastly API to create an Amazon Kinesis logging endpoint. | ||
type CreateCommand struct { | ||
common.Base | ||
manifest manifest.Data | ||
|
||
// required | ||
EndpointName string // Can't shadow common.Base method Name(). | ||
Version int | ||
StreamName string | ||
AccessKey string | ||
SecretKey string | ||
Region string | ||
|
||
// 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 an Amazon Kinesis logging endpoint on a Fastly service version").Alias("add") | ||
|
||
// required | ||
c.CmdClause.Flag("name", "The name of the Kinesis logging object. Used as a primary key for API access").Short('n').Required().StringVar(&c.EndpointName) | ||
c.CmdClause.Flag("version", "Number of service version").Required().IntVar(&c.Version) | ||
c.CmdClause.Flag("stream-name", "The Amazon Kinesis stream to send logs to").Required().StringVar(&c.StreamName) | ||
c.CmdClause.Flag("access-key", "The access key associated with the target Amazon Kinesis stream").Required().StringVar(&c.AccessKey) | ||
c.CmdClause.Flag("secret-key", "The secret key associated with the target Amazon Kinesis stream").Required().StringVar(&c.SecretKey) | ||
c.CmdClause.Flag("region", "The AWS region where the Kinesis stream exists").Required().StringVar(&c.Region) | ||
|
||
// optional | ||
c.CmdClause.Flag("service-id", "Service ID").Short('s').StringVar(&c.manifest.Flag.ServiceID) | ||
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.CreateKinesisInput, error) { | ||
var input fastly.CreateKinesisInput | ||
|
||
serviceID, source := c.manifest.ServiceID() | ||
if source == manifest.SourceUndefined { | ||
return nil, errors.ErrNoServiceID | ||
} | ||
|
||
input.ServiceID = serviceID | ||
input.ServiceVersion = c.Version | ||
input.Name = c.EndpointName | ||
input.StreamName = c.StreamName | ||
input.AccessKey = c.AccessKey | ||
input.SecretKey = c.SecretKey | ||
input.Region = c.Region | ||
|
||
if c.Format.WasSet { | ||
input.Format = c.Format.Value | ||
} | ||
|
||
if c.FormatVersion.WasSet { | ||
input.FormatVersion = c.FormatVersion.Value | ||
} | ||
|
||
if c.ResponseCondition.WasSet { | ||
input.ResponseCondition = c.ResponseCondition.Value | ||
} | ||
|
||
if c.Placement.WasSet { | ||
input.Placement = 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.CreateKinesis(input) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
text.Success(out, "Created Kinesis logging endpoint %s (service %s version %d)", d.Name, d.ServiceID, d.ServiceVersion) | ||
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,48 @@ | ||
package kinesis | ||
|
||
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/v2/fastly" | ||
) | ||
|
||
// DeleteCommand calls the Fastly API to delete an Amazon Kinesis logging endpoint. | ||
type DeleteCommand struct { | ||
common.Base | ||
manifest manifest.Data | ||
Input fastly.DeleteKinesisInput | ||
} | ||
|
||
// 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 Kinesis logging endpoint on a Fastly service version").Alias("remove") | ||
c.CmdClause.Flag("version", "Number of service version").Required().IntVar(&c.Input.ServiceVersion) | ||
c.CmdClause.Flag("name", "The name of the Kinesis logging object").Short('n').Required().StringVar(&c.Input.Name) | ||
c.CmdClause.Flag("service-id", "Service ID").Short('s').StringVar(&c.manifest.Flag.ServiceID) | ||
|
||
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.ServiceID = serviceID | ||
|
||
if err := c.Globals.Client.DeleteKinesis(&c.Input); err != nil { | ||
return err | ||
} | ||
|
||
text.Success(out, "Deleted Kinesis logging endpoint %s (service %s version %d)", c.Input.Name, c.Input.ServiceID, c.Input.ServiceVersion) | ||
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 kinesis | ||
|
||
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/v2/fastly" | ||
) | ||
|
||
// DescribeCommand calls the Fastly API to describe an Amazon Kinesis logging endpoint. | ||
type DescribeCommand struct { | ||
common.Base | ||
manifest manifest.Data | ||
Input fastly.GetKinesisInput | ||
} | ||
|
||
// 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 Kinesis 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.ServiceVersion) | ||
c.CmdClause.Flag("name", "The name of the Kinesis logging object").Short('n').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.ServiceID = serviceID | ||
|
||
kinesis, err := c.Globals.Client.GetKinesis(&c.Input) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
fmt.Fprintf(out, "Service ID: %s\n", kinesis.ServiceID) | ||
fmt.Fprintf(out, "Version: %d\n", kinesis.ServiceVersion) | ||
fmt.Fprintf(out, "Name: %s\n", kinesis.Name) | ||
fmt.Fprintf(out, "Stream name: %s\n", kinesis.StreamName) | ||
fmt.Fprintf(out, "Region: %s\n", kinesis.Region) | ||
fmt.Fprintf(out, "Access key: %s\n", kinesis.AccessKey) | ||
fmt.Fprintf(out, "Secret key: %s\n", kinesis.SecretKey) | ||
fmt.Fprintf(out, "Format: %s\n", kinesis.Format) | ||
fmt.Fprintf(out, "Format version: %d\n", kinesis.FormatVersion) | ||
fmt.Fprintf(out, "Response condition: %s\n", kinesis.ResponseCondition) | ||
fmt.Fprintf(out, "Placement: %s\n", kinesis.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 kinesis contains commands to inspect and manipulate Fastly service Kinesis | ||
// logging endpoints. | ||
package kinesis |
Oops, something went wrong.