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

feat(ratelimiter): add uri-dict-name flag #892

Merged
merged 2 commits into from
Mar 31, 2023
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 @@ -29,7 +29,7 @@ require (
)

require (
github.com/fastly/go-fastly/v7 v7.5.2
github.com/fastly/go-fastly/v7 v7.5.5
github.com/kennygrant/sanitize v1.2.4
github.com/mholt/archiver v3.1.1+incompatible
github.com/otiai10/copy v1.9.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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.2 h1:6TfHEScwdP3ErhAZRcsh7VC55W1ssBML/nwvKWvOMOc=
github.com/fastly/go-fastly/v7 v7.5.2/go.mod h1:/Z2GD7NuxV3vVMAyrtckg1WvZVnCuM2Z8ok/z70XTEQ=
github.com/fastly/go-fastly/v7 v7.5.5 h1:M3ePbU6a8BTPZzjaPoU4+O+pQspiBalF5HgVNomHlJI=
github.com/fastly/go-fastly/v7 v7.5.5/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=
Expand Down
6 changes: 6 additions & 0 deletions pkg/commands/ratelimit/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ func NewCreateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *C
Description: cmd.FlagServiceDesc,
Dst: &c.serviceName.Value,
})
c.CmdClause.Flag("uri-dict-name", "The name of an Edge Dictionary containing URIs as keys").StringVar(&c.uriDictName)
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...)

return &c
Expand All @@ -117,6 +118,7 @@ type CreateCommand struct {
rpsLimit int
serviceName cmd.OptionalServiceNameID
serviceVersion cmd.OptionalServiceVersion
uriDictName string
windowSize string
}

Expand Down Expand Up @@ -236,6 +238,10 @@ func (c *CreateCommand) constructInput() *fastly.CreateERLInput {
input.RpsLimit = fastly.Int(c.rpsLimit)
}

if c.uriDictName != "" {
input.URIDictionaryName = fastly.String(c.uriDictName)
}

if c.windowSize != "" {
for _, w := range fastly.ERLWindowSizes {
if c.windowSize == fmt.Sprint(w) {
Expand Down
6 changes: 6 additions & 0 deletions pkg/commands/ratelimit/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func NewUpdateCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *U
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("uri-dict-name", "The name of an Edge Dictionary containing URIs as keys").StringVar(&c.uriDictName)
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...)

return &c
Expand All @@ -67,6 +68,7 @@ type UpdateCommand struct {
responseObjectName string
responseStatus int
rpsLimit int
uriDictName string
windowSize string
}

Expand Down Expand Up @@ -167,6 +169,10 @@ func (c *UpdateCommand) constructInput() *fastly.UpdateERLInput {
input.RpsLimit = fastly.Int(c.rpsLimit)
}

if c.uriDictName != "" {
input.URIDictionaryName = fastly.String(c.uriDictName)
}

// NOTE: rateLimitWindowSizes is defined in ./create.go
if c.windowSize != "" {
for _, w := range fastly.ERLWindowSizes {
Expand Down