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

Add missing DCV delegation records #1329

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/1329.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
certificate_packs: Add Delegation Records
```
1 change: 1 addition & 0 deletions certificate_packs.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type CertificatePack struct {
ValidityDays int `json:"validity_days"`
CertificateAuthority string `json:"certificate_authority"`
CloudflareBranding bool `json:"cloudflare_branding"`
DelegationRecords []SSLDelegationRecord `json:"dcv_delegation_records,omitempty"`
}

// CertificatePackRequest is used for requesting a new certificate.
Expand Down
82 changes: 74 additions & 8 deletions certificate_packs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,22 @@ var (
ValidityDays: 90,
CertificateAuthority: "lets_encrypt",
}

pendingCertificatePackRecords = CertificatePack{
ID: "64289572-8b22-4cd4-af3c-3fef28ef5dae",
Type: "advanced",
Hosts: []string{"example.com"},
Certificates: []CertificatePackCertificate{},
PrimaryCertificate: "0",
Status: "pending_validation",
ValidationRecords: []SSLValidationRecord{SSLValidationRecord{CnameTarget: "", CnameName: "", TxtName: "_acme-challenge.example.com", TxtValue: "QkyhZpLUAD4r3Fn9urywnXzeIeZ_ZG68MxJgBY32NmU", HTTPUrl: "", HTTPBody: "", Emails: []string(nil)}},
ValidationErrors: []SSLValidationError(nil),
ValidationMethod: "txt",
ValidityDays: 90,
CertificateAuthority: "lets_encrypt",
CloudflareBranding: false,
DelegationRecords: []SSLDelegationRecord{SSLDelegationRecord{CnameTarget: "example.com.0f461ad6a17edc91.dcv.cloudflare.com", CnameName: "_acme-challenge.example.com"}},
}
)

func TestListCertificatePacks(t *testing.T) {
Expand Down Expand Up @@ -267,14 +283,14 @@ func TestDeleteCertificatePack(t *testing.T) {
assert.Equal(t, http.MethodDelete, r.Method, "Expected method 'DELETE', got %s", r.Method)
w.Header().Set("content-type", "application/json")
fmt.Fprintf(w, `{
"success": true,
"errors": [],
"messages": [],
"result": {
"id": "3822ff90-ea29-44df-9e55-21300bb9419b"
}
}
`)
"success": true,
"errors": [],
"messages": [],
"result": {
"id": "3822ff90-ea29-44df-9e55-21300bb9419b"
}
}
`)
}

mux.HandleFunc("/zones/"+testZoneID+"/ssl/certificate_packs/3822ff90-ea29-44df-9e55-21300bb9419b", handler)
Expand All @@ -283,3 +299,53 @@ func TestDeleteCertificatePack(t *testing.T) {

assert.NoError(t, err)
}

func TestListCertificatePackPending(t *testing.T) {
setup()
defer teardown()

handler := func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, http.MethodGet, r.Method, "Expected method 'GET', got %s", r.Method)
w.Header().Set("content-type", "application/json")
fmt.Fprintf(w, `{
"success": true,
"errors": [],
"messages": [],
"result": {
"id": "64289572-8b22-4cd4-af3c-3fef28ef5dae",
"type": "advanced",
"hosts": [
"example.com"
],
"primary_certificate": "0",
"status": "pending_validation",
"certificates": [],
"created_on": "2023-06-21T13:48:39.114782Z",
"validity_days": 90,
"validation_method": "txt",
"validation_records": [
{
"status": "pending",
"txt_name": "_acme-challenge.example.com",
"txt_value": "QkyhZpLUAD4r3Fn9urywnXzeIeZ_ZG68MxJgBY32NmU"
}
],
"dcv_delegation_records": [
{
"cname": "_acme-challenge.example.com",
"cname_target": "example.com.0f461ad6a17edc91.dcv.cloudflare.com"
}
],
"certificate_authority": "lets_encrypt"
}
}`)
}

mux.HandleFunc("/zones/"+testZoneID+"/ssl/certificate_packs/3822ff90-ea29-44df-9e55-21300bb9419a", handler)

actual, err := client.CertificatePack(context.Background(), testZoneID, "3822ff90-ea29-44df-9e55-21300bb9419a")

if assert.NoError(t, err) {
assert.Equal(t, pendingCertificatePackRecords, actual)
}
}
6 changes: 6 additions & 0 deletions ssl.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,9 @@ type SSLValidationRecord struct {

Emails []string `json:"emails,omitempty"`
}

// SSLDelegationRecord displays Domain Control Delegation tokens.
type SSLDelegationRecord struct {
CnameTarget string `json:"cname_target,omitempty"`
CnameName string `json:"cname,omitempty"`
}