From 612033a83a41de8a42b0baee212ad1169d637052 Mon Sep 17 00:00:00 2001 From: xenolf Date: Sat, 13 Jun 2015 03:56:34 +0200 Subject: [PATCH] Flesh out run cli_handler for error handling and saving certificates --- acme/messages.go | 1 + cli_handlers.go | 28 +++++++++++++++++++++++++++- configuration.go | 4 ++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/acme/messages.go b/acme/messages.go index 4f99bcff..609e8b70 100644 --- a/acme/messages.go +++ b/acme/messages.go @@ -33,6 +33,7 @@ type authorizationResource struct { Body authorization Domain string NewCertURL string + AuthURL string } type authorization struct { diff --git a/cli_handlers.go b/cli_handlers.go index 918ade17..fb60bf8a 100644 --- a/cli_handlers.go +++ b/cli_handlers.go @@ -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) + } + + } } diff --git a/configuration.go b/configuration.go index 3d4186ed..0bd27f3b 100644 --- a/configuration.go +++ b/configuration.go @@ -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 {