Skip to content

Commit

Permalink
Merge pull request go-acme#42 from xenolf/add-renew-time
Browse files Browse the repository at this point in the history
Add a way for cronjobs to automatically renew certificates.
  • Loading branch information
xenolf committed Dec 7, 2015
2 parents a528107 + 1573f13 commit 3cf9fe6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
7 changes: 7 additions & 0 deletions cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ func main() {
Name: "renew",
Usage: "Renew a certificate",
Action: renew,
Flags: []cli.Flag{
cli.IntFlag{
Name: "days",
Value: 0,
Usage: "The number of days left on a certificate to renew it.",
},
},
},
}

Expand Down
12 changes: 12 additions & 0 deletions cli_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"
"path"
"strings"
"time"

"github.com/codegangsta/cli"
"github.com/xenolf/lego/acme"
Expand Down Expand Up @@ -181,6 +182,17 @@ func renew(c *cli.Context) {
return
}

if c.IsSet("days") {
expTime, err := acme.GetPEMCertExpiration(certBytes)
if err != nil {
logger().Printf("Could not get Certification expiration for domain %s", domain)
}

if int(expTime.Sub(time.Now()).Hours() / 24.0) <= c.Int("days") {
continue
}
}

keyBytes, err := ioutil.ReadFile(privPath)
if err != nil {
logger().Printf("Error while loading the private key for domain %s\n\t%v", domain, err)
Expand Down

0 comments on commit 3cf9fe6

Please sign in to comment.