Skip to content
Merged
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

### Enhancements:

- feat(domainmanagement): add support for routing config domain link ([#875](https://github.com/fastly/go-fastly/pull/875))

### Bug fixes:

### Dependencies:
Expand Down
3 changes: 3 additions & 0 deletions fastly/domainmanagement/v1/domains/api_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ type Data struct {
// FQDN is the fully-qualified domain name of the domain. Read-only
// after creation.
FQDN string `json:"fqdn"`
// RoutingConfigurationID is the routing config identifier associated with
// the domain, or nil if there is no association.
RoutingConfigurationID *string `json:"routing_configuration_id"`
// ServiceID is the service_id associated with the domain or nil if there
// is no association.
ServiceID *string `json:"service_id"`
Expand Down
84 changes: 79 additions & 5 deletions fastly/domainmanagement/v1/domains/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ package domains
import (
"context"
"errors"
"strings"
"testing"

"github.com/fastly/go-fastly/v17/fastly"
"github.com/fastly/go-fastly/v17/fastly/domainmanagement/v1/routingconfigs"
"github.com/fastly/go-fastly/v17/fastly/domainmanagement/v1/routingconfigs/paths"
"github.com/fastly/go-fastly/v17/fastly/domainmanagement/v1/routingconfigs/paths/rules"
)

func TestClient_Domain(t *testing.T) {
Expand Down Expand Up @@ -50,7 +54,7 @@ func TestClient_Domain(t *testing.T) {
} else {
var okErr bool
for _, he := range httpError.Errors {
if he.Detail == "fqdn has already been taken" {
if strings.Contains(he.Detail, "already been taken") {
okErr = true
break
}
Expand Down Expand Up @@ -93,14 +97,62 @@ func TestClient_Domain(t *testing.T) {
t.Errorf("bad fqdn: %q (%q)", d.FQDN, gd.FQDN)
}

// Create and activate a routing config to associate with the domain in
// the Update step below (association requires an active routing config).
var rc *routingconfigs.Data
rcName := "gofastly-sdk-testing-domain-routing-config"
fastly.Record(t, "create_routing_config", func(c *fastly.Client) {
rc, err = routingconfigs.Create(context.TODO(), c, &routingconfigs.CreateInput{
Name: new(rcName),
})
})
if err != nil {
t.Fatal(err)
}

var rp *paths.Data
fastly.Record(t, "create_routing_config_path", func(c *fastly.Client) {
rp, err = paths.Create(context.TODO(), c, &paths.CreateInput{
RoutingConfigID: &rc.RoutingConfigID,
Path: new("/"),
})
})
if err != nil {
t.Fatal(err)
}

fastly.Record(t, "create_routing_config_rule", func(c *fastly.Client) {
_, err = rules.Create(context.TODO(), c, &rules.CreateInput{
RoutingConfigID: &rc.RoutingConfigID,
PathID: &rp.PathID,
Action: &rules.Action{
Type: "service",
Value: fastly.TestDeliveryServiceID,
},
})
})
if err != nil {
t.Fatal(err)
}

fastly.Record(t, "activate_routing_config", func(c *fastly.Client) {
_, err = routingconfigs.Activate(context.TODO(), c, &routingconfigs.ActivateInput{
RoutingConfigID: &rc.RoutingConfigID,
})
})
if err != nil {
t.Fatal(err)
}

// Update
var ud *Data
descUpdated := "updated description"
fastly.Record(t, "update", func(c *fastly.Client) {
ud, err = Update(context.TODO(), c, &UpdateInput{
Description: new(descUpdated),
DomainID: new(d.DomainID),
ServiceID: new(fastly.TestDeliveryServiceID),
Description: new(descUpdated),
DomainID: new(d.DomainID),
RoutingConfigurationID: fastly.NewNullable(rc.RoutingConfigID),
ServiceID: new(fastly.TestDeliveryServiceID),
})
})
if err != nil {
Expand All @@ -110,7 +162,10 @@ func TestClient_Domain(t *testing.T) {
t.Errorf("bad description: %q (%q)", descUpdated, ud.Description)
}
if ud.ServiceID == nil || *ud.ServiceID != fastly.TestDeliveryServiceID {
t.Errorf("bad service id: %v", *ud.ServiceID)
t.Errorf("bad service id: %v", ud.ServiceID)
}
if ud.RoutingConfigurationID == nil || *ud.RoutingConfigurationID != rc.RoutingConfigID {
t.Errorf("bad routing configuration id: %v", ud.RoutingConfigurationID)
}

// Delete
Expand All @@ -122,6 +177,25 @@ func TestClient_Domain(t *testing.T) {
if err != nil {
t.Fatal(err)
}

// Clean up the routing config created above.
fastly.Record(t, "deactivate_routing_config", func(c *fastly.Client) {
_, err = routingconfigs.Deactivate(context.TODO(), c, &routingconfigs.DeactivateInput{
RoutingConfigID: &rc.RoutingConfigID,
})
})
if err != nil {
t.Fatal(err)
}

fastly.Record(t, "delete_routing_config", func(c *fastly.Client) {
err = routingconfigs.Delete(context.TODO(), c, &routingconfigs.DeleteInput{
RoutingConfigID: &rc.RoutingConfigID,
})
})
if err != nil {
t.Fatal(err)
}
}

func TestClient_GetDomain_validation(t *testing.T) {
Expand Down
5 changes: 5 additions & 0 deletions fastly/domainmanagement/v1/domains/api_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ type UpdateInput struct {
Description *string `json:"description"`
// DomainID is the domain identifier (required).
DomainID *string `json:"-"`
// RoutingConfigurationID is the routing config identifier to associate
// with the domain (optional). Leave nil to leave the association
// unchanged, use fastly.NullValue[string]() to remove the association, or
// fastly.NewNullable(id) to set it.
RoutingConfigurationID *fastly.Nullable[string] `json:"routing_configuration_id,omitempty"`
Comment thread
anthony-gomez-fastly marked this conversation as resolved.
// ServiceID is the service_id associated with the domain or nil if there
// is no association (optional)
ServiceID *string `json:"service_id"`
Comment thread
anthony-gomez-fastly marked this conversation as resolved.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
version: 1
interactions:
- request:
body: ""
form: {}
headers:
User-Agent:
- FastlyGo/17.5.0 (+github.com/fastly/go-fastly; go1.27.1)
url: https://api.fastly.com/domain-management/v1/routing-configs/5fXNeLtY5TFDuVIet0vzMH/activate
method: POST
response:
body: |
{"created_at":"2026-09-25T19:16:51Z","id":"5fXNeLtY5TFDuVIet0vzMH","links":{"paths":"/domain-management/v1/routing-configs/5fXNeLtY5TFDuVIet0vzMH/paths","self":"/domain-management/v1/routing-configs/5fXNeLtY5TFDuVIet0vzMH"},"name":"gofastly-sdk-testing-domain-routing-config","state":"active","updated_at":"2026-09-25T19:16:51Z"}
headers:
Accept-Ranges:
- bytes
Cache-Control:
- no-store
Content-Length:
- "330"
Content-Type:
- application/json
Date:
- Fri, 25 Sep 2026 19:16:51 GMT
Pragma:
- no-cache
Server:
- fastly istio-envoy
Strict-Transport-Security:
- max-age=31536000
Via:
- 1.1 varnish, 1.1 varnish
X-Cache:
- MISS, MISS
X-Cache-Hits:
- 0, 0
X-Envoy-Upstream-Service-Time:
- "86"
X-Served-By:
- cache-chi-kmdw8640075-CHI, cache-ewr-kewr1740063-EWR
X-Timer:
- S1790363812.668650,VS0,VE119
status: 200 OK
code: 200
duration: ""
24 changes: 13 additions & 11 deletions fastly/domainmanagement/v1/domains/fixtures/create.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,41 +10,43 @@ interactions:
Content-Type:
- application/json
User-Agent:
- FastlyGo/11.0.0 (+github.com/fastly/go-fastly; go1.24.2)
- FastlyGo/17.5.0 (+github.com/fastly/go-fastly; go1.27.1)
url: https://api.fastly.com/domain-management/v1/domains
method: POST
response:
body: '{"id":"DMrAbNVlJcZgwFP2ISUNOQ","created_at":"2025-08-01T18:18:48.000Z","fqdn":"1.fastly-sdk-gofastly-testing.com","updated_at":"2025-08-01T18:18:48.000Z","service_id":null,"activated":false,"verified":false,"description":"my
description"}'
body: '{"id":"pPYOMApBAcxbIJGjtyXcmg","created_at":"2026-09-25T19:16:50.000Z","fqdn":"1.fastly-sdk-gofastly-testing.com","updated_at":"2026-09-25T19:16:50.000Z","service_id":null,"activated":false,"verified":false,"description":"my
description","routing_configuration_id":null}'
headers:
Accept-Ranges:
- bytes
Cache-Control:
- no-store
Content-Length:
- "238"
- "270"
Content-Type:
- application/json
Date:
- Fri, 01 Aug 2025 18:18:49 GMT
- Fri, 25 Sep 2026 19:16:50 GMT
Pragma:
- no-cache
Server:
- fastly
- fastly istio-envoy
Strict-Transport-Security:
- max-age=31536000
Via:
- 1.1 varnish
- 1.1 varnish, 1.1 varnish
X-Cache:
- MISS
- MISS, MISS
X-Cache-Hits:
- "0"
- 0, 0
X-Content-Type-Options:
- nosniff
X-Envoy-Upstream-Service-Time:
- "133"
X-Served-By:
- cache-chi-kigq8000025-CHI
- cache-chi-kigq8000067-CHI, cache-ewr-kewr1740063-EWR
X-Timer:
- S1754072329.862217,VS0,VE143
- S1790363811.609516,VS0,VE166
status: 201 Created
code: 201
duration: ""
24 changes: 13 additions & 11 deletions fastly/domainmanagement/v1/domains/fixtures/create_duplicate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,41 +10,43 @@ interactions:
Content-Type:
- application/json
User-Agent:
- FastlyGo/11.0.0 (+github.com/fastly/go-fastly; go1.24.2)
- FastlyGo/17.5.0 (+github.com/fastly/go-fastly; go1.27.1)
url: https://api.fastly.com/domain-management/v1/domains
method: POST
response:
body: '{"errors":[{"title":"Invalid value for fqdn","detail":"fqdn has already
been taken"}]}'
body: '{"errors":[{"title":"Invalid value for fqdn","detail":"fqdn Domain name
has already been taken"}]}'
headers:
Accept-Ranges:
- bytes
Cache-Control:
- no-store
Content-Length:
- "86"
- "98"
Content-Type:
- application/json
Date:
- Fri, 01 Aug 2025 18:18:49 GMT
- Fri, 25 Sep 2026 19:16:50 GMT
Pragma:
- no-cache
Server:
- fastly
- fastly istio-envoy
Strict-Transport-Security:
- max-age=31536000
Via:
- 1.1 varnish
- 1.1 varnish, 1.1 varnish
X-Cache:
- MISS
- MISS, MISS
X-Cache-Hits:
- "0"
- 0, 0
X-Content-Type-Options:
- nosniff
X-Envoy-Upstream-Service-Time:
- "99"
X-Served-By:
- cache-chi-kigq8000025-CHI
- cache-chi-kigq8000067-CHI, cache-ewr-kewr1740063-EWR
X-Timer:
- S1754072329.033324,VS0,VE103
- S1790363811.797630,VS0,VE128
status: 400 Bad Request
code: 400
duration: ""
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
version: 1
interactions:
- request:
body: '{"name":"gofastly-sdk-testing-domain-routing-config"}'
form: {}
headers:
Accept:
- application/json
Content-Type:
- application/json
User-Agent:
- FastlyGo/17.5.0 (+github.com/fastly/go-fastly; go1.27.1)
url: https://api.fastly.com/domain-management/v1/routing-configs
method: POST
response:
body: |
{"created_at":"2026-09-25T19:16:51.2945526Z","id":"5fXNeLtY5TFDuVIet0vzMH","links":{"paths":"/domain-management/v1/routing-configs/5fXNeLtY5TFDuVIet0vzMH/paths","self":"/domain-management/v1/routing-configs/5fXNeLtY5TFDuVIet0vzMH"},"name":"gofastly-sdk-testing-domain-routing-config"}
headers:
Accept-Ranges:
- bytes
Cache-Control:
- no-store
Content-Length:
- "285"
Content-Type:
- application/json
Date:
- Fri, 25 Sep 2026 19:16:51 GMT
Pragma:
- no-cache
Server:
- fastly istio-envoy
Strict-Transport-Security:
- max-age=31536000
Via:
- 1.1 varnish, 1.1 varnish
X-Cache:
- MISS, MISS
X-Cache-Hits:
- 0, 0
X-Envoy-Upstream-Service-Time:
- "41"
X-Served-By:
- cache-chi-kigq8000076-CHI, cache-ewr-kewr1740063-EWR
X-Timer:
- S1790363811.269910,VS0,VE78
status: 201 Created
code: 201
duration: ""
Loading
Loading