-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathzerossl_request_factory.go
156 lines (152 loc) · 5.48 KB
/
zerossl_request_factory.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/*
* Copyright [2022] [tinkernels (github.com/tinkernels)]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package zerosslIPCert
import (
"io"
"net/http"
"net/url"
"strings"
)
// ApiEndpoint is the zerossl api endpoint.
const ApiEndpoint = "api.zerossl.com"
// ApiReqFactory is a factory for creating API requests.
var ApiReqFactory = struct {
// Request of creating a new certificate.
CreateCertificate func(accessKey, certificateDomains, certificateCsr, certificateValidityDays,
strictDomains string) (req *http.Request)
// Request of listing all certificates.
ListCertificates func(accessKey, certificateStatus, search, limit, page string) (req *http.Request)
// Request of getting a certificate.
GetCertificate func(accessKey, id string) (req *http.Request)
// Request of verifying a certificate.
VerifyDomains func(accessKey, certificateId, validationMethod, validationEmail string) (req *http.Request)
// Request of verification status.
VerificationStatus func(accessKey, id string) (req *http.Request)
// Request of cancelation a certificate.
CancelCertificate func(accessKey, id string) (req *http.Request)
// Request of downloading a certificate.
DownloadCertificateInline func(accessKey, certID, includeCrossSigned string) (req *http.Request)
}{
CreateCertificate: func(accessKey, certificateDomains, certificateCsr, certificateValidityDays,
strictDomains string) (req *http.Request) {
req = &http.Request{Method: http.MethodPost}
url_ := &url.URL{Scheme: "https", Host: ApiEndpoint, Path: "/certificates"}
q_ := make(url.Values)
q_.Add("access_key", accessKey)
url_.RawQuery = q_.Encode()
req.URL = url_
bodyForm_ := make(url.Values)
if certificateDomains != "" {
bodyForm_.Add("certificate_domains", certificateDomains)
}
if certificateCsr != "" {
bodyForm_.Add("certificate_csr", certificateCsr)
}
if certificateValidityDays != "" {
bodyForm_.Add("certificate_validity_days", certificateValidityDays)
}
if strictDomains != "" {
bodyForm_.Add("strict_domains", strictDomains)
}
if len(bodyForm_) > 0 {
req.Header = make(http.Header)
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
req.Body = io.NopCloser(strings.NewReader(bodyForm_.Encode()))
}
return
},
ListCertificates: func(accessKey, certificateStatus, search, limit, page string) (req *http.Request) {
req = &http.Request{Method: http.MethodGet}
url_ := &url.URL{Scheme: "https", Host: ApiEndpoint, Path: "/certificates"}
q_ := make(url.Values)
q_.Add("access_key", accessKey)
if certificateStatus != "" {
q_.Add("certificate_status", certificateStatus)
}
if search != "" {
q_.Add("search", search)
}
if limit != "" {
q_.Add("limit", limit)
}
if page != "" {
q_.Add("page", page)
}
url_.RawQuery = q_.Encode()
req.URL = url_
return
},
GetCertificate: func(accessKey, id string) (req *http.Request) {
req = &http.Request{Method: http.MethodGet}
url_ := &url.URL{Scheme: "https", Host: ApiEndpoint, Path: "/certificates/" + id}
q_ := make(url.Values)
q_.Add("access_key", accessKey)
url_.RawQuery = q_.Encode()
req.URL = url_
return
},
VerifyDomains: func(accessKey, certificateId, validationMethod, validationEmail string) (req *http.Request) {
req = &http.Request{Method: http.MethodPost}
url_ := &url.URL{Scheme: "https", Host: ApiEndpoint, Path: "/certificates/" + certificateId + "/challenges"}
q_ := make(url.Values)
q_.Add("access_key", accessKey)
url_.RawQuery = q_.Encode()
req.URL = url_
bodyForm_ := make(url.Values)
if validationMethod != "" {
bodyForm_.Add("validation_method", validationMethod)
}
if validationEmail != "" {
bodyForm_.Add("validation_email", validationEmail)
}
if len(bodyForm_) > 0 {
req.Header = make(http.Header)
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
req.Body = io.NopCloser(strings.NewReader(bodyForm_.Encode()))
}
return
},
VerificationStatus: func(accessKey, id string) (req *http.Request) {
req = &http.Request{Method: http.MethodGet}
url_ := &url.URL{Scheme: "https", Host: ApiEndpoint, Path: "/certificates/" + id + "/status"}
q_ := make(url.Values)
q_.Add("access_key", accessKey)
url_.RawQuery = q_.Encode()
req.URL = url_
return
},
CancelCertificate: func(accessKey, id string) (req *http.Request) {
req = &http.Request{Method: http.MethodPost}
url_ := &url.URL{Scheme: "https", Host: ApiEndpoint, Path: "/certificates/" + id + "/cancel"}
q_ := make(url.Values)
q_.Add("access_key", accessKey)
url_.RawQuery = q_.Encode()
req.URL = url_
return
},
DownloadCertificateInline: func(accessKey, certID, includeCrossSigned string) (req *http.Request) {
req = &http.Request{Method: http.MethodGet}
url_ := &url.URL{Scheme: "https", Host: ApiEndpoint, Path: "/certificates/" + certID + "/download/return"}
q_ := make(url.Values)
q_.Add("access_key", accessKey)
if includeCrossSigned != "" {
q_.Add("include_cross_signed", includeCrossSigned)
}
url_.RawQuery = q_.Encode()
req.URL = url_
return
},
}