Skip to content

Commit

Permalink
feat(product_enablement): Add support for Log Explorer & Insights pro…
Browse files Browse the repository at this point in the history
…duct. (fastly#558)

The GetProduct, EnableProduct, and DisableProduct functions now
support 'ProductLogExplorerInsights'.
  • Loading branch information
kpfleming committed Nov 4, 2024
1 parent 8ce02a6 commit b43de5b
Show file tree
Hide file tree
Showing 6 changed files with 319 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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: ""
Original file line number Diff line number Diff line change
@@ -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: ""
Original file line number Diff line number Diff line change
@@ -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: ""
48 changes: 48 additions & 0 deletions fastly/fixtures/product_enablement/get_log_explorer_insights.yaml
Original file line number Diff line number Diff line change
@@ -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: ""
3 changes: 3 additions & 0 deletions fastly/product_enablement.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -47,6 +49,7 @@ const (
ProductDomainInspector
ProductFanout
ProductImageOptimizer
ProductLogExplorerInsights
ProductNGWAF
ProductOriginInspector
ProductWebSockets
Expand Down
121 changes: 121 additions & 0 deletions fastly/product_enablement_log_explorer_insights_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}

0 comments on commit b43de5b

Please sign in to comment.