Skip to content

Commit

Permalink
Fix default value check when setting SASL authentication from URI
Browse files Browse the repository at this point in the history
  • Loading branch information
vilius-g committed Mar 2, 2024
1 parent 5cbe37d commit 4835984
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,22 @@ func DialConfig(url string, config Config) (*Connection, error) {
}

if config.SASL == nil {
config.SASL = []Authentication{uri.PlainAuth()}
if uri.AuthMechanism != nil {
for _, identifier := range uri.AuthMechanism {
switch strings.ToUpper(identifier) {
case "PLAIN":
config.SASL = append(config.SASL, uri.PlainAuth())
case "AMQPLAIN":
config.SASL = append(config.SASL, uri.AMQPlainAuth())
case "EXTERNAL":
config.SASL = append(config.SASL, &ExternalAuth{})
default:
return nil, fmt.Errorf("unsupported auth_mechanism: %v", identifier)
}
}
} else {
config.SASL = []Authentication{uri.PlainAuth()}
}
}

if config.Vhost == "" {
Expand All @@ -226,21 +241,6 @@ func DialConfig(url string, config Config) (*Connection, error) {
connectionTimeout = time.Duration(uri.ConnectionTimeout) * time.Millisecond
}

if config.SASL == nil && uri.AuthMechanism != nil {
for _, identifier := range uri.AuthMechanism {
switch strings.ToUpper(identifier) {
case "PLAIN":
config.SASL = append(config.SASL, uri.PlainAuth())
case "AMQPLAIN":
config.SASL = append(config.SASL, uri.AMQPlainAuth())
case "EXTERNAL":
config.SASL = append(config.SASL, &ExternalAuth{})
default:
return nil, fmt.Errorf("unsupported auth_mechanism: %v", identifier)
}
}
}

addr := net.JoinHostPort(uri.Host, strconv.FormatInt(int64(uri.Port), 10))

dialer := config.Dial
Expand Down

0 comments on commit 4835984

Please sign in to comment.