aws-sdk-go-v2 icon indicating copy to clipboard operation
aws-sdk-go-v2 copied to clipboard

S3 GetBucketNotificationConfiguration API returns uppercase FilterRule.Name (Prefix, Suffix)

Open HongChenTW opened this issue 4 years ago • 4 comments

Confirm by changing [ ] to [x] below:

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.

HongChenTW avatar May 21 '21 01:05 HongChenTW

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.

KaibaLopez avatar May 21 '21 22:05 KaibaLopez

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!

HongChenTW avatar May 24 '21 02:05 HongChenTW

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.

KaibaLopez avatar Jun 07 '21 22:06 KaibaLopez

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.

github-actions[bot] avatar Jun 08 '22 00:06 github-actions[bot]