From d9173e696e7515085d9c14cf41473cd796fbe646 Mon Sep 17 00:00:00 2001 From: Yousong Zhou Date: Thu, 18 Oct 2018 08:59:27 +0000 Subject: [PATCH] loadbalancercertificates: make code compatible with go-1.9 Upstream go commit id https://github.com/golang/go/commit/34920b8713fa93ee50ee8963949728c1569e6017 --- .../models/loadbalancercertificates.go | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/pkg/compute/models/loadbalancercertificates.go b/pkg/compute/models/loadbalancercertificates.go index d1603881a6..69ce56a696 100644 --- a/pkg/compute/models/loadbalancercertificates.go +++ b/pkg/compute/models/loadbalancercertificates.go @@ -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 {