1111using System . Collections . Generic ;
1212using System . Linq ;
1313using System . Threading . Tasks ;
14+ using Amazon ;
1415using Amazon . SimpleNotificationService . Model ;
1516using GuiStack . Authentication . AWS ;
1617using GuiStack . Extensions ;
@@ -22,6 +23,7 @@ public interface ISNSRepository
2223 {
2324 Task CreateTopicAsync ( SNSCreateTopicModel model ) ;
2425 Task < IEnumerable < SNSTopic > > GetTopicsAsync ( ) ;
26+ Task < SNSTopicInfo > GetTopicAttributesAsync ( string topicArn ) ;
2527 Task DeleteTopicAsync ( string topicArn ) ;
2628 }
2729
@@ -43,7 +45,8 @@ public async Task CreateTopicAsync(SNSCreateTopicModel model)
4345 var response = await sns . CreateTopicAsync ( new CreateTopicRequest ( ) {
4446 Name = topicName ,
4547 Attributes = new Dictionary < string , string > ( ) {
46- { "FifoTopic" , model . IsFifo . ToString ( ) . ToLower ( ) }
48+ { "FifoTopic" , model . IsFifo . ToString ( ) . ToLower ( ) } ,
49+ { "ContentBasedDeduplication" , model . IsFifo ? model . ContentBasedDeduplication . ToString ( ) . ToLower ( ) : "false" }
4750 }
4851 } ) ;
4952
@@ -60,6 +63,34 @@ public async Task<IEnumerable<SNSTopic>> GetTopicsAsync()
6063 return response . Topics . Select ( topic => new SNSTopic ( topic . TopicArn ) ) ;
6164 }
6265
66+ public async Task < SNSTopicInfo > GetTopicAttributesAsync ( string topicName )
67+ {
68+ using var sns = authenticator . Authenticate ( ) ;
69+ var topic = await sns . FindTopicAsync ( topicName ) ;
70+
71+ if ( topic == null )
72+ throw new KeyNotFoundException ( $ "Topic with name '{ topicName } ' was not found") ;
73+
74+ var response = await sns . GetTopicAttributesAsync ( topic . TopicArn ) ;
75+
76+ response . ThrowIfUnsuccessful ( "SNS" ) ;
77+
78+ var subscriptionsConfirmed = response . Attributes . GetValueOrDefault ( "SubscriptionsConfirmed" ) ;
79+ var subscriptionsDeleted = response . Attributes . GetValueOrDefault ( "SubscriptionsDeleted" ) ;
80+ var subscriptionsPending = response . Attributes . GetValueOrDefault ( "SubscriptionsPending" ) ;
81+ var fifoTopic = response . Attributes . GetValueOrDefault ( "FifoTopic" ) ?? "" ;
82+ var contentBasedDeduplication = response . Attributes . GetValueOrDefault ( "ContentBasedDeduplication" ) ?? "" ;
83+
84+ return new SNSTopicInfo ( ) {
85+ TopicARN = Arn . Parse ( topic . TopicArn ) ,
86+ SubscriptionsConfirmed = int . TryParse ( subscriptionsConfirmed ?? "" , out var i ) ? i : 0 ,
87+ SubscriptionsDeleted = int . TryParse ( subscriptionsDeleted ?? "" , out i ) ? i : 0 ,
88+ SubscriptionsPending = int . TryParse ( subscriptionsPending ?? "" , out i ) ? i : 0 ,
89+ FifoTopic = fifoTopic . Equals ( "true" , StringComparison . OrdinalIgnoreCase ) ,
90+ ContentBasedDeduplication = contentBasedDeduplication . Equals ( "true" , StringComparison . OrdinalIgnoreCase )
91+ } ;
92+ }
93+
6394 public async Task DeleteTopicAsync ( string topicArn )
6495 {
6596 if ( string . IsNullOrWhiteSpace ( topicArn ) )
0 commit comments