Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle the parameters parsing error in NewProvider #673

Merged
merged 1 commit into from Dec 2, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 13 additions & 9 deletions pulsar/internal/auth/provider.go
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
}