Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance Consistency in resolveTopicArn() Method for Handling "arn:" Prefixes in SNS #1140

Open
Seongju-Lee opened this issue Apr 27, 2024 · 0 comments

Comments

@Seongju-Lee
Copy link

Seongju-Lee commented Apr 27, 2024

Type: Feature

Is your feature request related to a problem? Please describe.

I would like to suggest something related to Topic ARN processing on SNS. In the process of sending the Sns message, the flow of fetching the Arn object is as follows:

  1. CachingTopicArnResolver.resolveTopicArn() is responsible for ARN caching, where if the topic string is not in the cache map or starts with "arn:", it create an ARN object through DefaultTopicArnResolver.

  2. In DefaultTopicArnResolver.resolveTopicArn(), if the topic parameter starts with "arn:", it converts the string into an Arn object and returns it directly; otherwise, it creates a topic and returns Arn.

If "arn:" is not prefixed in this method(DefaultTopicArnResolver.resolveTopicArn()), no exception occurs because it automatically creates a topic or returns an existing Arn.
On the other hand, if it start with "arn:", it return Arn immediately, so if it input an ARN for a non-existent topic, an exception will occur.
I believe that the DefaultTopicArnResolver.resolveTopicArn() method is not being handled consistently.

Describe the solution you'd like

I would like to improvement the TopicArnResolver.resolveTopicArn() to ensure that the resolveTopicArn() method handles consistently, regardless of whether or not the prefix "arn:".

Additionally, the CachingTopicArnResolver.resolveTopicArn() method will also be modified to support this approach.
For example, CachingTopicArnResolver.resolveTopicArn() will be modified as follows.

@Override
public Arn resolveTopicArn(String topicName) {
    Assert.notNull(topicName, "topicName is required");

    if (topicName.toLowerCase().startsWith("arn:")) {
        Arn arn = delegate.resolveTopicArn(topicName);
        Arn startIndex = ...  // extract topicName start Index in ARN
        return cache.computeIfAbsent(topicName.substring(startIndex), delegate::resolveTopicArn);
    }

    return cache.computeIfAbsent(topicName, delegate::resolveTopicArn);
}

Additional context

This proposal is expected to contribute significantly to increasing functional consistency!! :)

@Seongju-Lee Seongju-Lee changed the title Enhance Consistency in resolveTopicArn() Method for Handling ARN Prefixes in SNS Enhance Consistency in resolveTopicArn() Method for Handling "arn:" Prefixes in SNS Apr 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant