diff --git a/fastly/fixtures/product_enablement/disable_log_explorer_insights.yaml b/fastly/fixtures/product_enablement/disable_log_explorer_insights.yaml new file mode 100644 index 000000000..5edcc1310 --- /dev/null +++ b/fastly/fixtures/product_enablement/disable_log_explorer_insights.yaml @@ -0,0 +1,45 @@ +--- +version: 1 +interactions: +- request: + body: "" + form: {} + headers: + User-Agent: + - FastlyGo/9.11.0 (+github.com/fastly/go-fastly; go1.23.2) + url: https://api.fastly.com/enabled-products/log_explorer_insights/services/VR3OlB58JjX9oVWj4lz2o5 + method: DELETE + response: + body: "" + headers: + Accept-Ranges: + - bytes + Cache-Control: + - no-store + Content-Type: + - application/json + Date: + - Mon, 04 Nov 2024 16:04:30 GMT + Pragma: + - no-cache + Server: + - control-gateway + Status: + - 204 No Content + Strict-Transport-Security: + - max-age=31536000 + Vary: + - Accept-Encoding + Via: + - 1.1 varnish, 1.1 varnish + X-Cache: + - MISS, MISS + X-Cache-Hits: + - 0, 0 + X-Served-By: + - cache-chi-klot8100072-CHI, cache-nyc-kteb1890096-NYC + X-Timer: + - S1730736270.029325,VS0,VE435 + status: 204 No Content + code: 204 + duration: "" diff --git a/fastly/fixtures/product_enablement/enable_log_explorer_insights.yaml b/fastly/fixtures/product_enablement/enable_log_explorer_insights.yaml new file mode 100644 index 000000000..5609f89c7 --- /dev/null +++ b/fastly/fixtures/product_enablement/enable_log_explorer_insights.yaml @@ -0,0 +1,54 @@ +--- +version: 1 +interactions: +- request: + body: ProductID=log_explorer_insights&ServiceID=VR3OlB58JjX9oVWj4lz2o5 + form: + ProductID: + - log_explorer_insights + ServiceID: + - VR3OlB58JjX9oVWj4lz2o5 + headers: + Content-Type: + - application/x-www-form-urlencoded + User-Agent: + - FastlyGo/9.11.0 (+github.com/fastly/go-fastly; go1.23.2) + url: https://api.fastly.com/enabled-products/log_explorer_insights/services/VR3OlB58JjX9oVWj4lz2o5 + method: PUT + response: + body: | + {"product":{"id":"log_explorer_insights","object":"product"},"service":{"id":"VR3OlB58JjX9oVWj4lz2o5","object":"service"},"_links":{"self":"/enabled-products/log_explorer_insights/services/VR3OlB58JjX9oVWj4lz2o5"}} + headers: + Accept-Ranges: + - bytes + Cache-Control: + - no-store + Content-Length: + - "215" + Content-Type: + - application/json + Date: + - Mon, 04 Nov 2024 16:04:29 GMT + Pragma: + - no-cache + Server: + - control-gateway + Status: + - 200 OK + Strict-Transport-Security: + - max-age=31536000 + Vary: + - Accept-Encoding + Via: + - 1.1 varnish, 1.1 varnish + X-Cache: + - MISS, MISS + X-Cache-Hits: + - 0, 0 + X-Served-By: + - cache-chi-klot8100072-CHI, cache-nyc-kteb1890096-NYC + X-Timer: + - S1730736269.965258,VS0,VE916 + status: 200 OK + code: 200 + duration: "" diff --git a/fastly/fixtures/product_enablement/get-disabled_log_explorer_insights.yaml b/fastly/fixtures/product_enablement/get-disabled_log_explorer_insights.yaml new file mode 100644 index 000000000..327bdb0a1 --- /dev/null +++ b/fastly/fixtures/product_enablement/get-disabled_log_explorer_insights.yaml @@ -0,0 +1,48 @@ +--- +version: 1 +interactions: +- request: + body: "" + form: {} + headers: + User-Agent: + - FastlyGo/9.11.0 (+github.com/fastly/go-fastly; go1.23.2) + url: https://api.fastly.com/enabled-products/log_explorer_insights/services/VR3OlB58JjX9oVWj4lz2o5 + method: GET + response: + body: | + {"type":"","title":"no product on service","status":400,"errors":null,"detail":""} + headers: + Accept-Ranges: + - bytes + Cache-Control: + - no-store + Content-Length: + - "83" + Content-Type: + - application/json + Date: + - Mon, 04 Nov 2024 16:04:30 GMT + Pragma: + - no-cache + Server: + - control-gateway + Status: + - 400 Bad Request + Strict-Transport-Security: + - max-age=31536000 + Vary: + - Accept-Encoding + Via: + - 1.1 varnish, 1.1 varnish + X-Cache: + - MISS, MISS + X-Cache-Hits: + - 0, 0 + X-Served-By: + - cache-chi-klot8100072-CHI, cache-nyc-kteb1890096-NYC + X-Timer: + - S1730736270.469785,VS0,VE96 + status: 400 Bad Request + code: 400 + duration: "" diff --git a/fastly/fixtures/product_enablement/get_log_explorer_insights.yaml b/fastly/fixtures/product_enablement/get_log_explorer_insights.yaml new file mode 100644 index 000000000..be23c546d --- /dev/null +++ b/fastly/fixtures/product_enablement/get_log_explorer_insights.yaml @@ -0,0 +1,48 @@ +--- +version: 1 +interactions: +- request: + body: "" + form: {} + headers: + User-Agent: + - FastlyGo/9.11.0 (+github.com/fastly/go-fastly; go1.23.2) + url: https://api.fastly.com/enabled-products/log_explorer_insights/services/VR3OlB58JjX9oVWj4lz2o5 + method: GET + response: + body: | + {"product":{"id":"log_explorer_insights","object":"product"},"service":{"id":"VR3OlB58JjX9oVWj4lz2o5","object":"service"},"_links":{"self":"/enabled-products/log_explorer_insights/services/VR3OlB58JjX9oVWj4lz2o5"}} + headers: + Accept-Ranges: + - bytes + Cache-Control: + - no-store + Content-Length: + - "215" + Content-Type: + - application/json + Date: + - Mon, 04 Nov 2024 16:04:30 GMT + Pragma: + - no-cache + Server: + - control-gateway + Status: + - 200 OK + Strict-Transport-Security: + - max-age=31536000 + Vary: + - Accept-Encoding + Via: + - 1.1 varnish, 1.1 varnish + X-Cache: + - MISS, MISS + X-Cache-Hits: + - 0, 0 + X-Served-By: + - cache-chi-klot8100072-CHI, cache-nyc-kteb1890096-NYC + X-Timer: + - S1730736270.894139,VS0,VE129 + status: 200 OK + code: 200 + duration: "" diff --git a/fastly/product_enablement.go b/fastly/product_enablement.go index 050000797..d767f0fb6 100644 --- a/fastly/product_enablement.go +++ b/fastly/product_enablement.go @@ -28,6 +28,8 @@ func (p Product) String() string { return "fanout" case ProductImageOptimizer: return "image_optimizer" + case ProductLogExplorerInsights: + return "log_explorer_insights" case ProductNGWAF: return "ngwaf" case ProductOriginInspector: @@ -47,6 +49,7 @@ const ( ProductDomainInspector ProductFanout ProductImageOptimizer + ProductLogExplorerInsights ProductNGWAF ProductOriginInspector ProductWebSockets diff --git a/fastly/product_enablement_log_explorer_insights_test.go b/fastly/product_enablement_log_explorer_insights_test.go new file mode 100644 index 000000000..b9b9e2016 --- /dev/null +++ b/fastly/product_enablement_log_explorer_insights_test.go @@ -0,0 +1,121 @@ +package fastly + +import ( + "testing" +) + +func TestClient_ProductEnablement_log_explorer_insights(t *testing.T) { + t.Parallel() + + var err error + + // Enable Product - Log Explorer & Insights + var pe *ProductEnablement + record(t, "product_enablement/enable_log_explorer_insights", func(c *Client) { + pe, err = c.EnableProduct(&ProductEnablementInput{ + ProductID: ProductLogExplorerInsights, + ServiceID: testServiceID, + }) + }) + if err != nil { + t.Fatal(err) + } + + if *pe.Product.ProductID != ProductLogExplorerInsights.String() { + t.Errorf("bad feature_revision: %s", *pe.Product.ProductID) + } + + // Get Product status + var gpe *ProductEnablement + record(t, "product_enablement/get_log_explorer_insights", func(c *Client) { + gpe, err = c.GetProduct(&ProductEnablementInput{ + ProductID: ProductLogExplorerInsights, + ServiceID: testServiceID, + }) + }) + if err != nil { + t.Fatal(err) + } + + if *gpe.Product.ProductID != ProductLogExplorerInsights.String() { + t.Errorf("bad feature_revision: %s", *gpe.Product.ProductID) + } + + // Disable Product + record(t, "product_enablement/disable_log_explorer_insights", func(c *Client) { + err = c.DisableProduct(&ProductEnablementInput{ + ProductID: ProductLogExplorerInsights, + ServiceID: testServiceID, + }) + }) + if err != nil { + t.Fatal(err) + } + + // Get Product status again to check disabled + record(t, "product_enablement/get-disabled_log_explorer_insights", func(c *Client) { + gpe, err = c.GetProduct(&ProductEnablementInput{ + ProductID: ProductLogExplorerInsights, + ServiceID: testServiceID, + }) + }) + + // The API returns a 400 if Product is not enabled. + // The API client returns an error if a non-2xx is returned from the API. + if err == nil { + t.Fatal("expected a 400 from the API but got a 2xx") + } +} + +func TestClient_GetProduct_validation_log_explorer_insights(t *testing.T) { + var err error + + _, err = testClient.GetProduct(&ProductEnablementInput{ + ProductID: ProductLogExplorerInsights, + }) + if err != ErrMissingServiceID { + t.Errorf("bad error: %s", err) + } + + _, err = testClient.GetProduct(&ProductEnablementInput{ + ServiceID: "foo", + }) + if err != ErrMissingProductID { + t.Errorf("bad error: %s", err) + } +} + +func TestClient_EnableProduct_validation_log_explorer_insights(t *testing.T) { + var err error + _, err = testClient.EnableProduct(&ProductEnablementInput{ + ProductID: ProductLogExplorerInsights, + }) + if err != ErrMissingServiceID { + t.Errorf("bad error: %s", err) + } + + _, err = testClient.EnableProduct(&ProductEnablementInput{ + ServiceID: "foo", + }) + if err != ErrMissingProductID { + t.Errorf("bad error: %s", err) + } +} + +func TestClient_DisableProduct_validation_log_explorer_insights(t *testing.T) { + var err error + + err = testClient.DisableProduct(&ProductEnablementInput{ + ProductID: ProductLogExplorerInsights, + }) + if err != ErrMissingServiceID { + t.Errorf("bad error: %s", err) + } + + err = testClient.DisableProduct(&ProductEnablementInput{ + ServiceID: "foo", + }) + if err != ErrMissingProductID { + t.Errorf("bad error: %s", err) + } +}