-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support issuing Lets Encrypt SSL certs
- Loading branch information
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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.api.makeRequest(http.MethodPost, "API_SSL", c.credentials, 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 | ||
} |