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 Heroku logging endpoint support #76

Merged
merged 1 commit into from
May 20, 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 @@ -124,6 +124,12 @@ type Interface interface {
UpdateHoneycomb(*fastly.UpdateHoneycombInput) (*fastly.Honeycomb, error)
DeleteHoneycomb(*fastly.DeleteHoneycombInput) error

CreateHeroku(*fastly.CreateHerokuInput) (*fastly.Heroku, error)
ListHerokus(*fastly.ListHerokusInput) ([]*fastly.Heroku, error)
GetHeroku(*fastly.GetHerokuInput) (*fastly.Heroku, error)
UpdateHeroku(*fastly.UpdateHerokuInput) (*fastly.Heroku, error)
DeleteHeroku(*fastly.DeleteHerokuInput) 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 @@ -22,6 +22,7 @@ import (
"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/heroku"
"github.com/fastly/cli/pkg/logging/honeycomb"
"github.com/fastly/cli/pkg/logging/logentries"
"github.com/fastly/cli/pkg/logging/loggly"
Expand Down Expand Up @@ -215,6 +216,13 @@ func Run(args []string, env config.Environment, file config.File, configFilePath
honeycombUpdate := honeycomb.NewUpdateCommand(honeycombRoot.CmdClause, &globals)
honeycombDelete := honeycomb.NewDeleteCommand(honeycombRoot.CmdClause, &globals)

herokuRoot := heroku.NewRootCommand(loggingRoot.CmdClause, &globals)
herokuCreate := heroku.NewCreateCommand(herokuRoot.CmdClause, &globals)
herokuList := heroku.NewListCommand(herokuRoot.CmdClause, &globals)
herokuDescribe := heroku.NewDescribeCommand(herokuRoot.CmdClause, &globals)
herokuUpdate := heroku.NewUpdateCommand(herokuRoot.CmdClause, &globals)
herokuDelete := heroku.NewDeleteCommand(herokuRoot.CmdClause, &globals)

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

herokuRoot,
herokuCreate,
herokuList,
herokuDescribe,
herokuUpdate,
herokuDelete,

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

logging heroku create --name=NAME --version=VERSION --url=URL --auth-token=AUTH-TOKEN [<flags>]
Create a Heroku logging endpoint on a Fastly service version

-n, --name=NAME The name of the Heroku logging object. Used as
a primary key for API access
-s, --service-id=SERVICE-ID Service ID
--version=VERSION Number of service version
--url=URL The url to stream logs to
--auth-token=AUTH-TOKEN The token to use for authentication
(https://devcenter.heroku.com/articles/add-on-partner-log-integration)
--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
--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 heroku list --version=VERSION [<flags>]
List Heroku endpoints on a Fastly service version

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

logging heroku describe --version=VERSION --name=NAME [<flags>]
Show detailed information about a Heroku 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 Heroku logging object

logging heroku update --version=VERSION --name=NAME [<flags>]
Update a Heroku 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 Heroku logging object
--new-name=NEW-NAME New name of the Heroku logging object
--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
--url=URL The url to stream logs to
--auth-token=AUTH-TOKEN The token to use for authentication
(https://devcenter.heroku.com/articles/add-on-partner-log-integration)
--response-condition=RESPONSE-CONDITION
The name of an existing condition in the
configured endpoint, or leave blank to always
execute
--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 heroku delete --version=VERSION --name=NAME [<flags>]
Delete a Heroku 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 Heroku logging object

stats regions
List stats regions

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

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 Heroku logging endpoints.
type CreateCommand struct {
common.Base
manifest manifest.Data

// required
EndpointName string // Can't shaddow common.Base method Name().
Version int
Token string
URL 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 a Heroku logging endpoint on a Fastly service version").Alias("add")

c.CmdClause.Flag("name", "The name of the Heroku 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("url", "The url to stream logs to").Required().StringVar(&c.URL)
c.CmdClause.Flag("auth-token", "The token to use for authentication (https://devcenter.heroku.com/articles/add-on-partner-log-integration)").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.CreateHerokuInput, error) {
var input fastly.CreateHerokuInput

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)
input.URL = fastly.String(c.URL)

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.CreateHeroku(input)
if err != nil {
return err
}

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

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

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

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

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

// 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 Heroku 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 Heroku 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

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

fmt.Fprintf(out, "Service ID: %s\n", heroku.ServiceID)
fmt.Fprintf(out, "Version: %d\n", heroku.Version)
fmt.Fprintf(out, "Name: %s\n", heroku.Name)
fmt.Fprintf(out, "URL: %s\n", heroku.URL)
fmt.Fprintf(out, "Token: %s\n", heroku.Token)
fmt.Fprintf(out, "Format: %s\n", heroku.Format)
fmt.Fprintf(out, "Format version: %d\n", heroku.FormatVersion)
fmt.Fprintf(out, "Response condition: %s\n", heroku.ResponseCondition)
fmt.Fprintf(out, "Placement: %s\n", heroku.Placement)

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