aws-sdk-go-v2
aws-sdk-go-v2 copied to clipboard
S3 GetBucketNotificationConfiguration API returns uppercase FilterRule.Name (Prefix, Suffix)
Confirm by changing [ ] to [x] below:
- [x] I've gone though the API reference
- [x] I've checked AWS Forums and StackOverflow for answers
Describe the question
https://github.com/aws/aws-sdk-go-v2/blob/31459368544ba0cafeee5f0f91e957826627e7e1/service/s3/api_op_GetBucketNotificationConfiguration.go#L30
When request GetBucketNotificationConfiguration api, GetBucketNotificationConfigurationOutput always return uppercase FilterRule.Name (Prefix, Suffix), but FilterRule type is also use FilterRuleName as type, which cause when we want to compare output with constant variable FilterRuleNamePrefix, we need to lowercase the output FilterRule.Name first.
https://github.com/aws/aws-sdk-go-v2/blob/31459368544ba0cafeee5f0f91e957826627e7e1/service/s3/types/enums.go#L336-L352
Is there any suggestions to better handle this comparison?
Thanks.
Not sure if I understand the question, what do you mean by "better handle this comparison?" either lower casing the output or doing an ignore case string comparison should work for this.
For example:
We passed topic configuration from GetBucketNotificationConfigurationOutput to HandleTopicConfiguration function below.
import (
"strings"
s3_types "github.com/aws/aws-sdk-go-v2/service/s3/types"
)
func HandleTopicConfiguration(configuration s3_types.TopicConfiguration) bool {
for _, r := range configuration.Filter.Key.FilterRules {
// 1. event r.Name is prefix, this condition will never be fulfilled,
// but r.Name & s3_types.FilterRuleNamePrefix are the same type,
// r.Name seems to return uppercase "Prefix/Suffix"
if r.Name == s3_types.FilterRuleNamePrefix {
// do something
}
if r.Name == s3_types.FilterRuleNameSuffix {
// do something
}
// 2. we have to lowercase first to do the comparison
if strings.ToLower(string(r.Name)) == string(s3_types.FilterRuleNamePrefix) {
// do something
}
if strings.ToLower(string(r.Name)) == string(s3_types.FilterRuleNameSuffix) {
// do something
}
}
return true
}
Does ignore case string comparison means we can use such as strings.EqualFold() function to do the comparison? Because constant variables FilterRuleNamePrefix/FilterRuleNameSuffix are defined, we thought that is consistent to use these two variables.
Thanks for your reply!
Yea, and I mean this in a, "as a workaround" way.
This is definitely a typo on our part, but yea strings.EqualFold() should work for these comparison.
We have noticed this issue has not received attention in 1 year. We will close this issue for now. If you think this is in error, please feel free to comment and reopen the issue.