From f583a553bd1d98120f2b9f8a6ad6c28f53fdd922 Mon Sep 17 00:00:00 2001 From: Integralist Date: Thu, 30 Mar 2023 13:09:53 +0100 Subject: [PATCH 1/3] build(go-fastly): bump to latest v7.5.2 --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index f749ceca9..36eabf98d 100644 --- a/go.mod +++ b/go.mod @@ -29,7 +29,7 @@ require ( ) require ( - github.com/fastly/go-fastly/v7 v7.5.1 + github.com/fastly/go-fastly/v7 v7.5.2 github.com/kennygrant/sanitize v1.2.4 github.com/mholt/archiver v3.1.1+incompatible github.com/otiai10/copy v1.9.0 diff --git a/go.sum b/go.sum index c6c9152c2..74a7e5a41 100644 --- a/go.sum +++ b/go.sum @@ -18,8 +18,8 @@ github.com/dsnet/compress v0.0.2-0.20210315054119-f66993602bf5/go.mod h1:qssHWj6 github.com/dsnet/golib v0.0.0-20171103203638-1ea166775780/go.mod h1:Lj+Z9rebOhdfkVLjJ8T6VcRQv3SXugXy999NBtR9aFY= github.com/dustinkirkland/golang-petname v0.0.0-20191129215211-8e5a1ed0cff0 h1:90Ly+6UfUypEF6vvvW5rQIv9opIL8CbmW9FT20LDQoY= github.com/dustinkirkland/golang-petname v0.0.0-20191129215211-8e5a1ed0cff0/go.mod h1:V+Qd57rJe8gd4eiGzZyg4h54VLHmYVVw54iMnlAMrF8= -github.com/fastly/go-fastly/v7 v7.5.1 h1:BkuUTHGgpuxb8/EDYDmgxyMUwP4JZOSO7cYZQFFpc9A= -github.com/fastly/go-fastly/v7 v7.5.1/go.mod h1:/Z2GD7NuxV3vVMAyrtckg1WvZVnCuM2Z8ok/z70XTEQ= +github.com/fastly/go-fastly/v7 v7.5.2 h1:6TfHEScwdP3ErhAZRcsh7VC55W1ssBML/nwvKWvOMOc= +github.com/fastly/go-fastly/v7 v7.5.2/go.mod h1:/Z2GD7NuxV3vVMAyrtckg1WvZVnCuM2Z8ok/z70XTEQ= 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.14.1 h1:qfhVLaG5s+nCROl1zJsZRxFeYrHLqWroPOQ8BWiNb4w= From d60a3a982215c04f15a15a142cc3bbb5ad3f685b Mon Sep 17 00:00:00 2001 From: Integralist Date: Thu, 30 Mar 2023 13:15:57 +0100 Subject: [PATCH 2/3] refactor(ratelimit): replace custom vars with package vars --- pkg/commands/ratelimit/create.go | 71 +++----------------------------- pkg/commands/ratelimit/update.go | 6 +-- 2 files changed, 9 insertions(+), 68 deletions(-) diff --git a/pkg/commands/ratelimit/create.go b/pkg/commands/ratelimit/create.go index 557b39adc..e72978e20 100644 --- a/pkg/commands/ratelimit/create.go +++ b/pkg/commands/ratelimit/create.go @@ -15,87 +15,28 @@ import ( "github.com/fastly/go-fastly/v7/fastly" ) -// rateLimitActions is a list of supported actions. -// It is used to construct the API input. -// It is also used to construct input for the --action enum flag. -// We build the flag input dynamically so we can avoid hardcoding the values. -// This is in case the underlying values in go-fastly change between releases. -var rateLimitActions = []fastly.ERLAction{ - fastly.ERLActionLogOnly, - fastly.ERLActionResponse, - fastly.ERLActionResponseObject, -} - // rateLimitActionFlagOpts is a string representation of rateLimitActions // suitable for use within the enum flag definition below. var rateLimitActionFlagOpts = func() (actions []string) { - for _, a := range rateLimitActions { + for _, a := range fastly.ERLActions { actions = append(actions, string(a)) } return actions }() -// rateLimitLoggers is a list of supported logger types. -// It is used to construct the API input. -// It is also used to construct input for the --logger-type enum flag. -// We build the flag input dynamically so we can avoid hardcoding the values. -// This is in case the underlying values in go-fastly change between releases. -var rateLimitLoggers = []fastly.ERLLogger{ - fastly.ERLLogAzureBlob, - fastly.ERLLogBigQuery, - fastly.ERLLogCloudFiles, - fastly.ERLLogDataDog, - fastly.ERLLogDigitalOcean, - fastly.ERLLogElasticSearch, - fastly.ERLLogFtp, - fastly.ERLLogGcs, - fastly.ERLLogGoogleAnalytics, - fastly.ERLLogHeroku, - fastly.ERLLogHoneycomb, - fastly.ERLLogHTTP, - fastly.ERLLogHTTPS, - fastly.ERLLogKafta, - fastly.ERLLogKinesis, - fastly.ERLLogLogEntries, - fastly.ERLLogLoggly, - fastly.ERLLogLogShuttle, - fastly.ERLLogNewRelic, - fastly.ERLLogOpenStack, - fastly.ERLLogPaperTrail, - fastly.ERLLogPubSub, - fastly.ERLLogS3, - fastly.ERLLogScalyr, - fastly.ERLLogSftp, - fastly.ERLLogSplunk, - fastly.ERLLogStackDriver, - fastly.ERLLogSumoLogic, - fastly.ERLLogSysLog, -} - // rateLimitLoggerFlagOpts is a string representation of rateLimitLoggers // suitable for use within the enum flag definition below. var rateLimitLoggerFlagOpts = func() (loggers []string) { - for _, l := range rateLimitLoggers { + for _, l := range fastly.ERLLoggers { loggers = append(loggers, string(l)) } return loggers }() -// rateLimitWindowSizes is a list of supported time window sizes. -// It is used to construct the API input. -// It is also used to construct input for the --window-size enum flag. -// We build the flag input dynamically so we can avoid hardcoding the values. -// This is in case the underlying values in go-fastly change between releases. -var rateLimitWindowSizes = []fastly.ERLWindowSize{ - fastly.ERLSize1, - fastly.ERLSize10, - fastly.ERLSize60, -} - // rateLimitWindowSizeFlagOpts is a string representation of rateLimitWindowSizes // suitable for use within the enum flag definition below. var rateLimitWindowSizeFlagOpts = func() (windowSizes []string) { - for _, w := range rateLimitWindowSizes { + for _, w := range fastly.ERLWindowSizes { windowSizes = append(windowSizes, fmt.Sprint(w)) } return windowSizes @@ -236,7 +177,7 @@ func (c *CreateCommand) constructInput() *fastly.CreateERLInput { var input fastly.CreateERLInput if c.action != "" { - for _, a := range rateLimitActions { + for _, a := range fastly.ERLActions { if c.action == string(a) { input.Action = fastly.ERLActionPtr(a) break @@ -255,7 +196,7 @@ func (c *CreateCommand) constructInput() *fastly.CreateERLInput { } if c.loggerType != "" { - for _, l := range rateLimitLoggers { + for _, l := range fastly.ERLLoggers { if c.loggerType == string(l) { input.LoggerType = fastly.ERLLoggerPtr(l) break @@ -284,7 +225,7 @@ func (c *CreateCommand) constructInput() *fastly.CreateERLInput { } if c.windowSize != "" { - for _, w := range rateLimitWindowSizes { + for _, w := range fastly.ERLWindowSizes { if c.windowSize == fmt.Sprint(w) { input.WindowSize = fastly.ERLWindowSizePtr(w) break diff --git a/pkg/commands/ratelimit/update.go b/pkg/commands/ratelimit/update.go index d462ad658..5d83d162c 100644 --- a/pkg/commands/ratelimit/update.go +++ b/pkg/commands/ratelimit/update.go @@ -107,7 +107,7 @@ func (c *UpdateCommand) constructInput() *fastly.UpdateERLInput { // NOTE: rateLimitActions is defined in ./create.go if c.action != "" { - for _, a := range rateLimitActions { + for _, a := range fastly.ERLActions { if c.action == string(a) { input.Action = fastly.ERLActionPtr(a) break @@ -127,7 +127,7 @@ func (c *UpdateCommand) constructInput() *fastly.UpdateERLInput { // NOTE: rateLimitLoggers is defined in ./create.go if c.loggerType != "" { - for _, l := range rateLimitLoggers { + for _, l := range fastly.ERLLoggers { if c.loggerType == string(l) { input.LoggerType = fastly.ERLLoggerPtr(l) break @@ -157,7 +157,7 @@ func (c *UpdateCommand) constructInput() *fastly.UpdateERLInput { // NOTE: rateLimitWindowSizes is defined in ./create.go if c.windowSize != "" { - for _, w := range rateLimitWindowSizes { + for _, w := range fastly.ERLWindowSizes { if c.windowSize == fmt.Sprint(w) { input.WindowSize = fastly.ERLWindowSizePtr(w) break From 8d599e488895d1502190294e754fd2ac77c90d6e Mon Sep 17 00:00:00 2001 From: Integralist Date: Thu, 30 Mar 2023 13:39:40 +0100 Subject: [PATCH 3/3] feat(ratelimit): add missing properties --- pkg/commands/ratelimit/create.go | 12 ++++++++++++ pkg/commands/ratelimit/update.go | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/pkg/commands/ratelimit/create.go b/pkg/commands/ratelimit/create.go index e72978e20..8108906d5 100644 --- a/pkg/commands/ratelimit/create.go +++ b/pkg/commands/ratelimit/create.go @@ -68,6 +68,7 @@ func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *C Dst: &c.autoClone.Value, }) c.CmdClause.Flag("client-key", "Comma-separated list of VCL variable used to generate a counter key to identify a client").StringVar(&c.clientKeys) + c.CmdClause.Flag("feature-revision", "Revision number of the rate limiting feature implementation").IntVar(&c.featRevision) c.CmdClause.Flag("http-methods", "Comma-separated list of HTTP methods to apply rate limiting to").StringVar(&c.httpMethods) c.RegisterFlagBool(c.JSONFlag()) // --json c.CmdClause.Flag("logger-type", "Name of the type of logging endpoint to be used when action is `log_only`").HintOptions(rateLimitLoggerFlagOpts...).EnumVar(&c.loggerType, rateLimitLoggerFlagOpts...) @@ -75,6 +76,7 @@ func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *C c.CmdClause.Flag("penalty-box-dur", "Length of time in minutes that the rate limiter is in effect after the initial violation is detected").IntVar(&c.penaltyDuration) c.CmdClause.Flag("response-content", "HTTP response body data").StringVar(&c.responseContent) c.CmdClause.Flag("response-content-type", "HTTP Content-Type (e.g. application/json)").StringVar(&c.responseContentType) + c.CmdClause.Flag("response-object-name", "Name of existing response object. Required if action is response_object").StringVar(&c.responseObjectName) c.CmdClause.Flag("response-status", "HTTP response status code (e.g. 429)").IntVar(&c.responseStatus) c.CmdClause.Flag("rps-limit", "Upper limit of requests per second allowed by the rate limiter").IntVar(&c.rpsLimit) c.RegisterFlag(cmd.StringFlagOpts{ @@ -102,6 +104,7 @@ type CreateCommand struct { action string autoClone cmd.OptionalAutoClone clientKeys string + featRevision int httpMethods string loggerType string manifest manifest.Data @@ -109,6 +112,7 @@ type CreateCommand struct { penaltyDuration int responseContent string responseContentType string + responseObjectName string responseStatus int rpsLimit int serviceName cmd.OptionalServiceNameID @@ -190,6 +194,10 @@ func (c *CreateCommand) constructInput() *fastly.CreateERLInput { input.ClientKey = &clientKeys } + if c.featRevision > 0 { + input.FeatureRevision = fastly.Int(c.featRevision) + } + if c.httpMethods != "" { httpMethods := strings.Split(strings.ReplaceAll(c.httpMethods, " ", ""), ",") input.HTTPMethods = &httpMethods @@ -220,6 +228,10 @@ func (c *CreateCommand) constructInput() *fastly.CreateERLInput { } } + if c.responseObjectName != "" { + input.ResponseObjectName = fastly.String(c.responseObjectName) + } + if c.rpsLimit > 0 { input.RpsLimit = fastly.Int(c.rpsLimit) } diff --git a/pkg/commands/ratelimit/update.go b/pkg/commands/ratelimit/update.go index 5d83d162c..5dd0e9659 100644 --- a/pkg/commands/ratelimit/update.go +++ b/pkg/commands/ratelimit/update.go @@ -32,6 +32,7 @@ func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *U // Optional. c.CmdClause.Flag("action", "The action to take when a rate limiter violation is detected").HintOptions(rateLimitActionFlagOpts...).EnumVar(&c.action, rateLimitActionFlagOpts...) c.CmdClause.Flag("client-key", "Comma-separated list of VCL variable used to generate a counter key to identify a client").StringVar(&c.clientKeys) + c.CmdClause.Flag("feature-revision", "Revision number of the rate limiting feature implementation").IntVar(&c.featRevision) c.CmdClause.Flag("http-methods", "Comma-separated list of HTTP methods to apply rate limiting to").StringVar(&c.httpMethods) c.RegisterFlagBool(c.JSONFlag()) // --json c.CmdClause.Flag("logger-type", "Name of the type of logging endpoint to be used when action is `log_only`").HintOptions(rateLimitLoggerFlagOpts...).EnumVar(&c.loggerType, rateLimitLoggerFlagOpts...) @@ -39,6 +40,7 @@ func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *U c.CmdClause.Flag("penalty-box-dur", "Length of time in minutes that the rate limiter is in effect after the initial violation is detected").IntVar(&c.penaltyDuration) c.CmdClause.Flag("response-content", "HTTP response body data").StringVar(&c.responseContent) c.CmdClause.Flag("response-content-type", "HTTP Content-Type (e.g. application/json)").StringVar(&c.responseContentType) + c.CmdClause.Flag("response-object-name", "Name of existing response object. Required if action is response_object").StringVar(&c.responseObjectName) c.CmdClause.Flag("response-status", "HTTP response status code (e.g. 429)").IntVar(&c.responseStatus) c.CmdClause.Flag("rps-limit", "Upper limit of requests per second allowed by the rate limiter").IntVar(&c.rpsLimit) c.CmdClause.Flag("window-size", "Number of seconds during which the RPS limit must be exceeded in order to trigger a violation").HintOptions(rateLimitWindowSizeFlagOpts...).EnumVar(&c.windowSize, rateLimitWindowSizeFlagOpts...) @@ -53,6 +55,7 @@ type UpdateCommand struct { action string clientKeys string + featRevision int httpMethods string id string loggerType string @@ -61,6 +64,7 @@ type UpdateCommand struct { penaltyDuration int responseContent string responseContentType string + responseObjectName string responseStatus int rpsLimit int windowSize string @@ -120,6 +124,10 @@ func (c *UpdateCommand) constructInput() *fastly.UpdateERLInput { input.ClientKey = &clientKeys } + if c.featRevision > 0 { + input.FeatureRevision = fastly.Int(c.featRevision) + } + if c.httpMethods != "" { httpMethods := strings.Split(strings.ReplaceAll(c.httpMethods, " ", ""), ",") input.HTTPMethods = &httpMethods @@ -151,6 +159,10 @@ func (c *UpdateCommand) constructInput() *fastly.UpdateERLInput { } } + if c.responseObjectName != "" { + input.ResponseObjectName = fastly.String(c.responseObjectName) + } + if c.rpsLimit > 0 { input.RpsLimit = fastly.Int(c.rpsLimit) }