Allowing anonymous connections
Updating rule to allow an anonymous connection without credentials
@@ -62,7 +62,7 @@ func isValidPEM(val string) bool {
}
func parseAMQPMetaData(md pubsub.Metadata, log logger.Logger) (*metadata, error) {
- m := metadata{}
+ m := metadata{anonymous: false}
// required configuration settings
if val, ok := md.Properties[amqpUrl]; ok && val != "" {
@@ -71,6 +71,17 @@ func parseAMQPMetaData(md pubsub.Metadata, log logger.Logger) (*metadata, error)
return &m, fmt.Errorf("%s missing url", errorMsgPrefix)
}
+ // optional configuration settings
+ if val, ok := md.Properties[anonymous]; ok && val != "" {
+ var err error
+ m.anonymous, err = strconv.ParseBool(val)
+ if err != nil {
+ return &m, fmt.Errorf("%s invalid anonymous %s, %s", errorMsgPrefix, val, err)
+ }
+ }
+
+ if !m.anonymous {
+
if val, ok := md.Properties[username]; ok && val != "" {
m.username = val
} else {
@@ -82,15 +93,8 @@ func parseAMQPMetaData(md pubsub.Metadata, log logger.Logger) (*metadata, error)
} else {
return &m, fmt.Errorf("%s missing username", errorMsgPrefix)
}
-
- // optional configuration settings
- if val, ok := md.Properties[anonymous]; ok && val != "" {
- var err error
- m.anonymous, err = strconv.ParseBool(val)
- if err != nil {
- return &m, fmt.Errorf("%s invalid anonymous %s, %s", errorMsgPrefix, val, err)
- }
}
+
if val, ok := md.Properties[amqpCACert]; ok && val != "" {
if !isValidPEM(val) {
return &m, fmt.Errorf("%s invalid caCert", errorMsgPrefix)
