2016-03-29 10:14:48 +00:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2016-03-29 16:55:17 +00:00
|
|
|
"os"
|
2016-03-29 10:14:48 +00:00
|
|
|
|
2016-03-29 17:17:51 +00:00
|
|
|
"github.com/xenolf/lego/cmd/utils"
|
2016-03-29 10:14:48 +00:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
2016-03-29 16:55:17 +00:00
|
|
|
func runHandler(cmd *cobra.Command, args []string) {
|
|
|
|
conf, acc, client := utils.Setup(RootCmd)
|
|
|
|
if acc.Registration == nil {
|
|
|
|
reg, err := client.Register()
|
|
|
|
if err != nil {
|
|
|
|
logger().Fatalf("Could not complete registration\n\t%s", err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
acc.Registration = reg
|
|
|
|
acc.Save()
|
|
|
|
email, err := RootCmd.PersistentFlags().GetString("email")
|
|
|
|
if err != nil {
|
|
|
|
logger().Fatalln(err.Error())
|
|
|
|
}
|
|
|
|
logger().Print("!!!! HEADS UP !!!!")
|
|
|
|
logger().Printf(`
|
|
|
|
Your account credentials have been saved in your Let's Encrypt
|
|
|
|
configuration directory at "%s".
|
|
|
|
You should make a secure backup of this folder now. This
|
|
|
|
configuration directory will also contain certificates and
|
|
|
|
private keys obtained from Let's Encrypt so making regular
|
|
|
|
backups of this folder is ideal.`, conf.AccountPath(email))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the agreement URL is empty, the account still needs to accept the LE TOS.
|
|
|
|
if acc.Registration.Body.Agreement == "" {
|
|
|
|
utils.HandleTOS(RootCmd, client, acc)
|
|
|
|
}
|
|
|
|
|
2016-03-29 17:04:32 +00:00
|
|
|
domains, err := RootCmd.PersistentFlags().GetStringSlice("domains")
|
|
|
|
if err != nil {
|
|
|
|
logger().Fatalln(err.Error())
|
|
|
|
}
|
|
|
|
|
2016-03-29 16:55:17 +00:00
|
|
|
if len(domains) == 0 {
|
|
|
|
logger().Fatal("Please specify --domains or -d")
|
|
|
|
}
|
|
|
|
|
2016-03-29 17:04:32 +00:00
|
|
|
nobundle, err := cmd.PersistentFlags().GetBool("no-bundle")
|
|
|
|
if err != nil {
|
|
|
|
logger().Fatalln(err.Error())
|
|
|
|
}
|
2016-03-29 16:55:17 +00:00
|
|
|
cert, failures := client.ObtainCertificate(domains, !nobundle, nil)
|
|
|
|
if len(failures) > 0 {
|
|
|
|
for k, v := range failures {
|
|
|
|
logger().Printf("[%s] Could not obtain certificates\n\t%s", k, v.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure to return a non-zero exit code if ObtainSANCertificate
|
|
|
|
// returned at least one error. Due to us not returning partial
|
|
|
|
// certificate we can just exit here instead of at the end.
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
2016-03-29 17:04:32 +00:00
|
|
|
err = utils.CheckFolder(conf.CertPath())
|
2016-03-29 16:55:17 +00:00
|
|
|
if err != nil {
|
|
|
|
logger().Fatalf("Could not check/create path: %s", err.Error())
|
|
|
|
}
|
|
|
|
|
2016-03-29 17:04:32 +00:00
|
|
|
utils.SaveCertRes(cert, conf)
|
2016-03-29 16:55:17 +00:00
|
|
|
}
|
|
|
|
|
2016-03-29 10:14:48 +00:00
|
|
|
// runCmd represents the run command
|
|
|
|
var runCmd = &cobra.Command{
|
|
|
|
Use: "run",
|
|
|
|
Short: "Register an account, then create and install a certificate",
|
2016-03-29 16:55:17 +00:00
|
|
|
Long: ``,
|
|
|
|
Run: runHandler,
|
2016-03-29 10:14:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
RootCmd.AddCommand(runCmd)
|
|
|
|
|
|
|
|
runCmd.PersistentFlags().Bool("no-bundle", false, "Do not create a certificate bundle by adding the issuers certificate to the new certificate.")
|
|
|
|
|
|
|
|
}
|