loadbalancercertificates: make code compatible with go-1.9

Upstream go commit id

	https://github.com/golang/go/commit/34920b8713fa93ee50ee8963949728c1569e6017
This commit is contained in:
Yousong Zhou
2018-10-18 09:07:18 +00:00
parent b188bc85ce
commit d9173e696e
+16 -4
View File
@@ -2,6 +2,7 @@ package models
import (
"context"
"crypto/x509"
"fmt"
"strings"
"time"
@@ -74,10 +75,21 @@ func (man *SLoadbalancerCertificateManager) validateCertKey(ctx context.Context,
}
}
cert := certV.Certificates[0]
certPubKeyAlgo := cert.PublicKeyAlgorithm.String()
if !LB_TLS_CERT_PUBKEY_ALGOS.Has(certPubKeyAlgo) {
return nil, httperrors.NewInputParameterError("invalid cert pubkey algorithm: %s, want %s",
certPubKeyAlgo, LB_TLS_CERT_PUBKEY_ALGOS.String())
var certPubKeyAlgo string
{
// x509.PublicKeyAlgorithm.String() is only available since go1.10
switch cert.PublicKeyAlgorithm {
case x509.RSA:
certPubKeyAlgo = LB_TLS_CERT_PUBKEY_ALGO_RSA
case x509.ECDSA:
certPubKeyAlgo = LB_TLS_CERT_PUBKEY_ALGO_ECDSA
default:
certPubKeyAlgo = fmt.Sprintf("algo %#v", cert.PublicKeyAlgorithm)
}
if !LB_TLS_CERT_PUBKEY_ALGOS.Has(certPubKeyAlgo) {
return nil, httperrors.NewInputParameterError("invalid cert pubkey algorithm: %s, want %s",
certPubKeyAlgo, LB_TLS_CERT_PUBKEY_ALGOS.String())
}
}
err := pkeyV.MatchCertificate(cert)
if err != nil {