forked from TrueCloudLab/lego
Add filename parameter (#612)
This commit is contained in:
parent
5a1c3d2134
commit
89eff6fc7b
2 changed files with 20 additions and 3 deletions
4
cli.go
4
cli.go
|
@ -109,6 +109,10 @@ func main() {
|
||||||
Name: "email, m",
|
Name: "email, m",
|
||||||
Usage: "Email used for registration and recovery contact.",
|
Usage: "Email used for registration and recovery contact.",
|
||||||
},
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "filename",
|
||||||
|
Usage: "Filename of the generated certificate",
|
||||||
|
},
|
||||||
cli.BoolFlag{
|
cli.BoolFlag{
|
||||||
Name: "accept-tos, a",
|
Name: "accept-tos, a",
|
||||||
Usage: "By setting this flag to true you indicate that you accept the current Let's Encrypt terms of service.",
|
Usage: "By setting this flag to true you indicate that you accept the current Let's Encrypt terms of service.",
|
||||||
|
|
|
@ -11,6 +11,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -151,8 +152,15 @@ func setup(c *cli.Context) (*Configuration, *Account, *acme.Client) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func saveCertRes(certRes *acme.CertificateResource, conf *Configuration) {
|
func saveCertRes(certRes *acme.CertificateResource, conf *Configuration) {
|
||||||
// make sure no funny chars are in the cert names (like wildcards ;))
|
var domainName string
|
||||||
domainName := strings.Replace(certRes.Domain, "*", "_", -1)
|
|
||||||
|
// Check filename cli parameter
|
||||||
|
if conf.context.GlobalString("filename") == "" {
|
||||||
|
// Make sure no funny chars are in the cert names (like wildcards ;))
|
||||||
|
domainName = strings.Replace(certRes.Domain, "*", "_", -1)
|
||||||
|
} else {
|
||||||
|
domainName = conf.context.GlobalString("filename")
|
||||||
|
}
|
||||||
|
|
||||||
// We store the certificate, private key and metadata in different files
|
// We store the certificate, private key and metadata in different files
|
||||||
// as web servers would not be able to work with a combined file.
|
// as web servers would not be able to work with a combined file.
|
||||||
|
@ -162,7 +170,12 @@ func saveCertRes(certRes *acme.CertificateResource, conf *Configuration) {
|
||||||
metaOut := path.Join(conf.CertPath(), domainName+".json")
|
metaOut := path.Join(conf.CertPath(), domainName+".json")
|
||||||
issuerOut := path.Join(conf.CertPath(), domainName+".issuer.crt")
|
issuerOut := path.Join(conf.CertPath(), domainName+".issuer.crt")
|
||||||
|
|
||||||
err := ioutil.WriteFile(certOut, certRes.Certificate, 0600)
|
err := checkFolder(filepath.Dir(certOut))
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Could not check/create path: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = ioutil.WriteFile(certOut, certRes.Certificate, 0600)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Unable to save Certificate for domain %s\n\t%v", certRes.Domain, err)
|
log.Fatalf("Unable to save Certificate for domain %s\n\t%v", certRes.Domain, err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue