Allowing anonymous connections

Updating rule to allow an anonymous connection without credentials

Signed-off-by: TKTheTechie <thomas.kunnumpurath@solace.com>
This commit is contained in:
TKTheTechie 2022-12-21 16:32:50 -05:00
parent 57c2324670
commit a5dfcb80fa
1 changed files with 17 additions and 13 deletions

View File

@ -62,7 +62,7 @@ func isValidPEM(val string) bool {
} }
func parseAMQPMetaData(md pubsub.Metadata, log logger.Logger) (*metadata, error) { func parseAMQPMetaData(md pubsub.Metadata, log logger.Logger) (*metadata, error) {
m := metadata{} m := metadata{anonymous: false}
// required configuration settings // required configuration settings
if val, ok := md.Properties[amqpUrl]; ok && val != "" { 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) 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 != "" { if val, ok := md.Properties[username]; ok && val != "" {
m.username = val m.username = val
} else { } else {
@ -82,15 +93,8 @@ func parseAMQPMetaData(md pubsub.Metadata, log logger.Logger) (*metadata, error)
} else { } else {
return &m, fmt.Errorf("%s missing username", errorMsgPrefix) 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 val, ok := md.Properties[amqpCACert]; ok && val != "" {
if !isValidPEM(val) { if !isValidPEM(val) {
return &m, fmt.Errorf("%s invalid caCert", errorMsgPrefix) return &m, fmt.Errorf("%s invalid caCert", errorMsgPrefix)