From 7ab9b4c11bf7bcd7225f3e5550fffa34b96ca686 Mon Sep 17 00:00:00 2001 From: Eugene R Date: Thu, 2 Dec 2021 19:52:06 +0200 Subject: [PATCH] handle the parameters parsing error in NewProvider (#673) --- pulsar/internal/auth/provider.go | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/pulsar/internal/auth/provider.go b/pulsar/internal/auth/provider.go index de718393a8..1731490001 100644 --- a/pulsar/internal/auth/provider.go +++ b/pulsar/internal/auth/provider.go @@ -23,11 +23,9 @@ import ( "fmt" "io" "net/http" - - "github.com/pkg/errors" ) -// Provider is a interface of authentication providers. +// Provider is an interface of authentication providers. type Provider interface { // Init the authentication provider. Init() error @@ -35,7 +33,7 @@ type Provider interface { // Name func returns the identifier for this authentication method. Name() string - // return a client certificate chain, or nil if the data are not available + // GetTLSCertificate returns a client certificate chain, or nil if the data are not available GetTLSCertificate() (*tls.Certificate, error) // GetData returns the authentication data identifying this client that will be sent to the broker. @@ -61,7 +59,10 @@ type HTTPTransport struct { // Some authentication method need to auth between each client channel. So it need // the broker, who it will talk to. func NewProvider(name string, params string) (Provider, error) { - m := parseParams(params) + m, err := parseParams(params) + if err != nil { + return nil, err + } switch name { case "": @@ -80,12 +81,15 @@ func NewProvider(name string, params string) (Provider, error) { return NewAuthenticationOAuth2WithParams(m) default: - return nil, errors.New(fmt.Sprintf("invalid auth provider '%s'", name)) + return nil, fmt.Errorf("invalid auth provider '%s'", name) } } -func parseParams(params string) map[string]string { +func parseParams(params string) (map[string]string, error) { var mapString map[string]string - json.Unmarshal([]byte(params), &mapString) - return mapString + if err := json.Unmarshal([]byte(params), &mapString); err != nil { + return nil, err + } + + return mapString, nil }