mirror of
https://gitee.com/rainbond/Rainbond.git
synced 2024-12-02 11:47:36 +08:00
fix issue/650
This commit is contained in:
parent
f9849d4c22
commit
a639e42200
@ -20,6 +20,8 @@ package store
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/x509"
|
||||
"encoding/pem"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
@ -817,7 +819,6 @@ func (s *k8sStore) syncSecret(secrKey string) {
|
||||
logrus.Errorf("fail to get certificate pem: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
old, exists := s.sslStore.Get(secrKey)
|
||||
if exists {
|
||||
oldSSLCert := old.(*v1.SSLCert)
|
||||
@ -858,9 +859,22 @@ func (s *k8sStore) getCertificatePem(secrKey string) (*v1.SSLCert, error) {
|
||||
if e := ioutil.WriteFile(filename, buffer.Bytes(), 0666); e != nil {
|
||||
return nil, fmt.Errorf("cant not write data to %s: %v", filename, e)
|
||||
}
|
||||
fileContent, err := ioutil.ReadFile(filename)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("read certificate file failed: %s", err.Error())
|
||||
}
|
||||
pemContent, _ := pem.Decode(fileContent)
|
||||
certificate, err := x509.ParseCertificate(pemContent.Bytes)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("generate certificate object failed: %s", err.Error())
|
||||
}
|
||||
|
||||
return &v1.SSLCert{
|
||||
CertificatePem: filename,
|
||||
Certificate: certificate,
|
||||
CertificateStr: string(certificate.Raw),
|
||||
PrivateKey: string(key),
|
||||
CN: []string{certificate.Subject.CommonName},
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user