forked from TrueCloudLab/lego
Flesh out run cli_handler for error handling and saving certificates
This commit is contained in:
parent
a2d9bf4cc3
commit
612033a83a
3 changed files with 32 additions and 1 deletions
|
@ -33,6 +33,7 @@ type authorizationResource struct {
|
|||
Body authorization
|
||||
Domain string
|
||||
NewCertURL string
|
||||
AuthURL string
|
||||
}
|
||||
|
||||
type authorization struct {
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue