示例#1
0
文件: ssl.go 项目: krousey/contrib
// AddOrUpdateCertAndKey creates a .pem file wth the cert and the key with the specified name
func (nginx *Manager) AddOrUpdateCertAndKey(name string, cert string, key string) (SSLCert, error) {
	pemFileName := sslDirectory + "/" + name + ".pem"

	pem, err := os.Create(pemFileName)
	if err != nil {
		return SSLCert{}, fmt.Errorf("Couldn't create pem file %v: %v", pemFileName, err)
	}
	defer pem.Close()

	_, err = pem.WriteString(fmt.Sprintf("%v\n%v", cert, key))
	if err != nil {
		return SSLCert{}, fmt.Errorf("Couldn't write to pem file %v: %v", pemFileName, err)
	}

	cn, err := nginx.commonNames(pemFileName)
	if err != nil {
		return SSLCert{}, err
	}

	return SSLCert{
		CertFileName: cert,
		KeyFileName:  key,
		PemFileName:  pemFileName,
		PemSHA:       nginx.pemSHA1(pemFileName),
		CN:           cn,
	}, nil
}
示例#2
0
// AddOrUpdateCertAndKey creates a .pem file wth the cert and the key with the specified name
func (nginx *Manager) AddOrUpdateCertAndKey(name string, cert string, key string) string {
	pemFileName := sslDirectory + "/" + name + ".pem"

	pem, err := os.Create(pemFileName)
	if err != nil {
		glog.Fatalf("Couldn't create pem file %v: %v", pemFileName, err)
	}
	defer pem.Close()

	_, err = pem.WriteString(fmt.Sprintf("%v\n%v", key, cert))
	if err != nil {
		glog.Fatalf("Couldn't write to pem file %v: %v", pemFileName, err)
	}

	return pemFileName
}