Skip to content

Commit

Permalink
handle the parameters parsing error in NewProvider (#673)
Browse files Browse the repository at this point in the history
  • Loading branch information
reugn authored Dec 2, 2021
1 parent 53d9c28 commit 7ab9b4c
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions pulsar/internal/auth/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,17 @@ 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

// 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.
Expand All @@ -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 "":
Expand All @@ -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
}

0 comments on commit 7ab9b4c

Please sign in to comment.