-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathssl.go
46 lines (37 loc) · 1.11 KB
/
ssl.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
package directadmin
import (
"errors"
"fmt"
"net/http"
"net/url"
"github.com/spf13/cast"
)
// IssueSSL (user) requests a lets encrypt certificate for the given hostnames
func (c *UserContext) IssueSSL(domain string, hostnamesToCertify ...string) error {
var response apiGenericResponse
if len(hostnamesToCertify) == 0 {
return errors.New("at least one hostname is required for the certificate")
}
body := url.Values{
"type": {"create"},
"request": {"letsencrypt"},
"name": {hostnamesToCertify[0]},
"domain": {domain},
"keysize": {"secp384r1"},
"encryption": {"sha256"},
"wildcard": {"no"},
"background": {"auto"},
"action": {"save"},
"acme_provider": {"letsencrypt"},
}
for index, certDomain := range hostnamesToCertify {
body.Set("le_select"+cast.ToString(index), certDomain)
}
if _, err := c.makeRequestOld(http.MethodPost, "API_SSL", body, &response); err != nil {
return err
}
if response.Success != "Certificate and Key Saved." {
return fmt.Errorf("failed to issue SSL certificate: %v", response.Result)
}
return nil
}