2016-03-29 10:14:48 +00:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2016-03-29 16:55:17 +00:00
|
|
|
"io/ioutil"
|
|
|
|
"path"
|
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 revokeHandler(cmd *cobra.Command, args []string) {
|
2016-03-29 17:04:32 +00:00
|
|
|
conf, _, client := utils.Setup(RootCmd)
|
2016-03-29 16:55:17 +00:00
|
|
|
|
2016-03-29 17:04:32 +00:00
|
|
|
err := utils.CheckFolder(conf.CertPath())
|
|
|
|
if err != nil {
|
|
|
|
logger().Fatalf("Could not check/create path: %s", err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
domains, err := RootCmd.PersistentFlags().GetStringSlice("domains")
|
|
|
|
if err != nil {
|
|
|
|
logger().Fatalln(err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, domain := range domains {
|
|
|
|
logger().Printf("Trying to revoke certificate for domain %s", domain)
|
|
|
|
|
|
|
|
certPath := path.Join(conf.CertPath(), domain+".crt")
|
|
|
|
certBytes, err := ioutil.ReadFile(certPath)
|
|
|
|
|
|
|
|
err = client.RevokeCertificate(certBytes)
|
|
|
|
if err != nil {
|
|
|
|
logger().Fatalf("Error while revoking the certificate for domain %s\n\t%s", domain, err.Error())
|
|
|
|
} else {
|
|
|
|
logger().Print("Certificate was revoked.")
|
|
|
|
}
|
|
|
|
}
|
2016-03-29 16:55:17 +00:00
|
|
|
}
|
|
|
|
|
2016-03-29 10:14:48 +00:00
|
|
|
// revokeCmd represents the revoke command
|
|
|
|
var revokeCmd = &cobra.Command{
|
|
|
|
Use: "revoke",
|
|
|
|
Short: "Revoke a certificate",
|
2016-03-29 16:55:17 +00:00
|
|
|
Long: ``,
|
2016-03-29 17:04:32 +00:00
|
|
|
Run: revokeHandler,
|
2016-03-29 10:14:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
RootCmd.AddCommand(revokeCmd)
|
2016-03-29 16:55:17 +00:00
|
|
|
|
2016-03-29 10:14:48 +00:00
|
|
|
}
|