Skip to content
Open
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
50 changes: 40 additions & 10 deletions pkg/commands/compute/setup/products.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
},
},
Expand Down
15 changes: 11 additions & 4 deletions pkg/manifest/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -134,16 +134,23 @@ 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
Mode string `toml:"mode,omitempty"`
}

var _ SetupProductSettings = (*SetupProductDDoSProtection)(nil)

type SetupProductNGWAF struct {
SetupProduct
WorkspaceID string `toml:"workspace_id,omitempty"`
}

var _ SetupProductSettings = (*SetupProductNGWAF)(nil)
3 changes: 3 additions & 0 deletions pkg/manifest/testdata/fastly-viceroy-update.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading