Check xcerts.Manager is initialized before adding certificates (#673)
This commit is contained in:
@@ -17,6 +17,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
@@ -146,15 +147,14 @@ func startServer(ctx *cli.Context) error {
|
|||||||
SwaggerServerCACertificate := ctx.String("tls-ca")
|
SwaggerServerCACertificate := ctx.String("tls-ca")
|
||||||
// load tls cert and key from swagger server tls-certificate and tls-key flags
|
// load tls cert and key from swagger server tls-certificate and tls-key flags
|
||||||
if swaggerServerCertificate != "" && swaggerServerCertificateKey != "" {
|
if swaggerServerCertificate != "" && swaggerServerCertificateKey != "" {
|
||||||
if errAddCert := restapi.GlobalTLSCertsManager.AddCertificate(swaggerServerCertificate, swaggerServerCertificateKey); errAddCert == nil {
|
if errAddCert := certs.AddCertificate(context.Background(), restapi.GlobalTLSCertsManager, swaggerServerCertificate, swaggerServerCertificateKey); errAddCert != nil {
|
||||||
if x509Certs, errParseCert := config.ParsePublicCertFile(swaggerServerCertificate); errParseCert == nil && len(x509Certs) > 0 {
|
|
||||||
restapi.GlobalPublicCerts = append(restapi.GlobalPublicCerts, x509Certs[0])
|
|
||||||
} else {
|
|
||||||
log.Println(errParseCert)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
log.Println(errAddCert)
|
log.Println(errAddCert)
|
||||||
}
|
}
|
||||||
|
if x509Certs, errParseCert := config.ParsePublicCertFile(swaggerServerCertificate); errParseCert == nil {
|
||||||
|
if len(x509Certs) > 0 {
|
||||||
|
restapi.GlobalPublicCerts = append(restapi.GlobalPublicCerts, x509Certs[0])
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// load ca cert from swagger server tls-ca flag
|
// load ca cert from swagger server tls-ca flag
|
||||||
if SwaggerServerCACertificate != "" {
|
if SwaggerServerCACertificate != "" {
|
||||||
|
|||||||
@@ -228,3 +228,14 @@ func GetAllCertificatesAndCAs() (*x509.CertPool, []*x509.Certificate, *xcerts.Ma
|
|||||||
logger.FatalIf(err, "Unable to load the TLS configuration")
|
logger.FatalIf(err, "Unable to load the TLS configuration")
|
||||||
return GlobalRootCAs, globalPublicCerts, globalTLSCertsManager
|
return GlobalRootCAs, globalPublicCerts, globalTLSCertsManager
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AddCertificate check if Manager is initialized and then append a new certificate to it
|
||||||
|
func AddCertificate(ctx context.Context, manager *xcerts.Manager, publicKey, privateKey string) (err error) {
|
||||||
|
// If Cert Manager is not nil add more certificates
|
||||||
|
if manager != nil {
|
||||||
|
return manager.AddCertificate(publicKey, privateKey)
|
||||||
|
}
|
||||||
|
// Initialize cert manager
|
||||||
|
manager, err = xcerts.NewManager(ctx, publicKey, privateKey, config.LoadX509KeyPair)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|||||||
@@ -557,9 +557,7 @@ const ViewBucket = ({
|
|||||||
setPolicyEdit(row);
|
setPolicyEdit(row);
|
||||||
};
|
};
|
||||||
|
|
||||||
const PolicyActions = [
|
const PolicyActions = [{ type: "view", onClick: viewAction }];
|
||||||
{ type: "view", onClick: viewAction },
|
|
||||||
];
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Fragment>
|
<Fragment>
|
||||||
|
|||||||
Reference in New Issue
Block a user