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(products): Add support for Fastly Bot Management product. #1300

Merged
merged 1 commit into from
Aug 21, 2024
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 @@ -25,7 +25,7 @@ require (
)

require (
github.com/fastly/go-fastly/v9 v9.8.0
github.com/fastly/go-fastly/v9 v9.9.0
github.com/hashicorp/cap v0.7.0
github.com/kennygrant/sanitize v1.2.4
github.com/otiai10/copy v1.14.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,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-20231002161417-6a283f1aaaf2 h1:S6Dco8FtAhEI/qkg/00H6RdEGC+MCy5GPiQ+xweNRFE=
github.com/dustinkirkland/golang-petname v0.0.0-20231002161417-6a283f1aaaf2/go.mod h1:8AuBTZBRSFqEYBPYULd+NN474/zZBLP+6WeT5S9xlAc=
github.com/fastly/go-fastly/v9 v9.8.0 h1:15dtV3fmLlS/8wbdU3tBsW3Tb0Tj/gQrdS4v5mhtDDE=
github.com/fastly/go-fastly/v9 v9.8.0/go.mod h1:5w2jgJBZqQEebOwM/rRg7wutAcpDTziiMYWb/6qdM7U=
github.com/fastly/go-fastly/v9 v9.9.0 h1:VDCyORoWi608l/LBp+tY+qic3M5/5ZFw+rtAfV6VR9E=
github.com/fastly/go-fastly/v9 v9.9.0/go.mod h1:5w2jgJBZqQEebOwM/rRg7wutAcpDTziiMYWb/6qdM7U=
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/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
Expand Down
8 changes: 6 additions & 2 deletions pkg/commands/products/products_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func TestProductEnablement(t *testing.T) {
},
Args: "--service-id 123",
WantOutput: `PRODUCT ENABLED
bot_management false
brotli_compression false
domain_inspector false
fanout false
Expand All @@ -47,6 +48,7 @@ websockets false
},
Args: "--service-id 123",
WantOutput: `PRODUCT ENABLED
bot_management true
brotli_compression true
domain_inspector true
fanout true
Expand All @@ -58,12 +60,12 @@ websockets true
{
Name: "validate flag parsing error for enabling product",
Args: "--service-id 123 --enable foo",
WantError: "error parsing arguments: enum value must be one of brotli_compression,domain_inspector,fanout,image_optimizer,origin_inspector,websockets, got 'foo'",
WantError: "error parsing arguments: enum value must be one of bot_management,brotli_compression,domain_inspector,fanout,image_optimizer,origin_inspector,websockets, got 'foo'",
},
{
Name: "validate flag parsing error for disabling product",
Args: "--service-id 123 --disable foo",
WantError: "error parsing arguments: enum value must be one of brotli_compression,domain_inspector,fanout,image_optimizer,origin_inspector,websockets, got 'foo'",
WantError: "error parsing arguments: enum value must be one of bot_management,brotli_compression,domain_inspector,fanout,image_optimizer,origin_inspector,websockets, got 'foo'",
},
{
Name: "validate success for enabling product",
Expand Down Expand Up @@ -99,6 +101,7 @@ websockets true
},
Args: "--service-id 123 --json",
WantOutput: `{
"bot_management": false,
"brotli_compression": false,
"domain_inspector": false,
"fanout": false,
Expand All @@ -116,6 +119,7 @@ websockets true
},
Args: "--service-id 123 --json",
WantOutput: `{
"bot_management": true,
"brotli_compression": true,
"domain_inspector": true,
"fanout": true,
Expand Down
11 changes: 11 additions & 0 deletions pkg/commands/products/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type RootCommand struct {

// ProductEnablementOptions is a list of products that can be enabled/disabled.
var ProductEnablementOptions = []string{
"bot_management",
"brotli_compression",
"domain_inspector",
"fanout",
Expand Down Expand Up @@ -111,6 +112,12 @@ func (c *RootCommand) Exec(_ io.Reader, out io.Writer) error {

ps := ProductStatus{}

if _, err = ac.GetProduct(&fastly.ProductEnablementInput{
ProductID: fastly.ProductBotManagement,
ServiceID: serviceID,
}); err == nil {
ps.BotManagement = true
}
if _, err = ac.GetProduct(&fastly.ProductEnablementInput{
ProductID: fastly.ProductBrotliCompression,
ServiceID: serviceID,
Expand Down Expand Up @@ -154,6 +161,7 @@ func (c *RootCommand) Exec(_ io.Reader, out io.Writer) error {

t := text.NewTable(out)
t.AddHeader("PRODUCT", "ENABLED")
t.AddLine(fastly.ProductBotManagement, ps.BotManagement)
t.AddLine(fastly.ProductBrotliCompression, ps.BrotliCompression)
t.AddLine(fastly.ProductDomainInspector, ps.DomainInspector)
t.AddLine(fastly.ProductFanout, ps.Fanout)
Expand All @@ -166,6 +174,8 @@ func (c *RootCommand) Exec(_ io.Reader, out io.Writer) error {

func identifyProduct(product string) fastly.Product {
switch product {
case "bot_management":
return fastly.ProductBotManagement
case "brotli_compression":
return fastly.ProductBrotliCompression
case "domain_inspector":
Expand All @@ -185,6 +195,7 @@ func identifyProduct(product string) fastly.Product {

// ProductStatus indicates the status for each product.
type ProductStatus struct {
BotManagement bool `json:"bot_management"`
BrotliCompression bool `json:"brotli_compression"`
DomainInspector bool `json:"domain_inspector"`
Fanout bool `json:"fanout"`
Expand Down