Skip to content

Commit b8eeffa

Browse files
committed
Remaining enableable products except NGWAF.
1 parent f0d3db5 commit b8eeffa

66 files changed

Lines changed: 1407 additions & 29 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

internal/productcore/base.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ type Base struct {
1414
Manifest manifest.Data
1515

1616
ServiceName argparser.OptionalServiceNameID
17+
ProductID string
1718
ProductName string
1819
}
1920

2021
// Init prepares the structure for use by the CLI core.
21-
func (cmd *Base) Init(parent argparser.Registerer, g *global.Data, productName string) {
22+
func (cmd *Base) Init(parent argparser.Registerer, g *global.Data, productID, productName string) {
2223
cmd.Globals = g
24+
cmd.ProductID = productID
2325
cmd.ProductName = productName
2426

2527
// Optional flags.
@@ -41,7 +43,8 @@ func (cmd *Base) Init(parent argparser.Registerer, g *global.Data, productName s
4143
// EnablementStatus is a structure used to generate JSON output from
4244
// the enablement-related commands
4345
type EnablementStatus struct {
44-
Enabled bool `json:"enabled"`
46+
ProductID string `json:"product_id"`
47+
Enabled bool `json:"enabled"`
4548
}
4649

4750
// EnablementHookFuncs is a structure of dependency-injection points

internal/productcore/disable.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ type Disable[O any] struct {
1717
}
1818

1919
// Init prepares the structure for use by the CLI core.
20-
func (cmd *Disable[O]) Init(parent argparser.Registerer, g *global.Data, productName string, hooks *EnablementHookFuncs[O]) {
20+
func (cmd *Disable[O]) Init(parent argparser.Registerer, g *global.Data, productID, productName string, hooks *EnablementHookFuncs[O]) {
2121
cmd.CmdClause = parent.Command("disable", "Disable the "+productName+" product")
2222
cmd.hooks = hooks
2323

24-
cmd.Base.Init(parent, g, productName)
24+
cmd.Base.Init(parent, g, productID, productName)
2525
}
2626

2727
// Exec executes the disablement operation.
@@ -46,7 +46,7 @@ func (cmd *Disable[O]) Exec(out io.Writer) error {
4646
return err
4747
}
4848

49-
if ok, err := cmd.WriteJSON(out, EnablementStatus{Enabled: false}); ok {
49+
if ok, err := cmd.WriteJSON(out, EnablementStatus{ProductID: cmd.ProductID, Enabled: false}); ok {
5050
return err
5151
}
5252

internal/productcore/enable.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ type Enable[O any] struct {
1616
}
1717

1818
// Init prepares the structure for use by the CLI core.
19-
func (cmd *Enable[O]) Init(parent argparser.Registerer, g *global.Data, productName string, hooks *EnablementHookFuncs[O]) {
19+
func (cmd *Enable[O]) Init(parent argparser.Registerer, g *global.Data, productID, productName string, hooks *EnablementHookFuncs[O]) {
2020
cmd.CmdClause = parent.Command("enable", "Enable the "+productName+" product")
2121
cmd.hooks = hooks
2222

23-
cmd.Base.Init(parent, g, productName)
23+
cmd.Base.Init(parent, g, productID, productName)
2424
}
2525

2626
// Exec executes the enablement operation.
@@ -45,7 +45,7 @@ func (cmd *Enable[O]) Exec(out io.Writer) error {
4545
return err
4646
}
4747

48-
if ok, err := cmd.WriteJSON(out, EnablementStatus{Enabled: true}); ok {
48+
if ok, err := cmd.WriteJSON(out, EnablementStatus{ProductID: cmd.ProductID, Enabled: true}); ok {
4949
return err
5050
}
5151

internal/productcore/status.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ type Status[O any] struct {
1818
}
1919

2020
// Init prepares the structure for use by the CLI core.
21-
func (cmd *Status[O]) Init(parent argparser.Registerer, g *global.Data, productName string, hooks *EnablementHookFuncs[O]) {
21+
func (cmd *Status[O]) Init(parent argparser.Registerer, g *global.Data, productID, productName string, hooks *EnablementHookFuncs[O]) {
2222
cmd.CmdClause = parent.Command("status", "Get the enablement status of the "+productName+" product")
2323
cmd.hooks = hooks
2424

25-
cmd.Base.Init(parent, g, productName)
25+
cmd.Base.Init(parent, g, productID, productName)
2626
}
2727

2828
// Exec executes the status operation.
@@ -41,7 +41,7 @@ func (cmd *Status[O]) Exec(out io.Writer) error {
4141
argparser.DisplayServiceID(serviceID, flag, source, out)
4242
}
4343

44-
s := EnablementStatus{}
44+
s := EnablementStatus{ProductID: cmd.ProductID}
4545
state := "disabled"
4646

4747
_, err = cmd.hooks.GetFunc(cmd.Globals.APIClient, serviceID)

internal/productcore_test/enablement.go

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,17 @@ import (
1111
"github.com/fastly/cli/pkg/testutil"
1212
)
1313

14+
// TestEnablementInput supplies the details required for
15+
// TestEnablement to execute a series of test scenarios.
1416
type TestEnablementInput[O any] struct {
1517
T *testing.T
1618
Commands []string
19+
ProductID string
1720
ProductName string
1821
Hooks *productcore.EnablementHookFuncs[O]
1922
}
2023

24+
// TestEnablement executes the test scenarios common to all products.
2125
func TestEnablement[O any](i TestEnablementInput[O]) {
2226
scenarios := []testutil.CLIScenario{
2327
{
@@ -52,7 +56,7 @@ func TestEnablement[O any](i TestEnablementInput[O]) {
5256
},
5357
{
5458
Name: "validate text output success for enabling product",
55-
Setup: func(t *testing.T, scenario *testutil.CLIScenario, opts *global.Data) {
59+
Setup: func(_ *testing.T, _ *testutil.CLIScenario, _ *global.Data) {
5660
i.Hooks.EnableFunc = func(_ api.Interface, _ string) (o O, err error) {
5761
return
5862
}
@@ -62,17 +66,17 @@ func TestEnablement[O any](i TestEnablementInput[O]) {
6266
},
6367
{
6468
Name: "validate JSON output success for enabling product",
65-
Setup: func(t *testing.T, scenario *testutil.CLIScenario, opts *global.Data) {
69+
Setup: func(_ *testing.T, _ *testutil.CLIScenario, _ *global.Data) {
6670
i.Hooks.EnableFunc = func(_ api.Interface, _ string) (o O, err error) {
6771
return
6872
}
6973
},
7074
Args: "enable --service-id 123 --json",
71-
WantOutput: "{\n \"enabled\": true\n}",
75+
WantOutput: "{\n \"product_id\": \"" + i.ProductID + "\",\n \"enabled\": true\n}",
7276
},
7377
{
7478
Name: "validate failure for enabling product",
75-
Setup: func(t *testing.T, scenario *testutil.CLIScenario, opts *global.Data) {
79+
Setup: func(_ *testing.T, _ *testutil.CLIScenario, _ *global.Data) {
7680
i.Hooks.EnableFunc = func(_ api.Interface, _ string) (o O, err error) {
7781
err = testutil.Err
7882
return
@@ -83,7 +87,7 @@ func TestEnablement[O any](i TestEnablementInput[O]) {
8387
},
8488
{
8589
Name: "validate text output success for disabling product",
86-
Setup: func(t *testing.T, scenario *testutil.CLIScenario, opts *global.Data) {
90+
Setup: func(_ *testing.T, _ *testutil.CLIScenario, _ *global.Data) {
8791
i.Hooks.DisableFunc = func(_ api.Interface, _ string) error {
8892
return nil
8993
}
@@ -93,17 +97,17 @@ func TestEnablement[O any](i TestEnablementInput[O]) {
9397
},
9498
{
9599
Name: "validate JSON output success for disabling product",
96-
Setup: func(t *testing.T, scenario *testutil.CLIScenario, opts *global.Data) {
100+
Setup: func(_ *testing.T, _ *testutil.CLIScenario, _ *global.Data) {
97101
i.Hooks.DisableFunc = func(_ api.Interface, _ string) error {
98102
return nil
99103
}
100104
},
101105
Args: "disable --service-id 123 --json",
102-
WantOutput: "{\n \"enabled\": false\n}",
106+
WantOutput: "{\n \"product_id\": \"" + i.ProductID + "\",\n \"enabled\": false\n}",
103107
},
104108
{
105109
Name: "validate failure for disabling product",
106-
Setup: func(t *testing.T, scenario *testutil.CLIScenario, opts *global.Data) {
110+
Setup: func(_ *testing.T, _ *testutil.CLIScenario, _ *global.Data) {
107111
i.Hooks.DisableFunc = func(_ api.Interface, _ string) error {
108112
return testutil.Err
109113
}
@@ -113,7 +117,7 @@ func TestEnablement[O any](i TestEnablementInput[O]) {
113117
},
114118
{
115119
Name: "validate text status output for enabled product",
116-
Setup: func(t *testing.T, scenario *testutil.CLIScenario, opts *global.Data) {
120+
Setup: func(_ *testing.T, _ *testutil.CLIScenario, _ *global.Data) {
117121
i.Hooks.GetFunc = func(_ api.Interface, _ string) (o O, err error) {
118122
return
119123
}
@@ -123,17 +127,17 @@ func TestEnablement[O any](i TestEnablementInput[O]) {
123127
},
124128
{
125129
Name: "validate JSON status output for enabled product",
126-
Setup: func(t *testing.T, scenario *testutil.CLIScenario, opts *global.Data) {
130+
Setup: func(_ *testing.T, _ *testutil.CLIScenario, _ *global.Data) {
127131
i.Hooks.GetFunc = func(_ api.Interface, _ string) (o O, err error) {
128132
return
129133
}
130134
},
131135
Args: "status --service-id 123 --json",
132-
WantOutput: "{\n \"enabled\": true\n}",
136+
WantOutput: "{\n \"product_id\": \"" + i.ProductID + "\",\n \"enabled\": true\n}",
133137
},
134138
{
135139
Name: "validate text status output for disabled product",
136-
Setup: func(t *testing.T, scenario *testutil.CLIScenario, opts *global.Data) {
140+
Setup: func(_ *testing.T, _ *testutil.CLIScenario, _ *global.Data) {
137141
i.Hooks.GetFunc = func(_ api.Interface, _ string) (o O, err error) {
138142
// The API returns a 'Bad Request' error when the
139143
// product has not been enabled on the service
@@ -146,7 +150,7 @@ func TestEnablement[O any](i TestEnablementInput[O]) {
146150
},
147151
{
148152
Name: "validate JSON status output for disabled product",
149-
Setup: func(t *testing.T, scenario *testutil.CLIScenario, opts *global.Data) {
153+
Setup: func(_ *testing.T, _ *testutil.CLIScenario, _ *global.Data) {
150154
i.Hooks.GetFunc = func(_ api.Interface, _ string) (o O, err error) {
151155
// The API returns a 'Bad Request' error when the
152156
// product has not been enabled on the service
@@ -155,7 +159,7 @@ func TestEnablement[O any](i TestEnablementInput[O]) {
155159
}
156160
},
157161
Args: "status --service-id 123 --json",
158-
WantOutput: "{\n \"enabled\": false\n}",
162+
WantOutput: "{\n \"product_id\": \"" + i.ProductID + "\",\n \"enabled\": false\n}",
159163
},
160164
}
161165

pkg/commands/commands.go

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ import (
6060
"github.com/fastly/cli/pkg/commands/pop"
6161
"github.com/fastly/cli/pkg/commands/product"
6262
"github.com/fastly/cli/pkg/commands/product/botmanagement"
63+
"github.com/fastly/cli/pkg/commands/product/brotlicompression"
64+
"github.com/fastly/cli/pkg/commands/product/ddosprotection"
65+
"github.com/fastly/cli/pkg/commands/product/domaininspector"
66+
"github.com/fastly/cli/pkg/commands/product/fanout"
67+
"github.com/fastly/cli/pkg/commands/product/imageoptimizer"
68+
"github.com/fastly/cli/pkg/commands/product/logexplorerinsights"
69+
"github.com/fastly/cli/pkg/commands/product/origininspector"
70+
"github.com/fastly/cli/pkg/commands/product/websockets"
6371
"github.com/fastly/cli/pkg/commands/products"
6472
"github.com/fastly/cli/pkg/commands/profile"
6573
"github.com/fastly/cli/pkg/commands/purge"
@@ -401,11 +409,53 @@ func Define( // nolint:revive // function-length
401409
objectStorageAccesskeysGet := accesskeys.NewGetCommand(objectStorageAccesskeysRoot.CmdClause, data)
402410
objectStorageAccesskeysList := accesskeys.NewListCommand(objectStorageAccesskeysRoot.CmdClause, data)
403411
popCmdRoot := pop.NewRootCommand(app, data)
412+
404413
productCmdRoot := product.NewRootCommand(app, data)
405414
productBotManagementCmdRoot := botmanagement.NewRootCommand(productCmdRoot.CmdClause, data)
406415
productBotManagementDisable := botmanagement.NewDisableCommand(productBotManagementCmdRoot.CmdClause, data)
407416
productBotManagementEnable := botmanagement.NewEnableCommand(productBotManagementCmdRoot.CmdClause, data)
408417
productBotManagementStatus := botmanagement.NewStatusCommand(productBotManagementCmdRoot.CmdClause, data)
418+
419+
productBrotliCompressionCmdRoot := brotlicompression.NewRootCommand(productCmdRoot.CmdClause, data)
420+
productBrotliCompressionDisable := brotlicompression.NewDisableCommand(productBrotliCompressionCmdRoot.CmdClause, data)
421+
productBrotliCompressionEnable := brotlicompression.NewEnableCommand(productBrotliCompressionCmdRoot.CmdClause, data)
422+
productBrotliCompressionStatus := brotlicompression.NewStatusCommand(productBrotliCompressionCmdRoot.CmdClause, data)
423+
424+
productDDoSProtectionCmdRoot := ddosprotection.NewRootCommand(productCmdRoot.CmdClause, data)
425+
productDDoSProtectionDisable := ddosprotection.NewDisableCommand(productDDoSProtectionCmdRoot.CmdClause, data)
426+
productDDoSProtectionEnable := ddosprotection.NewEnableCommand(productDDoSProtectionCmdRoot.CmdClause, data)
427+
productDDoSProtectionStatus := ddosprotection.NewStatusCommand(productDDoSProtectionCmdRoot.CmdClause, data)
428+
429+
productDomainInspectorCmdRoot := domaininspector.NewRootCommand(productCmdRoot.CmdClause, data)
430+
productDomainInspectorDisable := domaininspector.NewDisableCommand(productDomainInspectorCmdRoot.CmdClause, data)
431+
productDomainInspectorEnable := domaininspector.NewEnableCommand(productDomainInspectorCmdRoot.CmdClause, data)
432+
productDomainInspectorStatus := domaininspector.NewStatusCommand(productDomainInspectorCmdRoot.CmdClause, data)
433+
434+
productFanoutCmdRoot := fanout.NewRootCommand(productCmdRoot.CmdClause, data)
435+
productFanoutDisable := fanout.NewDisableCommand(productFanoutCmdRoot.CmdClause, data)
436+
productFanoutEnable := fanout.NewEnableCommand(productFanoutCmdRoot.CmdClause, data)
437+
productFanoutStatus := fanout.NewStatusCommand(productFanoutCmdRoot.CmdClause, data)
438+
439+
productImageOptimizerCmdRoot := imageoptimizer.NewRootCommand(productCmdRoot.CmdClause, data)
440+
productImageOptimizerDisable := imageoptimizer.NewDisableCommand(productImageOptimizerCmdRoot.CmdClause, data)
441+
productImageOptimizerEnable := imageoptimizer.NewEnableCommand(productImageOptimizerCmdRoot.CmdClause, data)
442+
productImageOptimizerStatus := imageoptimizer.NewStatusCommand(productImageOptimizerCmdRoot.CmdClause, data)
443+
444+
productLogExplorerInsightsCmdRoot := logexplorerinsights.NewRootCommand(productCmdRoot.CmdClause, data)
445+
productLogExplorerInsightsDisable := logexplorerinsights.NewDisableCommand(productLogExplorerInsightsCmdRoot.CmdClause, data)
446+
productLogExplorerInsightsEnable := logexplorerinsights.NewEnableCommand(productLogExplorerInsightsCmdRoot.CmdClause, data)
447+
productLogExplorerInsightsStatus := logexplorerinsights.NewStatusCommand(productLogExplorerInsightsCmdRoot.CmdClause, data)
448+
449+
productOriginInspectorCmdRoot := origininspector.NewRootCommand(productCmdRoot.CmdClause, data)
450+
productOriginInspectorDisable := origininspector.NewDisableCommand(productOriginInspectorCmdRoot.CmdClause, data)
451+
productOriginInspectorEnable := origininspector.NewEnableCommand(productOriginInspectorCmdRoot.CmdClause, data)
452+
productOriginInspectorStatus := origininspector.NewStatusCommand(productOriginInspectorCmdRoot.CmdClause, data)
453+
454+
productWebSocketsCmdRoot := websockets.NewRootCommand(productCmdRoot.CmdClause, data)
455+
productWebSocketsDisable := websockets.NewDisableCommand(productWebSocketsCmdRoot.CmdClause, data)
456+
productWebSocketsEnable := websockets.NewEnableCommand(productWebSocketsCmdRoot.CmdClause, data)
457+
productWebSocketsStatus := websockets.NewStatusCommand(productWebSocketsCmdRoot.CmdClause, data)
458+
409459
productsCmdRoot := products.NewRootCommand(app, data)
410460
profileCmdRoot := profile.NewRootCommand(app, data)
411461
profileCreate := profile.NewCreateCommand(profileCmdRoot.CmdClause, data, ssoCmdRoot)
@@ -829,6 +879,38 @@ func Define( // nolint:revive // function-length
829879
productBotManagementDisable,
830880
productBotManagementEnable,
831881
productBotManagementStatus,
882+
productBrotliCompressionCmdRoot,
883+
productBrotliCompressionDisable,
884+
productBrotliCompressionEnable,
885+
productBrotliCompressionStatus,
886+
productDDoSProtectionCmdRoot,
887+
productDDoSProtectionDisable,
888+
productDDoSProtectionEnable,
889+
productDDoSProtectionStatus,
890+
productDomainInspectorCmdRoot,
891+
productDomainInspectorDisable,
892+
productDomainInspectorEnable,
893+
productDomainInspectorStatus,
894+
productFanoutCmdRoot,
895+
productFanoutDisable,
896+
productFanoutEnable,
897+
productFanoutStatus,
898+
productImageOptimizerCmdRoot,
899+
productImageOptimizerDisable,
900+
productImageOptimizerEnable,
901+
productImageOptimizerStatus,
902+
productLogExplorerInsightsCmdRoot,
903+
productLogExplorerInsightsDisable,
904+
productLogExplorerInsightsEnable,
905+
productLogExplorerInsightsStatus,
906+
productOriginInspectorCmdRoot,
907+
productOriginInspectorDisable,
908+
productOriginInspectorEnable,
909+
productOriginInspectorStatus,
910+
productWebSocketsCmdRoot,
911+
productWebSocketsDisable,
912+
productWebSocketsEnable,
913+
productWebSocketsStatus,
832914
productsCmdRoot,
833915
profileCmdRoot,
834916
profileCreate,

pkg/commands/product/botmanagement/disable.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ type DisableCommand struct {
1818
// NewDisableCommand returns a usable command registered under the parent.
1919
func NewDisableCommand(parent argparser.Registerer, g *global.Data) *DisableCommand {
2020
c := DisableCommand{}
21-
c.Init(parent, g, botmanagement.ProductName, &EnablementHooks)
21+
c.Init(parent, g, botmanagement.ProductID, botmanagement.ProductName, &EnablementHooks)
2222
return &c
2323
}
2424

pkg/commands/product/botmanagement/enable.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ type EnableCommand struct {
1818
// NewEnableCommand returns a usable command registered under the parent.
1919
func NewEnableCommand(parent argparser.Registerer, g *global.Data) *EnableCommand {
2020
c := EnableCommand{}
21-
c.Init(parent, g, botmanagement.ProductName, &EnablementHooks)
21+
c.Init(parent, g, botmanagement.ProductID, botmanagement.ProductName, &EnablementHooks)
2222
return &c
2323
}
2424

pkg/commands/product/botmanagement/product_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ import (
99
"github.com/fastly/go-fastly/v9/fastly/products/botmanagement"
1010
)
1111

12-
func TestProductEnablement(t *testing.T) {
12+
func TestBotManagementEnablement(t *testing.T) {
1313
productcore_test.TestEnablement(productcore_test.TestEnablementInput[*botmanagement.EnableOutput]{
1414
T: t,
1515
Commands: []string{root.CommandName, sub.CommandName},
16+
ProductID: botmanagement.ProductID,
1617
ProductName: botmanagement.ProductName,
1718
Hooks: &sub.EnablementHooks,
1819
})

pkg/commands/product/botmanagement/status.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ type StatusCommand struct {
1818
// NewStatusCommand returns a usable command registered under the parent.
1919
func NewStatusCommand(parent argparser.Registerer, g *global.Data) *StatusCommand {
2020
c := StatusCommand{}
21-
c.Init(parent, g, botmanagement.ProductName, &EnablementHooks)
21+
c.Init(parent, g, botmanagement.ProductID, botmanagement.ProductName, &EnablementHooks)
2222
return &c
2323
}
2424

0 commit comments

Comments
 (0)