Skip to content

Commit 60111c9

Browse files
committed
pr comments
1 parent fee4386 commit 60111c9

File tree

6 files changed

+20
-10
lines changed

6 files changed

+20
-10
lines changed

Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Models/Attributes/AttributeModelBuilder.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
using System;
55
using Amazon.Lambda.Annotations.ALB;
6-
using Amazon.Lambda.Annotations.SNS;
76
using Amazon.Lambda.Annotations.APIGateway;
87
using Amazon.Lambda.Annotations.S3;
98
using Amazon.Lambda.Annotations.SQS;
@@ -117,7 +116,7 @@ public static AttributeModel Build(AttributeData att, GeneratorExecutionContext
117116
else if (att.AttributeClass.Equals(context.Compilation.GetTypeByMetadataName(TypeFullNames.SNSEventAttribute), SymbolEqualityComparer.Default))
118117
{
119118
var data = SNSEventAttributeBuilder.Build(att);
120-
model = new AttributeModel<Amazon.Lambda.Annotations.SNS.SNSEventAttribute>
119+
model = new AttributeModel<SNS.SNSEventAttribute>
121120
{
122121
Data = data,
123122
Type = TypeModelBuilder.Build(att.AttributeClass, context)

Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Writers/CloudFormationWriter.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -697,10 +697,7 @@ private string ProcessSnsAttribute(ILambdaFunctionSerializable lambdaFunction, S
697697
else
698698
{
699699
var topic = att.Topic.Substring(1);
700-
if (_templateWriter.Exists($"{PARAMETERS}.{topic}"))
701-
SetEventProperty(syncedEventProperties, lambdaFunction.ResourceName, eventName, $"Topic.{REF}", topic);
702-
else
703-
SetEventProperty(syncedEventProperties, lambdaFunction.ResourceName, eventName, $"Topic.{REF}", topic);
700+
SetEventProperty(syncedEventProperties, lambdaFunction.ResourceName, eventName, $"Topic.{REF}", topic);
704701
}
705702

706703
// FilterPolicy

Libraries/src/Amazon.Lambda.Annotations/SNS/SNSEventAttribute.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,20 @@ public string ResourceName
3232
{
3333
return resourceName;
3434
}
35+
if (string.IsNullOrEmpty(Topic))
36+
{
37+
return string.Empty;
38+
}
3539
if (Topic.StartsWith("@"))
3640
{
3741
return Topic.Substring(1);
3842
}
3943

4044
var arnTokens = Topic.Split(new char[] { ':' }, 6);
45+
if (arnTokens.Length < 6)
46+
{
47+
return Topic;
48+
}
4149
var topicName = arnTokens[5];
4250
var sanitizedTopicName = string.Join(string.Empty, topicName.Where(char.IsLetterOrDigit));
4351
return sanitizedTopicName;
@@ -61,7 +69,7 @@ public string ResourceName
6169
/// </summary>
6270
public bool Enabled
6371
{
64-
get => enabled.GetValueOrDefault();
72+
get => enabled.GetValueOrDefault(true);
6573
set => enabled = value;
6674
}
6775
private bool? enabled { get; set; }
@@ -80,6 +88,12 @@ internal List<string> Validate()
8088
{
8189
var validationErrors = new List<string>();
8290

91+
if (string.IsNullOrEmpty(Topic))
92+
{
93+
validationErrors.Add($"{nameof(SNSEventAttribute.Topic)} is required and must not be null or empty");
94+
return validationErrors;
95+
}
96+
8397
if (!Topic.StartsWith("@"))
8498
{
8599
var arnTokens = Topic.Split(new char[] { ':' }, 6);

Libraries/src/Amazon.Lambda.Annotations/SQS/SQSEventAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public string ResourceName
6060
/// </summary>
6161
public bool Enabled
6262
{
63-
get => enabled.GetValueOrDefault();
63+
get => enabled.GetValueOrDefault(true);
6464
set => enabled = value;
6565
}
6666
private bool? enabled { get; set; }

Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/WriterTests/SNSEventsTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public void VerifySNSEventAttributes_AreCorrectlyApplied(CloudFormationTemplateF
3838

3939
foreach (var att in snsEventAttributes)
4040
{
41-
var eventName = att.Topic.StartsWith("@") ? att.Topic.Substring(1) : att.Topic.Split(':').ToList()[5];
41+
var eventName = att.ResourceName;
4242
var eventPath = $"Resources.{lambdaFunctionModel.ResourceName}.Properties.Events.{eventName}";
4343
var eventPropertiesPath = $"{eventPath}.Properties";
4444

Libraries/test/TestServerlessApp.IntegrationTests/SNSEventSubscription.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public async Task VerifySNSSubscriptionConfiguration()
2929

3030
// Find the Lambda subscription
3131
var lambdaSub = subscriptions.Subscriptions.FirstOrDefault(s =>
32-
s.Protocol == "lambda" && s.Endpoint.Contains("SNSMessageHandler"));
32+
s.Protocol == "lambda" && s.Endpoint.Contains(lambdaFunctionName));
3333
Assert.NotNull(lambdaSub);
3434

3535
// Verify filter policy

0 commit comments

Comments
 (0)