Skip to content

Commit f86165b

Browse files
committed
feat(products/apidiscovery): Add enable/disable support for API Discovery.
1 parent 0955b64 commit f86165b

10 files changed

+396
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
### Enhancements:
1010

11+
- feat(products/apidiscovery): Add enable/disable support for API Discovery ([#XXX](https://github.com/fastly/go-fastly/pull/XXX))
12+
1113
### Bug fixes:
1214

1315
### Dependencies:
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package apidiscovery
2+
3+
import (
4+
"context"
5+
6+
"github.com/fastly/go-fastly/v12/fastly"
7+
"github.com/fastly/go-fastly/v12/fastly/products"
8+
"github.com/fastly/go-fastly/v12/internal/productcore"
9+
)
10+
11+
const (
12+
ProductID = "api_discovery"
13+
ProductName = "API Discovery"
14+
)
15+
16+
// EnableOutput holds the details returned by the API from 'Get' and
17+
// 'Enable' operations; this alias exists to ensure that users of this
18+
// package will have a stable name to reference.
19+
type EnableOutput = products.EnableOutput
20+
21+
// Get gets the status of the API Discovery product on the service.
22+
func Get(ctx context.Context, c *fastly.Client, serviceID string) (EnableOutput, error) {
23+
return productcore.Get[EnableOutput](ctx, &productcore.GetInput{
24+
Client: c,
25+
ProductID: ProductID,
26+
ServiceID: serviceID,
27+
})
28+
}
29+
30+
// Enable enables the API Discovery product on the service.
31+
func Enable(ctx context.Context, c *fastly.Client, serviceID string) (EnableOutput, error) {
32+
return productcore.Put[EnableOutput](ctx, &productcore.PutInput[products.NullInput]{
33+
Client: c,
34+
ProductID: ProductID,
35+
ServiceID: serviceID,
36+
})
37+
}
38+
39+
// Disable disables the API Discovery product on the service.
40+
func Disable(ctx context.Context, c *fastly.Client, serviceID string) error {
41+
return productcore.Delete(ctx, &productcore.DeleteInput{
42+
Client: c,
43+
ProductID: ProductID,
44+
ServiceID: serviceID,
45+
})
46+
}
47+
48+
// NewEnableOutput is used to construct mock API output structures for
49+
// use in tests.
50+
func NewEnableOutput(serviceID string) EnableOutput {
51+
return products.NewEnableOutput(ProductID, serviceID)
52+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package apidiscovery_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/fastly/go-fastly/v12/fastly"
7+
"github.com/fastly/go-fastly/v12/fastly/products"
8+
"github.com/fastly/go-fastly/v12/fastly/products/apidiscovery"
9+
"github.com/fastly/go-fastly/v12/internal/productcore"
10+
"github.com/fastly/go-fastly/v12/internal/test_utils"
11+
)
12+
13+
var functionalTests = []*test_utils.FunctionalTest{
14+
productcore.NewDisableTest(&productcore.DisableTestInput{
15+
Phase: "ensure disabled before testing",
16+
OpFn: apidiscovery.Disable,
17+
IgnoreFailure: true,
18+
}),
19+
productcore.NewGetTest(&productcore.GetTestInput[apidiscovery.EnableOutput]{
20+
Phase: "before enablement",
21+
OpFn: apidiscovery.Get,
22+
ProductID: apidiscovery.ProductID,
23+
ExpectFailure: true,
24+
}),
25+
productcore.NewEnableTest(&productcore.EnableTestInput[apidiscovery.EnableOutput, products.NullInput]{
26+
OpNoInputFn: apidiscovery.Enable,
27+
ProductID: apidiscovery.ProductID,
28+
}),
29+
productcore.NewGetTest(&productcore.GetTestInput[apidiscovery.EnableOutput]{
30+
Phase: "after enablement",
31+
OpFn: apidiscovery.Get,
32+
ProductID: apidiscovery.ProductID,
33+
}),
34+
productcore.NewDisableTest(&productcore.DisableTestInput{
35+
OpFn: apidiscovery.Disable,
36+
}),
37+
productcore.NewGetTest(&productcore.GetTestInput[apidiscovery.EnableOutput]{
38+
Phase: "after disablement",
39+
OpFn: apidiscovery.Get,
40+
ProductID: apidiscovery.ProductID,
41+
ExpectFailure: true,
42+
}),
43+
}
44+
45+
func TestEnablementDelivery(t *testing.T) {
46+
test_utils.ExecuteFunctionalTests(t, functionalTests, fastly.TestDeliveryServiceID)
47+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Package apidiscovery contains API operations to enable and
2+
// disable the API Discovery product on a service
3+
package apidiscovery
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
version: 1
3+
interactions:
4+
- request:
5+
body: ""
6+
form: {}
7+
headers:
8+
User-Agent:
9+
- FastlyGo/12.0.0 (+github.com/fastly/go-fastly; go1.24.3)
10+
url: https://api.fastly.com/enabled-products/v1/api_discovery/services/kKJb5bOFI47uHeBVluGfX1
11+
method: DELETE
12+
response:
13+
body: ""
14+
headers:
15+
Accept-Ranges:
16+
- bytes
17+
Cache-Control:
18+
- no-store
19+
Content-Type:
20+
- application/json
21+
Date:
22+
- Mon, 29 Sep 2025 18:26:30 GMT
23+
Pragma:
24+
- no-cache
25+
Server:
26+
- fastly
27+
Status:
28+
- 204 No Content
29+
Strict-Transport-Security:
30+
- max-age=31536000
31+
Vary:
32+
- Accept-Encoding
33+
Via:
34+
- 1.1 varnish, 1.1 varnish
35+
X-Cache:
36+
- MISS, MISS
37+
X-Cache-Hits:
38+
- 0, 0
39+
X-Served-By:
40+
- cache-chi-klot8100116-CHI, cache-nyc-kteb1890041-NYC
41+
X-Timer:
42+
- S1759170387.407735,VS0,VE2895
43+
status: 204 No Content
44+
code: 204
45+
duration: ""
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
version: 1
3+
interactions:
4+
- request:
5+
body: ""
6+
form: {}
7+
headers:
8+
User-Agent:
9+
- FastlyGo/12.0.0 (+github.com/fastly/go-fastly; go1.24.3)
10+
url: https://api.fastly.com/enabled-products/v1/api_discovery/services/kKJb5bOFI47uHeBVluGfX1
11+
method: DELETE
12+
response:
13+
body: ""
14+
headers:
15+
Accept-Ranges:
16+
- bytes
17+
Cache-Control:
18+
- no-store
19+
Content-Type:
20+
- application/json
21+
Date:
22+
- Mon, 29 Sep 2025 18:26:34 GMT
23+
Pragma:
24+
- no-cache
25+
Server:
26+
- fastly
27+
Status:
28+
- 204 No Content
29+
Strict-Transport-Security:
30+
- max-age=31536000
31+
Vary:
32+
- Accept-Encoding
33+
Via:
34+
- 1.1 varnish, 1.1 varnish
35+
X-Cache:
36+
- MISS, MISS
37+
X-Cache-Hits:
38+
- 0, 0
39+
X-Served-By:
40+
- cache-chi-klot8100116-CHI, cache-nyc-kteb1890041-NYC
41+
X-Timer:
42+
- S1759170392.951022,VS0,VE2841
43+
status: 204 No Content
44+
code: 204
45+
duration: ""
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
---
2+
version: 1
3+
interactions:
4+
- request:
5+
body: '{}'
6+
form: {}
7+
headers:
8+
Accept:
9+
- application/json
10+
Content-Type:
11+
- application/json
12+
User-Agent:
13+
- FastlyGo/12.0.0 (+github.com/fastly/go-fastly; go1.24.3)
14+
url: https://api.fastly.com/enabled-products/v1/api_discovery/services/kKJb5bOFI47uHeBVluGfX1
15+
method: PUT
16+
response:
17+
body: |
18+
{"product":{"id":"api_discovery","object":"product"},"service":{"id":"kKJb5bOFI47uHeBVluGfX1","object":"service"},"_links":{"self":"/enabled-products/v1/api_discovery/services/kKJb5bOFI47uHeBVluGfX1"}}
19+
headers:
20+
Accept-Ranges:
21+
- bytes
22+
Cache-Control:
23+
- no-store
24+
Content-Length:
25+
- "202"
26+
Content-Type:
27+
- application/json
28+
Date:
29+
- Mon, 29 Sep 2025 18:26:31 GMT
30+
Pragma:
31+
- no-cache
32+
Server:
33+
- fastly
34+
Status:
35+
- 200 OK
36+
Strict-Transport-Security:
37+
- max-age=31536000
38+
Vary:
39+
- Accept-Encoding
40+
Via:
41+
- 1.1 varnish, 1.1 varnish
42+
X-Cache:
43+
- MISS, MISS
44+
X-Cache-Hits:
45+
- 0, 0
46+
X-Served-By:
47+
- cache-chi-klot8100116-CHI, cache-nyc-kteb1890041-NYC
48+
X-Timer:
49+
- S1759170391.537231,VS0,VE1155
50+
status: 200 OK
51+
code: 200
52+
duration: ""
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---
2+
version: 1
3+
interactions:
4+
- request:
5+
body: ""
6+
form: {}
7+
headers:
8+
Accept:
9+
- application/json
10+
User-Agent:
11+
- FastlyGo/12.0.0 (+github.com/fastly/go-fastly; go1.24.3)
12+
url: https://api.fastly.com/enabled-products/v1/api_discovery/services/kKJb5bOFI47uHeBVluGfX1
13+
method: GET
14+
response:
15+
body: |
16+
{"type":"","title":"no product on service","status":400,"errors":null,"detail":""}
17+
headers:
18+
Accept-Ranges:
19+
- bytes
20+
Cache-Control:
21+
- no-store
22+
Content-Length:
23+
- "83"
24+
Content-Type:
25+
- application/json
26+
Date:
27+
- Mon, 29 Sep 2025 18:26:35 GMT
28+
Pragma:
29+
- no-cache
30+
Server:
31+
- fastly
32+
Status:
33+
- 400 Bad Request
34+
Strict-Transport-Security:
35+
- max-age=31536000
36+
Vary:
37+
- Accept-Encoding
38+
Via:
39+
- 1.1 varnish, 1.1 varnish
40+
X-Cache:
41+
- MISS, MISS
42+
X-Cache-Hits:
43+
- 0, 0
44+
X-Served-By:
45+
- cache-chi-klot8100116-CHI, cache-nyc-kteb1890041-NYC
46+
X-Timer:
47+
- S1759170395.800610,VS0,VE264
48+
status: 400 Bad Request
49+
code: 400
50+
duration: ""
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---
2+
version: 1
3+
interactions:
4+
- request:
5+
body: ""
6+
form: {}
7+
headers:
8+
Accept:
9+
- application/json
10+
User-Agent:
11+
- FastlyGo/12.0.0 (+github.com/fastly/go-fastly; go1.24.3)
12+
url: https://api.fastly.com/enabled-products/v1/api_discovery/services/kKJb5bOFI47uHeBVluGfX1
13+
method: GET
14+
response:
15+
body: |
16+
{"product":{"id":"api_discovery","object":"product"},"service":{"id":"kKJb5bOFI47uHeBVluGfX1","object":"service"},"_links":{"self":"/enabled-products/v1/api_discovery/services/kKJb5bOFI47uHeBVluGfX1"}}
17+
headers:
18+
Accept-Ranges:
19+
- bytes
20+
Cache-Control:
21+
- no-store
22+
Content-Length:
23+
- "202"
24+
Content-Type:
25+
- application/json
26+
Date:
27+
- Mon, 29 Sep 2025 18:26:31 GMT
28+
Pragma:
29+
- no-cache
30+
Server:
31+
- fastly
32+
Status:
33+
- 200 OK
34+
Strict-Transport-Security:
35+
- max-age=31536000
36+
Vary:
37+
- Accept-Encoding
38+
Via:
39+
- 1.1 varnish, 1.1 varnish
40+
X-Cache:
41+
- MISS, MISS
42+
X-Cache-Hits:
43+
- 0, 0
44+
X-Served-By:
45+
- cache-chi-klot8100116-CHI, cache-nyc-kteb1890041-NYC
46+
X-Timer:
47+
- S1759170392.701099,VS0,VE241
48+
status: 200 OK
49+
code: 200
50+
duration: ""

0 commit comments

Comments
 (0)