diff --git a/pkg/commands/compute/setup/products.go b/pkg/commands/compute/setup/products.go index 16de72883..7950f0362 100644 --- a/pkg/commands/compute/setup/products.go +++ b/pkg/commands/compute/setup/products.go @@ -80,19 +80,19 @@ func (p *Product) Enabled() bool { return p != nil && p.Enable } -type ProductNGWAF struct { +type ProductBotManagement struct { Product - WorkspaceID string + ContentGuard string } -func NewProductNGWAF(workspaceID string) *ProductNGWAF { - return &ProductNGWAF{ - Product: *NewProductEnabled(), - WorkspaceID: workspaceID, +func NewProductBotManagement(contentGuard string) *ProductBotManagement { + return &ProductBotManagement{ + Product: *NewProductEnabled(), + ContentGuard: contentGuard, } } -var _ ProductSettings = (*ProductNGWAF)(nil) +var _ ProductSettings = (*ProductBotManagement)(nil) type ProductDDoSProtection struct { Product @@ -108,6 +108,20 @@ func NewProductDDoSProtection(mode string) *ProductDDoSProtection { var _ ProductSettings = (*ProductDDoSProtection)(nil) +type ProductNGWAF struct { + Product + WorkspaceID string +} + +func NewProductNGWAF(workspaceID string) *ProductNGWAF { + return &ProductNGWAF{ + Product: *NewProductEnabled(), + WorkspaceID: workspaceID, + } +} + +var _ ProductSettings = (*ProductNGWAF)(nil) + type productsSpec struct { id string name string @@ -145,15 +159,31 @@ func init() { getSetupProduct: func(setupProducts *manifest.SetupProducts) manifest.SetupProductSettings { return setupProducts.BotManagement }, - configure: func(_ io.Writer, p *ProductsMap, _ manifest.SetupProductSettings) error { - p.BotManagement = NewProductEnabled() + configure: func(w io.Writer, p *ProductsMap, sp manifest.SetupProductSettings) error { + botManagementSetupProduct, ok := sp.(*manifest.SetupProductBotManagement) + if !ok { + return fmt.Errorf("unexpected: Incorrect type for setupProduct") + } + if strings.TrimSpace(botManagementSetupProduct.ContentGuard) == "" { + return fmt.Errorf("contentguard is required") + } + text.Output(w, " contentguard: %s", botManagementSetupProduct.ContentGuard) + p.BotManagement = NewProductBotManagement(botManagementSetupProduct.ContentGuard) return nil }, getConfiguredProduct: func(products *ProductsMap) ProductSettings { return products.BotManagement }, - enable: func(fc *fastly.Client, _ ProductSettings, serviceID string) error { + enable: func(fc *fastly.Client, product ProductSettings, serviceID string) error { + botManagementProduct, ok := product.(*ProductBotManagement) + if !ok { + return fmt.Errorf("unexpected: Incorrect type for product") + } _, err := botmanagement.Enable(context.TODO(), fc, serviceID) + if err != nil { + return fmt.Errorf("unexpected: Unable to Enable product") + } + _, err = botmanagement.UpdateConfiguration(context.TODO(), fc, serviceID, botmanagement.ConfigureInput{ContentGuard: botManagementProduct.ContentGuard}) return err }, }, diff --git a/pkg/manifest/setup.go b/pkg/manifest/setup.go index f6fd7ae09..c5bd2b117 100644 --- a/pkg/manifest/setup.go +++ b/pkg/manifest/setup.go @@ -94,7 +94,7 @@ type SetupSecretStoreEntry struct { type SetupProducts struct { APIDiscovery *SetupProduct `toml:"api_discovery,omitempty"` - BotManagement *SetupProduct `toml:"bot_management,omitempty"` + BotManagement *SetupProductBotManagement `toml:"bot_management,omitempty"` BrotliCompression *SetupProduct `toml:"brotli_compression,omitempty"` DDoSProtection *SetupProductDDoSProtection `toml:"ddos_protection,omitempty"` DomainInspector *SetupProduct `toml:"domain_inspector,omitempty"` @@ -134,12 +134,12 @@ func (p *SetupProduct) Enabled() bool { return p != nil && p.Enable } -type SetupProductNGWAF struct { +type SetupProductBotManagement struct { SetupProduct - WorkspaceID string `toml:"workspace_id,omitempty"` + ContentGuard string `toml:"contentguard,omitempty"` } -var _ SetupProductSettings = (*SetupProductNGWAF)(nil) +var _ SetupProductSettings = (*SetupProductBotManagement)(nil) type SetupProductDDoSProtection struct { SetupProduct @@ -147,3 +147,10 @@ type SetupProductDDoSProtection struct { } var _ SetupProductSettings = (*SetupProductDDoSProtection)(nil) + +type SetupProductNGWAF struct { + SetupProduct + WorkspaceID string `toml:"workspace_id,omitempty"` +} + +var _ SetupProductSettings = (*SetupProductNGWAF)(nil) diff --git a/pkg/manifest/testdata/fastly-viceroy-update.toml b/pkg/manifest/testdata/fastly-viceroy-update.toml index 3a561c8c7..405fdc807 100644 --- a/pkg/manifest/testdata/fastly-viceroy-update.toml +++ b/pkg/manifest/testdata/fastly-viceroy-update.toml @@ -78,6 +78,9 @@ env = "ENV_FOURTH" [setup] [setup.products] +[setup.products.bot_management] +enable = true +contentguard = "on" [setup.products.ddos_protection] enable = true mode = "log"