-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CRUD commands for S3 logging endpoints (#9)
- Loading branch information
Showing
13 changed files
with
1,123 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package s3 | ||
|
||
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 Amazon S3 logging endpoints. | ||
type CreateCommand struct { | ||
common.Base | ||
manifest manifest.Data | ||
Input fastly.CreateS3Input | ||
|
||
redundancy string | ||
serverSideEncryption string | ||
} | ||
|
||
// 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 S3 logging endpoint on a Fastly service version").Alias("add") | ||
|
||
c.CmdClause.Flag("name", "The name of the S3 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("bucket", "Your S3 bucket name").Required().StringVar(&c.Input.BucketName) | ||
c.CmdClause.Flag("access-key", "Your S3 account access key").Required().StringVar(&c.Input.AccessKey) | ||
c.CmdClause.Flag("secret-key", "Your S3 account secret key").Required().StringVar(&c.Input.SecretKey) | ||
|
||
c.CmdClause.Flag("domain", "The domain of the S3 endpoint").StringVar(&c.Input.Domain) | ||
c.CmdClause.Flag("path", "The path to upload logs to").StringVar(&c.Input.Path) | ||
c.CmdClause.Flag("period", "How frequently log files are finalized so they can be available for reading (in seconds, default 3600)").UintVar(&c.Input.Period) | ||
c.CmdClause.Flag("gzip-level", "What level of GZIP encoding to have when dumping logs (default 0, no compression)").UintVar(&c.Input.GzipLevel) | ||
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("message-type", "How the message should be formatted. One of: classic (default), loggly, logplex or blank").StringVar(&c.Input.MessageType) | ||
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("timestamp-format", `strftime specified timestamp formatting (default "%Y-%m-%dT%H:%M:%S.000")`).StringVar(&c.Input.TimestampFormat) | ||
c.CmdClause.Flag("redundancy", "The S3 redundancy level. Can be either standard or reduced_redundancy").EnumVar(&c.redundancy, string(fastly.S3RedundancyStandard), string(fastly.S3RedundancyReduced)) | ||
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("server-side-encryption", "Set to enable S3 Server Side Encryption. Can be either AES256 or aws:kms").EnumVar(&c.serverSideEncryption, string(fastly.S3ServerSideEncryptionAES), string(fastly.S3ServerSideEncryptionKMS)) | ||
c.CmdClause.Flag("server-side-encryption-kms-key-id", "Server-side KMS Key ID. Must be set if server-side-encryption is set to aws:kms").StringVar(&c.Input.ServerSideEncryptionKMSKeyID) | ||
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 | ||
|
||
switch c.redundancy { | ||
case string(fastly.S3RedundancyStandard): | ||
c.Input.Redundancy = fastly.S3RedundancyStandard | ||
case string(fastly.S3RedundancyReduced): | ||
c.Input.Redundancy = fastly.S3RedundancyReduced | ||
} | ||
|
||
switch c.serverSideEncryption { | ||
case string(fastly.S3ServerSideEncryptionAES): | ||
c.Input.ServerSideEncryption = fastly.S3ServerSideEncryptionAES | ||
case string(fastly.S3ServerSideEncryptionKMS): | ||
c.Input.ServerSideEncryption = fastly.S3ServerSideEncryptionKMS | ||
} | ||
|
||
d, err := c.Globals.Client.CreateS3(&c.Input) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
text.Success(out, "Created S3 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 s3 | ||
|
||
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 Amazon S3 logging endpoints. | ||
type DeleteCommand struct { | ||
common.Base | ||
manifest manifest.Data | ||
Input fastly.DeleteS3Input | ||
} | ||
|
||
// 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 S3 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 S3 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.DeleteS3(&c.Input); err != nil { | ||
return err | ||
} | ||
|
||
text.Success(out, "Deleted S3 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,66 @@ | ||
package s3 | ||
|
||
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 an Amazon S3 logging endpoint. | ||
type DescribeCommand struct { | ||
common.Base | ||
manifest manifest.Data | ||
Input fastly.GetS3Input | ||
} | ||
|
||
// 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 S3 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 S3 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 | ||
|
||
s3, err := c.Globals.Client.GetS3(&c.Input) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
fmt.Fprintf(out, "Service ID: %s\n", s3.ServiceID) | ||
fmt.Fprintf(out, "Version: %d\n", s3.Version) | ||
fmt.Fprintf(out, "Name: %s\n", s3.Name) | ||
fmt.Fprintf(out, "Bucket: %s\n", s3.BucketName) | ||
fmt.Fprintf(out, "Access key: %s\n", s3.AccessKey) | ||
fmt.Fprintf(out, "Secret key: %s\n", s3.SecretKey) | ||
fmt.Fprintf(out, "Path: %s\n", s3.Path) | ||
fmt.Fprintf(out, "Period: %d\n", s3.Period) | ||
fmt.Fprintf(out, "GZip level: %d\n", s3.GzipLevel) | ||
fmt.Fprintf(out, "Format: %s\n", s3.Format) | ||
fmt.Fprintf(out, "Format version: %d\n", s3.FormatVersion) | ||
fmt.Fprintf(out, "Response condition: %s\n", s3.ResponseCondition) | ||
fmt.Fprintf(out, "Message type: %s\n", s3.MessageType) | ||
fmt.Fprintf(out, "Timestamp format: %s\n", s3.TimestampFormat) | ||
fmt.Fprintf(out, "Placement: %s\n", s3.Placement) | ||
fmt.Fprintf(out, "Redundancy: %s\n", s3.Redundancy) | ||
fmt.Fprintf(out, "Server-side encryption: %s\n", s3.ServerSideEncryption) | ||
fmt.Fprintf(out, "Server-side encryption KMS key ID: %s\n", s3.ServerSideEncryption) | ||
|
||
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 s3 contains commands to inspect and manipulate Fastly service S3 | ||
// logging endpoints. | ||
package s3 |
Oops, something went wrong.