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

Reduce duplication of strings in logging package #653

Merged
merged 9 commits into from
Oct 6, 2022
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/bep/debounce v1.2.0
github.com/blang/semver v3.5.1+incompatible
github.com/dustinkirkland/golang-petname v0.0.0-20191129215211-8e5a1ed0cff0
github.com/fastly/go-fastly/v6 v6.5.2
github.com/fastly/go-fastly/v6 v6.6.0
github.com/fastly/kingpin v2.1.12-0.20191105091915-95d230a53780+incompatible
github.com/fatih/color v1.13.0
github.com/frankban/quicktest v1.13.1 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ github.com/etcd-io/bbolt v1.3.3/go.mod h1:ZF2nL25h33cCyBtcyWeZ2/I3HQOfTP+0PIEvHj
github.com/fasthttp-contrib/websocket v0.0.0-20160511215533-1f3b11f56072/go.mod h1:duJ4Jxv5lDcvg4QuQr0oowTf7dz4/CR8NtyCooz9HL8=
github.com/fastly/go-fastly/v6 v6.5.2 h1:oeHoRoddStqHn1Ukyz+oVxPjvYDBARNr+hP6+HAt4TY=
github.com/fastly/go-fastly/v6 v6.5.2/go.mod h1:NrIbx45etTFv35rgfRe+eQY+8kA47arWABIkOaQ+roY=
github.com/fastly/go-fastly/v6 v6.6.0 h1:H+KpD/K2FlhB6JHFxXIUst7aJRyF3r0Ro0uMdSX85AI=
github.com/fastly/go-fastly/v6 v6.6.0/go.mod h1:NrIbx45etTFv35rgfRe+eQY+8kA47arWABIkOaQ+roY=
github.com/fastly/kingpin v2.1.12-0.20191105091915-95d230a53780+incompatible h1:FhrXlfhgGCS+uc6YwyiFUt04alnjpoX7vgDKJxS6Qbk=
github.com/fastly/kingpin v2.1.12-0.20191105091915-95d230a53780+incompatible/go.mod h1:U8UynVoU1SQaqD2I4ZqgYd5lx3A1ipQYn4aSt2Y5h6c=
github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w=
Expand Down
4 changes: 2 additions & 2 deletions pkg/commands/logging/azureblob/azureblob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func TestUpdateBlobStorageInput(t *testing.T) {
SASToken: fastly.String("new4"),
Path: fastly.String("new5"),
Period: fastly.Uint(3601),
GzipLevel: fastly.Uint(0),
GzipLevel: fastly.Uint8(0),
Format: fastly.String("new6"),
FormatVersion: fastly.Uint(3),
ResponseCondition: fastly.String("new7"),
Expand Down Expand Up @@ -356,7 +356,7 @@ func updateCommandAll() *azureblob.UpdateCommand {
SASToken: cmd.OptionalString{Optional: cmd.Optional{WasSet: true}, Value: "new4"},
Path: cmd.OptionalString{Optional: cmd.Optional{WasSet: true}, Value: "new5"},
Period: cmd.OptionalUint{Optional: cmd.Optional{WasSet: true}, Value: 3601},
GzipLevel: cmd.OptionalUint{Optional: cmd.Optional{WasSet: true}, Value: 0},
GzipLevel: cmd.OptionalUint8{Optional: cmd.Optional{WasSet: true}, Value: 0},
Format: cmd.OptionalString{Optional: cmd.Optional{WasSet: true}, Value: "new6"},
FormatVersion: cmd.OptionalUint{Optional: cmd.Optional{WasSet: true}, Value: 3},
ResponseCondition: cmd.OptionalString{Optional: cmd.Optional{WasSet: true}, Value: "new7"},
Expand Down
25 changes: 13 additions & 12 deletions pkg/commands/logging/azureblob/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io"

"github.com/fastly/cli/pkg/cmd"
"github.com/fastly/cli/pkg/commands/logging/common"
"github.com/fastly/cli/pkg/config"
"github.com/fastly/cli/pkg/errors"
"github.com/fastly/cli/pkg/manifest"
Expand All @@ -29,7 +30,7 @@ type CreateCommand struct {
AutoClone cmd.OptionalAutoClone
Path cmd.OptionalString
Period cmd.OptionalUint
GzipLevel cmd.OptionalUint
GzipLevel cmd.OptionalUint8
MessageType cmd.OptionalString
Format cmd.OptionalString
FormatVersion cmd.OptionalUint
Expand Down Expand Up @@ -73,18 +74,18 @@ func NewCreateCommand(parent cmd.Registerer, globals *config.Data, data manifest
Description: cmd.FlagServiceDesc,
Dst: &c.ServiceName.Value,
})
c.CmdClause.Flag("path", "The path to upload logs to").Action(c.Path.Set).StringVar(&c.Path.Value)
c.CmdClause.Flag("period", "How frequently log files are finalized so they can be available for reading (in seconds, default 3600)").Action(c.Period.Set).UintVar(&c.Period.Value)
c.CmdClause.Flag("gzip-level", "What level of GZIP encoding to have when dumping logs (default 0, no compression)").Action(c.GzipLevel.Set).UintVar(&c.GzipLevel.Value)
c.CmdClause.Flag("format", "Apache style log formatting").Action(c.Format.Set).StringVar(&c.Format.Value)
c.CmdClause.Flag("message-type", "How the message should be formatted. One of: classic (default), loggly, logplex or blank").Action(c.MessageType.Set).StringVar(&c.MessageType.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("timestamp-format", `strftime specified timestamp formatting (default "%Y-%m-%dT%H:%M:%S.000")`).Action(c.TimestampFormat.Set).StringVar(&c.TimestampFormat.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)
c.CmdClause.Flag("public-key", "A PGP public key that Fastly will use to encrypt your log files before writing them to disk").Action(c.PublicKey.Set).StringVar(&c.PublicKey.Value)
common.Path(c.CmdClause, &c.Path)
common.Period(c.CmdClause, &c.Period)
common.GzipLevel(c.CmdClause, &c.GzipLevel)
common.Format(c.CmdClause, &c.Format)
common.MessageType(c.CmdClause, &c.MessageType)
common.FormatVersion(c.CmdClause, &c.FormatVersion)
common.ResponseCondition(c.CmdClause, &c.ResponseCondition)
common.TimestampFormat(c.CmdClause, &c.TimestampFormat)
common.Placement(c.CmdClause, &c.Placement)
common.PublicKey(c.CmdClause, &c.PublicKey)
c.CmdClause.Flag("file-max-bytes", "The maximum size of a log file in bytes").Action(c.FileMaxBytes.Set).UintVar(&c.FileMaxBytes.Value)
c.CmdClause.Flag("compression-codec", `The codec used for compression of your logs. Valid values are zstd, snappy, and gzip. If the specified codec is "gzip", gzip_level will default to 3. To specify a different level, leave compression_codec blank and explicitly set the level using gzip_level. Specifying both compression_codec and gzip_level in the same API request will result in an error.`).Action(c.CompressionCodec.Set).StringVar(&c.CompressionCodec.Value)
common.CompressionCodec(c.CmdClause, &c.CompressionCodec)
return &c
}

Expand Down
27 changes: 14 additions & 13 deletions pkg/commands/logging/azureblob/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"io"

"github.com/fastly/cli/pkg/cmd"
"github.com/fastly/cli/pkg/commands/logging/common"
"github.com/fastly/cli/pkg/config"
"github.com/fastly/cli/pkg/errors"
"github.com/fastly/cli/pkg/manifest"
Expand All @@ -29,7 +30,7 @@ type UpdateCommand struct {
SASToken cmd.OptionalString
Path cmd.OptionalString
Period cmd.OptionalUint
GzipLevel cmd.OptionalUint
GzipLevel cmd.OptionalUint8
MessageType cmd.OptionalString
Format cmd.OptionalString
FormatVersion cmd.OptionalUint
Expand Down Expand Up @@ -74,18 +75,18 @@ func NewUpdateCommand(parent cmd.Registerer, globals *config.Data, data manifest
c.CmdClause.Flag("container", "The name of the Azure Blob Storage container in which to store logs").Action(c.Container.Set).StringVar(&c.Container.Value)
c.CmdClause.Flag("account-name", "The unique Azure Blob Storage namespace in which your data objects are stored").Action(c.AccountName.Set).StringVar(&c.AccountName.Value)
c.CmdClause.Flag("sas-token", "The Azure shared access signature providing write access to the blob service objects. Be sure to update your token before it expires or the logging functionality will not work").Action(c.SASToken.Set).StringVar(&c.SASToken.Value)
c.CmdClause.Flag("path", "The path to upload logs to").Action(c.Path.Set).StringVar(&c.Path.Value)
c.CmdClause.Flag("period", "How frequently log files are finalized so they can be available for reading (in seconds, default 3600)").Action(c.Period.Set).UintVar(&c.Period.Value)
c.CmdClause.Flag("gzip-level", "What level of GZIP encoding to have when dumping logs (default 0, no compression)").Action(c.GzipLevel.Set).UintVar(&c.GzipLevel.Value)
c.CmdClause.Flag("format", "Apache style log formatting").Action(c.Format.Set).StringVar(&c.Format.Value)
c.CmdClause.Flag("message-type", "How the message should be formatted. One of: classic (default), loggly, logplex or blank").Action(c.MessageType.Set).StringVar(&c.MessageType.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("timestamp-format", `strftime specified timestamp formatting (default "%Y-%m-%dT%H:%M:%S.000")`).Action(c.TimestampFormat.Set).StringVar(&c.TimestampFormat.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)
c.CmdClause.Flag("public-key", "A PGP public key that Fastly will use to encrypt your log files before writing them to disk").Action(c.PublicKey.Set).StringVar(&c.PublicKey.Value)
common.Path(c.CmdClause, &c.Path)
common.Period(c.CmdClause, &c.Period)
common.GzipLevel(c.CmdClause, &c.GzipLevel)
common.Format(c.CmdClause, &c.Format)
common.MessageType(c.CmdClause, &c.MessageType)
common.FormatVersion(c.CmdClause, &c.FormatVersion)
common.ResponseCondition(c.CmdClause, &c.ResponseCondition)
common.TimestampFormat(c.CmdClause, &c.TimestampFormat)
common.Placement(c.CmdClause, &c.Placement)
common.PublicKey(c.CmdClause, &c.PublicKey)
c.CmdClause.Flag("file-max-bytes", "The maximum size of a log file in bytes").Action(c.FileMaxBytes.Set).UintVar(&c.FileMaxBytes.Value)
c.CmdClause.Flag("compression-codec", `The codec used for compression of your logs. Valid values are zstd, snappy, and gzip. If the specified codec is "gzip", gzip_level will default to 3. To specify a different level, leave compression_codec blank and explicitly set the level using gzip_level. Specifying both compression_codec and gzip_level in the same API request will result in an error.`).Action(c.CompressionCodec.Set).StringVar(&c.CompressionCodec.Value)
common.CompressionCodec(c.CmdClause, &c.CompressionCodec)
return &c
}

Expand Down Expand Up @@ -123,7 +124,7 @@ func (c *UpdateCommand) ConstructInput(serviceID string, serviceVersion int) (*f
}

if c.GzipLevel.WasSet {
input.GzipLevel = fastly.Uint(c.GzipLevel.Value)
input.GzipLevel = fastly.Uint8(c.GzipLevel.Value)
}

if c.Format.WasSet {
Expand Down
9 changes: 5 additions & 4 deletions pkg/commands/logging/bigquery/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"io"

"github.com/fastly/cli/pkg/cmd"
"github.com/fastly/cli/pkg/commands/logging/common"
"github.com/fastly/cli/pkg/config"
"github.com/fastly/cli/pkg/errors"
"github.com/fastly/cli/pkg/manifest"
Expand Down Expand Up @@ -70,10 +71,10 @@ func NewCreateCommand(parent cmd.Registerer, globals *config.Data, data manifest
Dst: &c.ServiceName.Value,
})
c.CmdClause.Flag("template-suffix", "BigQuery table name suffix template").Action(c.Template.Set).StringVar(&c.Template.Value)
c.CmdClause.Flag("format", "Apache style log formatting. Must produce JSON that matches the schema of your BigQuery table").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 (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").Action(c.FormatVersion.Set).UintVar(&c.FormatVersion.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. This field is not required and has no default value").Action(c.Placement.Set).StringVar(&c.Placement.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)
common.Format(c.CmdClause, &c.Format)
common.FormatVersion(c.CmdClause, &c.FormatVersion)
common.Placement(c.CmdClause, &c.Placement)
common.ResponseCondition(c.CmdClause, &c.ResponseCondition)
return &c
}

Expand Down
9 changes: 5 additions & 4 deletions pkg/commands/logging/bigquery/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"io"

"github.com/fastly/cli/pkg/cmd"
"github.com/fastly/cli/pkg/commands/logging/common"
"github.com/fastly/cli/pkg/config"
"github.com/fastly/cli/pkg/errors"
"github.com/fastly/cli/pkg/manifest"
Expand Down Expand Up @@ -72,10 +73,10 @@ func NewUpdateCommand(parent cmd.Registerer, globals *config.Data, data manifest
c.CmdClause.Flag("user", "Your Google Cloud Platform service account email address. The client_email field in your service account authentication JSON.").Action(c.User.Set).StringVar(&c.User.Value)
c.CmdClause.Flag("secret-key", "Your Google Cloud Platform account secret key. The private_key field in your service account authentication JSON.").Action(c.SecretKey.Set).StringVar(&c.SecretKey.Value)
c.CmdClause.Flag("template-suffix", "BigQuery table name suffix template").Action(c.Template.Set).StringVar(&c.Template.Value)
c.CmdClause.Flag("format", "Apache style log formatting. Must produce JSON that matches the schema of your BigQuery table").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 (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").Action(c.FormatVersion.Set).UintVar(&c.FormatVersion.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. This field is not required and has no default value").Action(c.Placement.Set).StringVar(&c.Placement.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)
common.Format(c.CmdClause, &c.Format)
common.FormatVersion(c.CmdClause, &c.FormatVersion)
common.Placement(c.CmdClause, &c.Placement)
common.ResponseCondition(c.CmdClause, &c.ResponseCondition)
return &c
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/commands/logging/cloudfiles/cloudfiles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func TestUpdateCloudfilesInput(t *testing.T) {
Region: fastly.String("new5"),
Placement: fastly.String("new6"),
Period: fastly.Uint(3601),
GzipLevel: fastly.Uint(0),
GzipLevel: fastly.Uint8(0),
Format: fastly.String("new7"),
FormatVersion: fastly.Uint(3),
ResponseCondition: fastly.String("new8"),
Expand Down Expand Up @@ -358,7 +358,7 @@ func updateCommandAll() *cloudfiles.UpdateCommand {
Region: cmd.OptionalString{Optional: cmd.Optional{WasSet: true}, Value: "new5"},
Placement: cmd.OptionalString{Optional: cmd.Optional{WasSet: true}, Value: "new6"},
Period: cmd.OptionalUint{Optional: cmd.Optional{WasSet: true}, Value: 3601},
GzipLevel: cmd.OptionalUint{Optional: cmd.Optional{WasSet: true}, Value: 0},
GzipLevel: cmd.OptionalUint8{Optional: cmd.Optional{WasSet: true}, Value: 0},
Format: cmd.OptionalString{Optional: cmd.Optional{WasSet: true}, Value: "new7"},
FormatVersion: cmd.OptionalUint{Optional: cmd.Optional{WasSet: true}, Value: 3},
ResponseCondition: cmd.OptionalString{Optional: cmd.Optional{WasSet: true}, Value: "new8"},
Expand Down
25 changes: 13 additions & 12 deletions pkg/commands/logging/cloudfiles/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io"

"github.com/fastly/cli/pkg/cmd"
"github.com/fastly/cli/pkg/commands/logging/common"
"github.com/fastly/cli/pkg/config"
"github.com/fastly/cli/pkg/errors"
"github.com/fastly/cli/pkg/manifest"
Expand Down Expand Up @@ -32,7 +33,7 @@ type CreateCommand struct {
Region cmd.OptionalString
PublicKey cmd.OptionalString
Period cmd.OptionalUint
GzipLevel cmd.OptionalUint
GzipLevel cmd.OptionalUint8
MessageType cmd.OptionalString
TimestampFormat cmd.OptionalString
Format cmd.OptionalString
Expand Down Expand Up @@ -74,18 +75,18 @@ func NewCreateCommand(parent cmd.Registerer, globals *config.Data, data manifest
Description: cmd.FlagServiceDesc,
Dst: &c.ServiceName.Value,
})
c.CmdClause.Flag("path", "The path to upload logs to").Action(c.Path.Set).StringVar(&c.Path.Value)
c.CmdClause.Flag("region", "The region to stream logs to. One of: DFW-Dallas, ORD-Chicago, IAD-Northern Virginia, LON-London, SYD-Sydney, HKG-Hong Kong").Action(c.Region.Set).StringVar(&c.Region.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)
c.CmdClause.Flag("period", "How frequently log files are finalized so they can be available for reading (in seconds, default 3600)").Action(c.Period.Set).UintVar(&c.Period.Value)
c.CmdClause.Flag("gzip-level", "What level of GZIP encoding to have when dumping logs (default 0, no compression)").Action(c.GzipLevel.Set).UintVar(&c.GzipLevel.Value)
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("message-type", "How the message should be formatted. One of: classic (default), loggly, logplex or blank").Action(c.MessageType.Set).StringVar(&c.MessageType.Value)
c.CmdClause.Flag("timestamp-format", `strftime specified timestamp formatting (default "%Y-%m-%dT%H:%M:%S.000")`).Action(c.TimestampFormat.Set).StringVar(&c.TimestampFormat.Value)
c.CmdClause.Flag("public-key", "A PGP public key that Fastly will use to encrypt your log files before writing them to disk").Action(c.PublicKey.Set).StringVar(&c.PublicKey.Value)
c.CmdClause.Flag("compression-codec", `The codec used for compression of your logs. Valid values are zstd, snappy, and gzip. If the specified codec is "gzip", gzip_level will default to 3. To specify a different level, leave compression_codec blank and explicitly set the level using gzip_level. Specifying both compression_codec and gzip_level in the same API request will result in an error.`).Action(c.CompressionCodec.Set).StringVar(&c.CompressionCodec.Value)
common.Path(c.CmdClause, &c.Path)
common.Placement(c.CmdClause, &c.Placement)
common.Period(c.CmdClause, &c.Period)
common.GzipLevel(c.CmdClause, &c.GzipLevel)
common.Format(c.CmdClause, &c.Format)
common.FormatVersion(c.CmdClause, &c.FormatVersion)
common.ResponseCondition(c.CmdClause, &c.ResponseCondition)
common.MessageType(c.CmdClause, &c.MessageType)
common.TimestampFormat(c.CmdClause, &c.TimestampFormat)
common.PublicKey(c.CmdClause, &c.PublicKey)
common.CompressionCodec(c.CmdClause, &c.CompressionCodec)
return &c
}

Expand Down
Loading