Exemplo n.º 1
0
Arquivo: main.go Projeto: polvi/cad
func main() {
	flag.Parse()

	c, err := client.NewCaClient(*cadAddr, false, "", "")
	if err != nil {
		fmt.Println(err)
		return
	}
	csr, priv, err := x509ez.CreateMinCertificateRequest()
	if err != nil {
		fmt.Println(err)
		return
	}
	cert, err := c.SignCert(csr, time.Duration(10*time.Second))
	if err != nil {
		fmt.Println(err)
		return
	}
	if err := x509ez.WriteCertToFile(cert, *certOutFile); err != nil {
		fmt.Println(err)
		return
	}
	if err := x509ez.WriteKeyToFile(priv, *keyOutFile); err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println("wrote keys, sleeping until", cert.NotAfter)
	time.Sleep(cert.NotAfter.Sub(time.Now()))
}
Exemplo n.º 2
0
Arquivo: main.go Projeto: polvi/cad
func main() {
	flag.Parse()
	if *secretName == "" && (*caCertFile == "" || *caKeyFile == "") {
		fmt.Println("must specify -secret-name or -ca-cert/key")
		return
	}
	dur, err := time.ParseDuration(*selfSignedDuration)
	if err != nil {
		fmt.Println(err)
		return
	}
	if *secretName != "" {
		objBytes, err := kube.CreateMinSelfSignedCACertificateSecret(*secretName, dur)
		if err != nil {
			fmt.Println(err)
			return
		}
		fmt.Print(string(objBytes))
	}
	if *caCertFile != "" && *caKeyFile != "" {
		cert, priv, err := x509ez.CreateMinSelfSignedCACertificate(dur)
		if err != nil {
			fmt.Println(err)
			return
		}
		if err := x509ez.WriteKeyToFile(priv, *caKeyFile); err != nil {
			fmt.Println(err)
			return
		}
		if err := x509ez.WriteCertToFile(cert, *caCertFile); err != nil {
			fmt.Println(err)
			return
		}
		fmt.Println("wrote keys to", *caCertFile, *caKeyFile)
	}
}