1
0
mirror of https://github.com/go-acme/lego.git synced 2024-12-25 11:02:56 +02:00

Flesh out run cli_handler for error handling and saving certificates

This commit is contained in:
xenolf 2015-06-13 03:56:34 +02:00
parent a2d9bf4cc3
commit 612033a83a
3 changed files with 32 additions and 1 deletions

View File

@ -33,6 +33,7 @@ type authorizationResource struct {
Body authorization
Domain string
NewCertURL string
AuthURL string
}
type authorization struct {

View File

@ -2,7 +2,9 @@ package main
import (
"bufio"
"io/ioutil"
"os"
"path"
"strings"
"github.com/codegangsta/cli"
@ -92,5 +94,29 @@ func run(c *cli.Context) {
logger().Fatal("Please specify --domains")
}
client.ObtainCertificates(c.GlobalStringSlice("domains"))
certs, err := client.ObtainCertificates(c.GlobalStringSlice("domains"))
if err != nil {
logger().Fatalf("Could not obtain certificates -> %v", err)
}
err = checkFolder(conf.CertPath())
if err != nil {
logger().Fatalf("Cound not check/create path: %v", err)
}
for _, certRes := range certs {
certOut := path.Join(conf.CertPath(), certRes.Domain+".crt")
privOut := path.Join(conf.CertPath(), certRes.Domain+".key")
err = ioutil.WriteFile(certOut, certRes.Certificate, 0700)
if err != nil {
logger().Printf("Unable to save Certificate for domain %s -> %v", certRes.Domain, err)
}
err = ioutil.WriteFile(privOut, certRes.PrivateKey, 0700)
if err != nil {
logger().Printf("Unable to save PrivateKey for domain %s -> %v", certRes.Domain, err)
}
}
}

View File

@ -35,6 +35,10 @@ func (c *Configuration) ServerPath() string {
return strings.Replace(srvStr, "/", string(os.PathSeparator), -1)
}
func (c *Configuration) CertPath() string {
return path.Join(c.context.GlobalString("path"), "certificates")
}
// AccountsPath returns the OS dependent path to the
// local accounts for a specific CA
func (c *Configuration) AccountsPath() string {