-
Notifications
You must be signed in to change notification settings - Fork 1
/
cloudflareTypes.go
91 lines (81 loc) · 3.11 KB
/
cloudflareTypes.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package main
import (
"crypto/x509"
"encoding/pem"
"fmt"
"time"
)
// Zone represents a zone in Cloudflare (https://api.cloudflare.com/#zone-list-zones).
type Zone struct {
ID string `json:"id"`
Name string `json:"name"`
DevMode int `json:"development_mode"`
OriginalNS []string `json:"original_name_servers"`
OriginalRegistrar string `json:"original_registrar"`
OriginalDNSHost string `json:"original_dnshost"`
CreatedOn time.Time `json:"created_on"`
ModifiedOn time.Time `json:"modified_on"`
NameServers []string `json:"name_servers"`
Permissions []string `json:"permissions"`
Status string `json:"status"`
Paused bool `json:"paused"`
Type string `json:"type"`
Host struct {
Name string
Website string
} `json:"host"`
VanityNS []string `json:"vanity_name_servers"`
Betas []string `json:"betas"`
DeactReason string `json:"deactivation_reason"`
}
// APIAuthentication contains the email address and api key to authenticate a request to the cloudflare api.
type APIAuthentication struct {
Key, Email string
}
type zonesResult struct {
Success bool `json:"success"`
Errors interface{} `json:"errors"`
Messages interface{} `json:"messages"`
Zones []Zone `json:"result"`
ResultInfo resultInfo `json:"result_info"`
}
type resultInfo struct {
Page int `json:"page"`
PerPage int `json:"per_page"`
Count int `json:"count"`
TotalCount int `json:"total_count"`
}
type listResult struct {
Success bool `json:"success"`
Errors interface{} `json:"errors"`
Messages interface{} `json:"messages"`
SSLConfigurations []SSLConfiguration `json:"result,omitempty"`
}
type sslConfigResult struct {
Success bool `json:"success"`
Errors interface{} `json:"errors"`
Messages interface{} `json:"messages"`
SSLConfiguration SSLConfiguration `json:"result,omitempty"`
}
type SSLConfiguration struct {
ID string `json:"id,omitempty"`
Hosts []string `json:"hosts,omitempty"`
ZoneID string `json:"zone_id,omitempty"`
ExpiresOn time.Time `json:"expires_on,omitempty"`
Certificate string `json:"certificate,omitempty"`
PrivateKey string `json:"private_key,omitempty"`
}
// this function should return true if the certificate to be uploaded is the same as the one saved at CF
// right now is only comparing the expiration date, since it's not possible to get the actual certificate data from CF
// it would also be possible to compare the hostnames, it wasn't done yet in favor of simplicity and lack of necessity so far
func (sslConfig *SSLConfiguration) CertificateEqual(rawCertificate []byte) (bool, error) {
block, _ := pem.Decode(rawCertificate)
if block == nil {
return false, fmt.Errorf("Decoding certificate failed: %v", rawCertificate)
}
certificate, err := x509.ParseCertificate(block.Bytes)
if err != nil {
return false, err
}
return sslConfig.ExpiresOn.Equal(certificate.NotAfter), nil
}