Skip to content

Commit

Permalink
Use raw string literals
Browse files Browse the repository at this point in the history
  • Loading branch information
slang25 authored and martincostello committed Feb 19, 2024
1 parent e8aa7e3 commit f9ab280
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 56 deletions.
74 changes: 38 additions & 36 deletions src/JustSaying/AwsTools/MessageHandling/SnsPolicyBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,41 +12,43 @@ internal static string BuildPolicyJson(SnsPolicyDetails policyDetails)
throw new ArgumentException("Must be a valid ARN.", nameof(policyDetails));
}
var accountId = arn.AccountId;
return $@"{{
""Version"" : ""2012-10-17"",
""Statement"" : [
{{
""Sid"" : ""{Guid.NewGuid().ToString().Replace("-", "")}"",
""Effect"" : ""Allow"",
""Principal"" : {{
""AWS"" : ""*""
}},
""Action"" : [
""sns:GetTopicAttributes"",
""sns:SetTopicAttributes"",
""sns:AddPermission"",
""sns:RemovePermission"",
""sns:DeleteTopic"",
""sns:Subscribe"",
""sns:Publish""
],
""Resource"" : ""{policyDetails.SourceArn}"",
""Condition"" : {{
""StringEquals"" : {{
""AWS:SourceOwner"" : ""{accountId}""
}}
}}
}},
{{
""Sid"" : ""{Guid.NewGuid().ToString().Replace("-", "")}"",
""Effect"" : ""Allow"",
""Principal"" : {{
""AWS"" : {JsonSerializer.Serialize(policyDetails.AccountIds)}
}},
""Action"" : ""sns:Subscribe"",
""Resource"" : ""{policyDetails.SourceArn}""
}}
]
}}";
return $$"""
{
"Version" : "2012-10-17",
"Statement" : [
{
"Sid" : "{{Guid.NewGuid().ToString().Replace("-", "")}}",
"Effect" : "Allow",
"Principal" : {
"AWS" : "*"
},
"Action" : [
"sns:GetTopicAttributes",
"sns:SetTopicAttributes",
"sns:AddPermission",
"sns:RemovePermission",
"sns:DeleteTopic",
"sns:Subscribe",
"sns:Publish"
],
"Resource" : "{{policyDetails.SourceArn}}",
"Condition" : {
"StringEquals" : {
"AWS:SourceOwner" : "{{accountId}}"
}
}
},
{
"Sid" : "{{Guid.NewGuid().ToString().Replace("-", "")}}",
"Effect" : "Allow",
"Principal" : {
"AWS" : {{JsonSerializer.Serialize(policyDetails.AccountIds)}}
},
"Action" : "sns:Subscribe",
"Resource" : "{{policyDetails.SourceArn}}"
}
]
}
""";
}
}
40 changes: 21 additions & 19 deletions src/JustSaying/AwsTools/MessageHandling/SqsPolicyBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,27 @@ public static string BuildPolicyJson(SqsPolicyDetails policyDetails)
? "*"
: CreateTopicArnWildcard(policyDetails.SourceArn);

var policyJson = $@"{{
""Version"" : ""2012-10-17"",
""Statement"" : [
{{
""Sid"" : ""{sid}"",
""Effect"" : ""Allow"",
""Principal"" : {{
""AWS"" : ""*""
}},
""Action"" : ""sqs:SendMessage"",
""Resource"" : ""{resource}"",
""Condition"" : {{
""ArnLike"" : {{
""aws:SourceArn"" : ""{topicArnWildcard}""
}}
}}
}}
]
}}";
var policyJson = $$"""
{
"Version" : "2012-10-17",
"Statement" : [
{
"Sid" : "{{sid}}",
"Effect" : "Allow",
"Principal" : {
"AWS" : "*"
},
"Action" : "sqs:SendMessage",
"Resource" : "{{resource}}",
"Condition" : {
"ArnLike" : {
"aws:SourceArn" : "{{topicArnWildcard}}"
}
}
}
]
}
""";
return policyJson;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public async Task Messages_Are_Throttled_But_Still_Delivered(int throttleMessage
{
var batchEntry = new SendMessageBatchRequestEntry
{
MessageBody = $"{{\"Subject\":\"SimpleMessage\", \"Message\": {{ \"Content\": \"{entriesAdded}\"}}}}",
MessageBody = $$"""{"Subject":"SimpleMessage", "Message": { "Content": "{{entriesAdded}}"} }""",
Id = Guid.NewGuid().ToString()
};

Expand Down

0 comments on commit f9ab280

Please sign in to comment.