Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to manage default cert for custom TLS configurations #555

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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: 1 addition & 1 deletion fastly/fixtures/custom_tls_configuration/get.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interactions:
url: https://api.fastly.com/tls/configurations/TLS_CONFIGURATION_ID
method: GET
response:
body: '{"data":{"id":"TLS_CONFIGURATION_ID","type":"tls_configuration","attributes":{"bulk":false,"created_at":"2018-09-11T20:59:51.000Z","default":true,"http_protocols":["http/1.1","http/2"],"name":"My configuration","tls_protocols":["1.2"],"updated_at":"2020-10-20T22:16:11.000Z"},"relationships":{"dns_records":{"data":[{"id":"IP_ADDRESS","type":"dns_record"}]}}},"included":[{"id":"IP_ADDRESS","type":"dns_record","attributes":{"record_type":"A","region":"global"}}]}'
body: '{"data":{"id":"TLS_CONFIGURATION_ID","type":"tls_configuration","attributes":{"bulk":false,"created_at":"2018-09-11T20:59:51.000Z","default":true,"http_protocols":["http/1.1","http/2"],"name":"My configuration","tls_protocols":["1.2"],"updated_at":"2020-10-20T22:16:11.000Z"},"relationships":{"default_certificate":{"data":{"id":"DEFAULT_CERTIFICATE_ID","type":"tls_certificate"}},"dns_records":{"data":[{"id":"IP_ADDRESS","type":"dns_record"}]}}},"included":[{"id":"IP_ADDRESS","type":"dns_record","attributes":{"record_type":"A","region":"global"}}]}'
headers:
Accept-Ranges:
- bytes
Expand Down
4 changes: 2 additions & 2 deletions fastly/fixtures/custom_tls_configuration/update.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: 1
interactions:
- request:
body: |
{"data":{"type":"","attributes":{"id":"TLS_CONFIGURATION_ID","name":"My configuration v2"}}}
{"data":{"type":"","attributes":{"id":"TLS_CONFIGURATION_ID","name":"My configuration v2"},"relationships":{"default_certificate":{"data":{"id":"NEW_DEFAULT_CERTIFICATE_ID","type":"tls_certificate"}}}}}
form: {}
headers:
Accept:
Expand All @@ -15,7 +15,7 @@ interactions:
url: https://api.fastly.com/tls/configurations/TLS_CONFIGURATION_ID
method: PATCH
response:
body: '{"data":{"id":"TLS_CONFIGURATION_ID","type":"tls_configuration","attributes":{"bulk":false,"created_at":"2018-09-11T20:59:51.000Z","default":true,"http_protocols":["http/1.1","http/2"],"name":"My configuration v2","tls_protocols":["1.2"],"updated_at":"2020-10-22T22:38:24.000Z"}}}'
body: '{"data":{"id":"TLS_CONFIGURATION_ID","type":"tls_configuration","attributes":{"bulk":false,"created_at":"2018-09-11T20:59:51.000Z","default":true,"http_protocols":["http/1.1","http/2"],"name":"My configuration v2","tls_protocols":["1.2"],"updated_at":"2020-10-22T22:38:24.000Z"},"relationships":{"default_certificate":{"data":{"id":"NEW_DEFAULT_CERTIFICATE_ID","type":"tls_certificate"}}}}}'
headers:
Accept-Ranges:
- bytes
Expand Down
27 changes: 18 additions & 9 deletions fastly/tls_custom_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@ import (

// CustomTLSConfiguration represents a TLS configuration response from the Fastly API.
type CustomTLSConfiguration struct {
Bulk bool `jsonapi:"attr,bulk"`
CreatedAt *time.Time `jsonapi:"attr,created_at,iso8601"`
DNSRecords []*DNSRecord `jsonapi:"relation,dns_records"`
Default bool `jsonapi:"attr,default"`
HTTPProtocols []string `jsonapi:"attr,http_protocols"`
ID string `jsonapi:"primary,tls_configuration"`
Name string `jsonapi:"attr,name"`
TLSProtocols []string `jsonapi:"attr,tls_protocols"`
UpdatedAt *time.Time `jsonapi:"attr,updated_at,iso8601"`
Bulk bool `jsonapi:"attr,bulk"`
CreatedAt *time.Time `jsonapi:"attr,created_at,iso8601"`
DNSRecords []*DNSRecord `jsonapi:"relation,dns_records"`
Default bool `jsonapi:"attr,default"`
HTTPProtocols []string `jsonapi:"attr,http_protocols"`
ID string `jsonapi:"primary,tls_configuration"`
Name string `jsonapi:"attr,name"`
TLSProtocols []string `jsonapi:"attr,tls_protocols"`
UpdatedAt *time.Time `jsonapi:"attr,updated_at,iso8601"`
DefaultCertificate *DefaultCertificate `jsonapi:"relation,default_certificate,omitempty"`
}

// DNSRecord is a child of CustomTLSConfiguration.
Expand All @@ -29,6 +30,12 @@ type DNSRecord struct {
Region string `jsonapi:"attr,region"`
}

// DefaultCertificate is a child of CustomTLSConfiguration. Used as a fallback cert for Platform TLS.
type DefaultCertificate struct {
ID string `jsonapi:"primary,tls_certificate"`
Type string `jsonapi:"attr,type"`
}

// ListCustomTLSConfigurationsInput is used as input to the ListCustomTLSConfigurationsInput function.
type ListCustomTLSConfigurationsInput struct {
// FilterBulk is whether or not to only include bulk=true configurations
Expand Down Expand Up @@ -148,6 +155,8 @@ type UpdateCustomTLSConfigurationInput struct {
ID string
// Name is a custom name for your TLS configuration.
Name string `jsonapi:"attr,name"`
// DefaultCertificate is the default certificate for the TLS configuration. Used as a fallback cert for Platform TLS.
DefaultCertificate *DefaultCertificate `jsonapi:"relation,default_certificate,omitempty"`
}

// UpdateCustomTLSConfiguration updates the specified resource.
Expand Down
20 changes: 20 additions & 0 deletions fastly/tls_custom_configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ func TestClient_CustomTLSConfiguration(t *testing.T) {

var err error
conID := "TLS_CONFIGURATION_ID"
certID := "DEFAULT_CERTIFICATE_ID"

// Get
var gcon *CustomTLSConfiguration
Expand All @@ -26,6 +27,14 @@ func TestClient_CustomTLSConfiguration(t *testing.T) {
t.Errorf("bad ID: %q (%q)", conID, gcon.ID)
}

if gcon.DefaultCertificate == nil {
t.Errorf("missing default certificate: %v", gcon.DefaultCertificate)
}

if gcon.DefaultCertificate.ID != certID {
t.Errorf("wrong default certificate ID: %v", gcon.DefaultCertificate.ID)
}

// List
var lcon []*CustomTLSConfiguration
record(t, fixtureBase+"list", func(c *Client) {
Expand All @@ -41,10 +50,15 @@ func TestClient_CustomTLSConfiguration(t *testing.T) {
// Update
var ucon *CustomTLSConfiguration
newName := "My configuration v2"
newCertID := "NEW_DEFAULT_CERTIFICATE_ID"
record(t, fixtureBase+"update", func(c *Client) {
ucon, err = c.UpdateCustomTLSConfiguration(&UpdateCustomTLSConfigurationInput{
ID: "TLS_CONFIGURATION_ID",
Name: newName,
DefaultCertificate: &DefaultCertificate{
ID: newCertID,
Type: "tls_certificate",
},
})
})
if err != nil {
Expand All @@ -56,6 +70,12 @@ func TestClient_CustomTLSConfiguration(t *testing.T) {
if ucon.Name != newName {
t.Errorf("bad Name: %q (%q)", newName, ucon.Name)
}
if ucon.DefaultCertificate == nil {
t.Fatal("missing default certificate")
}
if ucon.DefaultCertificate.ID != newCertID {
t.Errorf("bad default cert ID: %q (%q)", newCertID, ucon.DefaultCertificate.ID)
}
}

func TestClient_ListCustomTLSConfigurations_validation(t *testing.T) {
Expand Down
Loading