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 FTP logging endpoint support #63

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 @@ -94,6 +94,12 @@ type Interface interface {
UpdateGCS(*fastly.UpdateGCSInput) (*fastly.GCS, error)
DeleteGCS(*fastly.DeleteGCSInput) error

CreateFTP(*fastly.CreateFTPInput) (*fastly.FTP, error)
ListFTPs(*fastly.ListFTPsInput) ([]*fastly.FTP, error)
GetFTP(*fastly.GetFTPInput) (*fastly.FTP, error)
UpdateFTP(*fastly.UpdateFTPInput) (*fastly.FTP, error)
DeleteFTP(*fastly.DeleteFTPInput) 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 @@ -20,6 +20,7 @@ import (
"github.com/fastly/cli/pkg/healthcheck"
"github.com/fastly/cli/pkg/logging"
"github.com/fastly/cli/pkg/logging/bigquery"
"github.com/fastly/cli/pkg/logging/ftp"
"github.com/fastly/cli/pkg/logging/gcs"
"github.com/fastly/cli/pkg/logging/logentries"
"github.com/fastly/cli/pkg/logging/papertrail"
Expand Down Expand Up @@ -175,6 +176,13 @@ func Run(args []string, env config.Environment, file config.File, configFilePath
gcsUpdate := gcs.NewUpdateCommand(gcsRoot.CmdClause, &globals)
gcsDelete := gcs.NewDeleteCommand(gcsRoot.CmdClause, &globals)

ftpRoot := ftp.NewRootCommand(loggingRoot.CmdClause, &globals)
ftpCreate := ftp.NewCreateCommand(ftpRoot.CmdClause, &globals)
ftpList := ftp.NewListCommand(ftpRoot.CmdClause, &globals)
ftpDescribe := ftp.NewDescribeCommand(ftpRoot.CmdClause, &globals)
ftpUpdate := ftp.NewUpdateCommand(ftpRoot.CmdClause, &globals)
ftpDelete := ftp.NewDeleteCommand(ftpRoot.CmdClause, &globals)

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

ftpRoot,
ftpCreate,
ftpList,
ftpDescribe,
ftpUpdate,
ftpDelete,

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

logging ftp create --name=NAME --version=VERSION --address=ADDRESS --user=USER --password=PASSWORD [<flags>]
Create an FTP logging endpoint on a Fastly service version

-n, --name=NAME The name of the FTP logging object. Used as a
primary key for API access
-s, --service-id=SERVICE-ID Service ID
--version=VERSION Number of service version
--address=ADDRESS An hostname or IPv4 address
--user=USER The username for the server (can be anonymous)
--password=PASSWORD The password for the server (for anonymous use
an email address)
--port=PORT The port number
--path=PATH The path to upload log files to. If the path
ends in / then it is treated as a directory
--period=PERIOD How frequently log files are finalized so they
can be available for reading (in seconds,
default 3600)
--gzip-level=GZIP-LEVEL What level of GZIP encoding to have when
dumping logs (default 0, no compression)
--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
--timestamp-format=TIMESTAMP-FORMAT
strftime specified timestamp formatting
(default "%Y-%m-%dT%H:%M:%S.000")
--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 ftp list --version=VERSION [<flags>]
List FTP endpoints on a Fastly service version

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

logging ftp describe --version=VERSION --name=NAME [<flags>]
Show detailed information about an FTP 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 FTP logging object

logging ftp update --version=VERSION --name=NAME [<flags>]
Update an FTP 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 FTP logging object
--new-name=NEW-NAME New name of the FTP logging object
--address=ADDRESS An hostname or IPv4 address
--port=PORT The port number
--username=USERNAME The username for the server (can be anonymous)
--password=PASSWORD The password for the server (for anonymous use
an email address)
--public-key=PUBLIC-KEY A PGP public key that Fastly will use to
encrypt your log files before writing them to
disk
--path=PATH The path to upload log files to. If the path
ends in / then it is treated as a directory
--period=PERIOD How frequently log files are finalized so they
can be available for reading (in seconds,
default 3600)
--gzip-level=GZIP-LEVEL What level of GZIP encoding to have when
dumping logs (default 0, no compression)
--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
(the default, version 2 log format) or 1 (the
version 1 log format). The logging call gets
placed by default in vcl_log if format_version
is set to 2 and in vcl_deliver if
format_version is set to 1
--response-condition=RESPONSE-CONDITION
The name of an existing condition in the
configured endpoint, or leave blank to always
execute
--timestamp-format=TIMESTAMP-FORMAT
strftime specified timestamp formatting
(default "%Y-%m-%dT%H:%M:%S.000")
--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 ftp delete --version=VERSION --name=NAME [<flags>]
Delete an FTP 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 FTP logging object

stats regions
List stats regions

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

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 FTP logging endpoints.
type CreateCommand struct {
common.Base
manifest manifest.Data
Input fastly.CreateFTPInput
}

// 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 FTP logging endpoint on a Fastly service version").Alias("add")

c.CmdClause.Flag("name", "The name of the FTP 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("address", "An hostname or IPv4 address").Required().StringVar(&c.Input.Address)
c.CmdClause.Flag("user", "The username for the server (can be anonymous)").Required().StringVar(&c.Input.Username)
c.CmdClause.Flag("password", "The password for the server (for anonymous use an email address)").Required().StringVar(&c.Input.Password)

c.CmdClause.Flag("port", "The port number").UintVar(&c.Input.Port)
c.CmdClause.Flag("path", "The path to upload log files to. If the path ends in / then it is treated as a directory").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)").Uint8Var(&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("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("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)

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.CreateFTP(&c.Input)
if err != nil {
return err
}

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

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 FTP logging endpoints.
type DeleteCommand struct {
common.Base
manifest manifest.Data
Input fastly.DeleteFTPInput
}

// 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 an FTP 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 FTP 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.DeleteFTP(&c.Input); err != nil {
return err
}

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

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 FTP logging endpoint.
type DescribeCommand struct {
common.Base
manifest manifest.Data
Input fastly.GetFTPInput
}

// 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 an FTP 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 FTP 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

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

fmt.Fprintf(out, "Service ID: %s\n", ftp.ServiceID)
fmt.Fprintf(out, "Version: %d\n", ftp.Version)
fmt.Fprintf(out, "Name: %s\n", ftp.Name)
fmt.Fprintf(out, "Address: %s\n", ftp.Address)
fmt.Fprintf(out, "Port: %d\n", ftp.Port)
fmt.Fprintf(out, "Username: %s\n", ftp.Username)
fmt.Fprintf(out, "Password: %s\n", ftp.Password)
fmt.Fprintf(out, "Public key: %s\n", ftp.PublicKey)
fmt.Fprintf(out, "Path: %s\n", ftp.Path)
fmt.Fprintf(out, "Period: %d\n", ftp.Period)
fmt.Fprintf(out, "GZip level: %d\n", ftp.GzipLevel)
fmt.Fprintf(out, "Format: %s\n", ftp.Format)
fmt.Fprintf(out, "Format version: %d\n", ftp.FormatVersion)
fmt.Fprintf(out, "Response condition: %s\n", ftp.ResponseCondition)
fmt.Fprintf(out, "Timestamp format: %s\n", ftp.TimestampFormat)
fmt.Fprintf(out, "Placement: %s\n", ftp.Placement)

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